121 lines
4 KiB
Plaintext
121 lines
4 KiB
Plaintext
@page "/"
|
|
|
|
@inherits Fluxor.Blazor.Web.Components.FluxorComponent
|
|
|
|
@using System.Linq
|
|
@using Start.Client.Components
|
|
@using Start.Client.Store.State
|
|
@using Start.Client.Store.Features.ContainersList
|
|
@using Start.Client.Store.Features.CurrentContainer
|
|
@using Start.Client.Store.Features.CreateContainer
|
|
@using Start.Client.Store.Features.DeleteContainer
|
|
@using Fluxor
|
|
|
|
@* Distinguish from Refit.Authorize *@
|
|
@attribute [Microsoft.AspNetCore.Authorization.Authorize]
|
|
|
|
@inject Blazored.LocalStorage.ILocalStorageService localStorage
|
|
@inject IState<RootState> state
|
|
@inject IDispatcher dispatch
|
|
|
|
@if (this.state.Value.ContainerListState.ErrorMessage != null) {
|
|
<Alert Type="Alert.AlertType.Error">
|
|
<b>Error</b> @this.state.Value.ContainerListState.ErrorMessage
|
|
</Alert>
|
|
}
|
|
|
|
@if (this.state.Value.ContainerListState.IsLoadingContainersList)
|
|
{
|
|
<div class="empty">
|
|
<div class="empty-icon">
|
|
<div class="loading loading-lg"></div>
|
|
</div>
|
|
<p class="empty-title h5">Loading Containers</p>
|
|
</div>
|
|
}
|
|
else
|
|
{
|
|
<ul class="containerList tab">
|
|
@foreach (BookmarkContainerDto container in this.state.Value.ContainerListState.Containers)
|
|
{
|
|
string itemClasses = "tab-item";
|
|
if (container.BookmarkContainerId == this.state.Value.CurrentContainerState.Container?.BookmarkContainerId)
|
|
itemClasses += " active";
|
|
|
|
<li class="@itemClasses">
|
|
<a @onclick="() => OnContainerSelected(container.BookmarkContainerId)">
|
|
@container.Title
|
|
<button class="btn btn-clear"
|
|
@onclick="() => this.OnDeleteContainerClicked(container.BookmarkContainerId)">
|
|
</button>
|
|
</a>
|
|
</li>
|
|
}
|
|
<li class="tab-item tab-action">
|
|
<button @onclick="OnCreateContainerClicked" class="btn btn-link"
|
|
title="Create New Container" aria-label="Create New Container">
|
|
+
|
|
</button>
|
|
</li>
|
|
</ul>
|
|
|
|
<BookmarkContainer Container="this.state.Value.CurrentContainerState.Container" />
|
|
|
|
<CreateContainer />
|
|
<DeleteContainer />
|
|
}
|
|
|
|
@code
|
|
{
|
|
protected override async Task OnInitializedAsync()
|
|
{
|
|
this.dispatch.Dispatch(new LoadContainerListAction());
|
|
this.dispatch.Dispatch(new LoadCurrentContainerAction(await this.GetSelectedContainerId()));
|
|
}
|
|
|
|
protected void OnContainerSelected(int bookmarkContainerId)
|
|
{
|
|
dispatch.Dispatch(new LoadCurrentContainerAction(bookmarkContainerId));
|
|
}
|
|
|
|
protected void OnDeleteContainerClicked(int bookmarkContainerId)
|
|
{
|
|
BookmarkContainerDto? bookmarkContainerToDelete = this.state.Value.ContainerListState
|
|
.Containers
|
|
?.FirstOrDefault(bc => bc.BookmarkContainerId == bookmarkContainerId);
|
|
|
|
if (bookmarkContainerToDelete == null)
|
|
return;
|
|
|
|
this.dispatch.Dispatch(new ShowDeleteContainerFormAction(
|
|
bookmarkContainerToDelete.BookmarkContainerId, bookmarkContainerToDelete.Title));
|
|
}
|
|
|
|
protected void OnCreateContainerClicked()
|
|
{
|
|
dispatch.Dispatch(new ShowCreateContainerFormAction());
|
|
}
|
|
|
|
// Save the currently selected container in LocalStorage so that the same container remains
|
|
// selected between new tabs
|
|
|
|
protected async Task<int> GetSelectedContainerId()
|
|
{
|
|
bool hasValue = await localStorage.ContainKeyAsync("SelectedContainer");
|
|
|
|
if (hasValue)
|
|
return await 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 localStorage.SetItemAsync<int>("SelectedContainer", selectedContainerId);
|
|
}
|
|
}
|