2021-12-04 00:44:02 +00:00
|
|
|
|
using System.Threading.Tasks;
|
|
|
|
|
using Fluxor;
|
|
|
|
|
using Microsoft.AspNetCore.Components.WebAssembly.Authentication;
|
|
|
|
|
using Refit;
|
|
|
|
|
using Start.Shared;
|
|
|
|
|
using Start.Shared.Api;
|
|
|
|
|
using Start.Client.Store.Features.ContainersList;
|
|
|
|
|
|
|
|
|
|
namespace Start.Client.Store.Features.CreateContainer {
|
|
|
|
|
public class CreateContainerEffects {
|
2021-12-05 23:50:48 +00:00
|
|
|
|
public IBookmarkContainersApi BookmarkContainersApi { get; init; }
|
2021-12-04 00:44:02 +00:00
|
|
|
|
|
|
|
|
|
public CreateContainerEffects(IBookmarkContainersApi bookmarkContainersApi) {
|
|
|
|
|
this.BookmarkContainersApi = bookmarkContainersApi;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
[EffectMethod]
|
|
|
|
|
public async Task SubmitCreateContainer(SubmitCreateContainerAction action,
|
|
|
|
|
IDispatcher dispatch) {
|
|
|
|
|
dispatch.Dispatch(new FetchCreateContainerAction());
|
|
|
|
|
|
|
|
|
|
try {
|
|
|
|
|
ApiResponse<BookmarkContainerDto?> apiResponse = await this.BookmarkContainersApi
|
|
|
|
|
.CreateBookmarkContainer(action.NewContainer.Title);
|
|
|
|
|
|
|
|
|
|
BookmarkContainerDto? container = apiResponse.Content;
|
|
|
|
|
|
2021-12-05 23:50:48 +00:00
|
|
|
|
if (container == null) {
|
2021-12-04 00:44:02 +00:00
|
|
|
|
dispatch.Dispatch(new ErrorFetchingCreateContainerAction(
|
|
|
|
|
"Failed to create container"));
|
2021-12-05 23:50:48 +00:00
|
|
|
|
return;
|
2021-12-04 00:44:02 +00:00
|
|
|
|
}
|
2021-12-05 23:50:48 +00:00
|
|
|
|
|
|
|
|
|
dispatch.Dispatch(new AddContainerToListAction(container));
|
|
|
|
|
dispatch.Dispatch(new ReceivedCreateContainerAction());
|
2021-12-04 00:44:02 +00:00
|
|
|
|
} catch (AccessTokenNotAvailableException e) {
|
|
|
|
|
e.Redirect();
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|