BlazorStart/Start/Client/Pages/Index.razor

121 lines
3.9 KiB
Plaintext
Raw Normal View History

2021-11-30 05:34:42 +00:00
@page "/"
2021-12-04 00:44:02 +00:00
@inherits Fluxor.Blazor.Web.Components.FluxorComponent
@using System.Linq
@using Start.Client.Components
2021-12-04 00:44:02 +00:00
@using Start.Client.Store.State
@using Start.Client.Store.Features.CurrentContainer
@using Start.Client.Store.Features.CreateContainer
@using Start.Client.Store.Features.DeleteContainer
@using Start.Client.Store.Features.Sidebar
2021-12-04 00:44:02 +00:00
@using Fluxor
2021-11-30 05:54:28 +00:00
@* Distinguish from Refit.Authorize *@
@attribute [Microsoft.AspNetCore.Authorization.Authorize]
2021-12-04 00:44:02 +00:00
@inject Blazored.LocalStorage.ILocalStorageService localStorage
2021-12-04 00:44:02 +00:00
@inject IState<RootState> state
@inject IDispatcher dispatch
@if (this.state.Value.ContainerListState.ErrorMessage != null)
{
2021-12-04 00:44:02 +00:00
<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
{
<Sidebar>
2021-12-08 01:34:47 +00:00
<div id="containerTabStrip" class="px-2">
<button id="menuButton" class="btn btn-link" @onclick="this.ShowSidebar">
<i class="icon icon-menu"></i>
</button>
<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
@if (this.state.Value.EditMode)
{
<button class="btn btn-clear"
@onclick="() => this.OnDeleteContainerClicked(container.BookmarkContainerId)">
</button>
}
</a>
</li>
}
@if (this.state.Value.EditMode)
{
<li class="tab-item tab-action">
<button @onclick="OnCreateContainerClicked" class="btn btn-link tooltip tooltip-left"
title="Create New Container" aria-label="Create New Container"
data-tooltip="Create Container">
+
</button>
</li>
}
</ul>
</div>
<BookmarkContainer />
2021-12-16 18:46:22 +00:00
@* Data management forms *@
<CreateContainer />
<DeleteContainer />
2021-12-05 23:50:48 +00:00
<CreateGroup />
2021-12-11 21:56:35 +00:00
<DeleteGroup />
2021-12-14 00:27:13 +00:00
<CreateBookmark />
2021-12-16 18:46:22 +00:00
<DeleteBookmark />
</Sidebar>
}
@code
{
protected void ShowSidebar()
{
dispatch.Dispatch(new ShowSidebarAction());
}
2021-12-04 00:44:02 +00:00
protected void OnContainerSelected(int bookmarkContainerId)
{
2021-12-04 00:44:02 +00:00
dispatch.Dispatch(new LoadCurrentContainerAction(bookmarkContainerId));
}
2021-11-23 06:12:13 +00:00
protected void OnDeleteContainerClicked(int bookmarkContainerId)
{
2021-12-04 00:44:02 +00:00
BookmarkContainerDto? bookmarkContainerToDelete = this.state.Value.ContainerListState
.Containers
?.FirstOrDefault(bc => bc.BookmarkContainerId == bookmarkContainerId);
2021-12-04 00:44:02 +00:00
if (bookmarkContainerToDelete == null)
return;
2021-12-04 00:44:02 +00:00
this.dispatch.Dispatch(new ShowDeleteContainerFormAction(
bookmarkContainerToDelete.BookmarkContainerId, bookmarkContainerToDelete.Title));
}
2021-12-04 00:44:02 +00:00
protected void OnCreateContainerClicked()
2021-11-23 06:12:13 +00:00
{
2021-12-04 00:44:02 +00:00
dispatch.Dispatch(new ShowCreateContainerFormAction());
2021-11-23 06:12:13 +00:00
}
}