Quick fixes for initial setup
This commit is contained in:
parent
45c8899f06
commit
2356fbab4f
2 changed files with 31 additions and 16 deletions
|
|
@ -2,19 +2,25 @@
|
|||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Threading.Tasks;
|
||||
using Blazored.LocalStorage;
|
||||
using Fluxor;
|
||||
using Microsoft.AspNetCore.Components.WebAssembly.Authentication;
|
||||
using Refit;
|
||||
using Start.Client.Store.Features.CreateContainer;
|
||||
using Start.Client.Store.Features.CurrentContainer;
|
||||
using Start.Client.Store.State;
|
||||
using Start.Shared;
|
||||
using Start.Shared.Api;
|
||||
|
||||
namespace Start.Client.Store.Features.ContainersList {
|
||||
public class ContainerListEffects {
|
||||
public IBookmarkContainersApi BookmarkContainersApi { get; init; }
|
||||
public ILocalStorageService LocalStorage { get; set; }
|
||||
|
||||
public ContainerListEffects(IBookmarkContainersApi bookmarkContainersApi) {
|
||||
public ContainerListEffects(IBookmarkContainersApi bookmarkContainersApi,
|
||||
ILocalStorageService localStorage) {
|
||||
this.BookmarkContainersApi = bookmarkContainersApi;
|
||||
this.LocalStorage = localStorage;
|
||||
}
|
||||
|
||||
[EffectMethod(typeof(LoadContainerListAction))]
|
||||
|
|
@ -35,21 +41,22 @@ namespace Start.Client.Store.Features.ContainersList {
|
|||
}
|
||||
|
||||
if (!bookmarkContainers.Any()) {
|
||||
dispatch.Dispatch(new SubmitCreateContainerAction(
|
||||
new BookmarkContainerDto("Default", 0)));
|
||||
|
||||
// And load again
|
||||
response = await this
|
||||
ApiResponse<BookmarkContainerDto?>? createResponse = await this
|
||||
.BookmarkContainersApi
|
||||
.GetAllBookmarkContainers();
|
||||
.CreateBookmarkContainer("Default", 0);
|
||||
|
||||
bookmarkContainers = response.Content?.ToList();
|
||||
BookmarkContainerDto? newContainer = createResponse.Content;
|
||||
|
||||
if (bookmarkContainers == null) {
|
||||
if (newContainer == null) {
|
||||
dispatch.Dispatch(new ErrorFetchingContainerListAction(
|
||||
"Failed to fetch containers list"));
|
||||
"Failed to create default container"));
|
||||
return;
|
||||
}
|
||||
|
||||
bookmarkContainers = new List<BookmarkContainerDto> { newContainer };
|
||||
|
||||
await this.SetSelectedContainer(newContainer.BookmarkContainerId);
|
||||
dispatch.Dispatch(new LoadCurrentContainerAction(newContainer.BookmarkContainerId));
|
||||
}
|
||||
|
||||
dispatch.Dispatch(new RecievedContainerListAction(bookmarkContainers));
|
||||
|
|
@ -58,5 +65,9 @@ namespace Start.Client.Store.Features.ContainersList {
|
|||
e.Redirect();
|
||||
}
|
||||
}
|
||||
|
||||
private async Task SetSelectedContainer(int selectedContainerId) {
|
||||
await this.LocalStorage.SetItemAsync("SelectedContainer", selectedContainerId);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue