Add creating bookmark groups
This commit is contained in:
parent
d997655b59
commit
7841d1d1a8
28 changed files with 692 additions and 114 deletions
41
Start/Client/Store/State/StoreInitializedEffects.cs
Normal file
41
Start/Client/Store/State/StoreInitializedEffects.cs
Normal file
|
|
@ -0,0 +1,41 @@
|
|||
using System.Threading.Tasks;
|
||||
using Fluxor;
|
||||
using Blazored.LocalStorage;
|
||||
using Start.Client.Store.Features.ContainersList;
|
||||
using Start.Client.Store.Features.CurrentContainer;
|
||||
using System.Linq;
|
||||
|
||||
namespace Start.Client.Store.State {
|
||||
public class StoreInitializedEffects {
|
||||
public IState<RootState> State { get; init; }
|
||||
public ILocalStorageService LocalStorage { get; init; }
|
||||
|
||||
public StoreInitializedEffects(IState<RootState> state, ILocalStorageService localStorage) {
|
||||
this.State = state;
|
||||
this.LocalStorage = localStorage;
|
||||
}
|
||||
|
||||
[EffectMethod(typeof(StoreInitializedAction))]
|
||||
public async Task InitialLoad(IDispatcher dispatch) {
|
||||
dispatch.Dispatch(new LoadContainerListAction());
|
||||
dispatch.Dispatch(new LoadCurrentContainerAction(await GetSelectedContainerId()));
|
||||
}
|
||||
|
||||
private async Task<int> GetSelectedContainerId() {
|
||||
bool hasValue = await this.LocalStorage.ContainKeyAsync("SelectedContainer");
|
||||
|
||||
if (hasValue)
|
||||
return await this.LocalStorage.GetItemAsync<int>("SelectedContainer");
|
||||
|
||||
// Default to the first container
|
||||
int firstContainer = this.State.Value.ContainerListState.Containers
|
||||
.First().BookmarkContainerId;
|
||||
await this.SetSelectedContainer(firstContainer);
|
||||
return firstContainer;
|
||||
}
|
||||
|
||||
protected async Task SetSelectedContainer(int selectedContainerId) {
|
||||
await this.LocalStorage.SetItemAsync("SelectedContainer", selectedContainerId);
|
||||
}
|
||||
}
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue