2021-11-30 05:34:42 +00:00
|
|
|
@page "/"
|
2021-11-29 06:32:21 +00:00
|
|
|
@using System.Collections.Generic
|
|
|
|
@using System.Linq
|
2021-11-21 06:47:10 +00:00
|
|
|
@using Microsoft.AspNetCore.Components.WebAssembly.Authentication
|
|
|
|
@using Start.Client.Components
|
|
|
|
@using Start.Shared
|
2021-11-29 06:32:21 +00:00
|
|
|
@using Start.Shared.Api
|
|
|
|
@using Refit
|
|
|
|
|
2021-11-30 05:54:28 +00:00
|
|
|
@* Distinguish from Refit.Authorize *@
|
2021-11-29 06:32:21 +00:00
|
|
|
@attribute [Microsoft.AspNetCore.Authorization.Authorize]
|
2021-11-21 06:47:10 +00:00
|
|
|
@inject Blazored.LocalStorage.ILocalStorageService localStorage
|
2021-11-29 06:32:21 +00:00
|
|
|
@inject IBookmarkContainersApi bookmarkContainersApi
|
2021-11-21 06:47:10 +00:00
|
|
|
|
|
|
|
@if (bookmarkContainers == null)
|
|
|
|
{
|
|
|
|
<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.bookmarkContainers)
|
|
|
|
{
|
|
|
|
string itemClasses = "tab-item";
|
|
|
|
if (container.BookmarkContainerId == this.selectedBookmarkContainer?.BookmarkContainerId)
|
|
|
|
itemClasses += " active";
|
|
|
|
|
|
|
|
<li class="@itemClasses">
|
|
|
|
<a @onclick="() => OnContainerSelected(container.BookmarkContainerId)">
|
|
|
|
@container.Title
|
2021-11-22 20:52:41 +00:00
|
|
|
<button class="btn btn-clear"
|
|
|
|
@onclick="() => this.OnDeleteContainerClicked(container.BookmarkContainerId)">
|
|
|
|
</button>
|
2021-11-21 06:47:10 +00:00
|
|
|
</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>
|
|
|
|
|
|
|
|
<div class="activeBookmarkContainer">
|
|
|
|
@if (this.selectedBookmarkContainer == null)
|
|
|
|
{
|
|
|
|
<div class="empty">
|
|
|
|
<div class="empty-icon">
|
|
|
|
<div class="loading loading-icon"></div>
|
|
|
|
</div>
|
|
|
|
<p class="empty-title h5">Loading Bookmarks</p>
|
|
|
|
</div>
|
|
|
|
<p class="text-center">Loading Bookmarks</p>
|
|
|
|
}
|
|
|
|
else if (!this.selectedBookmarkContainer.BookmarkGroups?.Any() ?? true)
|
|
|
|
{
|
|
|
|
<div class="empty">
|
|
|
|
<div class="empty-icon">
|
|
|
|
<i class="icon icon-3x icon-bookmark"></i>
|
|
|
|
</div>
|
|
|
|
<p class="empty-title h5">No Bookmark Groups</p>
|
|
|
|
</div>
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
@foreach (BookmarkGroupDto group in this.selectedBookmarkContainer.BookmarkGroups!)
|
|
|
|
{
|
|
|
|
<BookmarkGroup Group="group" />
|
|
|
|
}
|
|
|
|
}
|
|
|
|
</div>
|
|
|
|
|
|
|
|
<CreateContainer IsOpen="showCreateContainerForm" OnClose="this.OnCloseCreateContainer"
|
|
|
|
OnCreated="this.OnContainerCreated" />
|
2021-11-23 06:12:13 +00:00
|
|
|
<DeleteContainer Active="this.showDeleteContainerForm" OnClose="this.OnCloseDeleteContainer"
|
|
|
|
BookmarkContainerId="this.bookmarkContainerToDelete?.BookmarkContainerId ?? 0"
|
|
|
|
ContainerTitle="@(this.bookmarkContainerToDelete?.Title ?? "")"
|
|
|
|
OnDeleted="this.OnContainerDeleted" />
|
2021-11-21 06:47:10 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
@code
|
|
|
|
{
|
|
|
|
private IList<BookmarkContainerDto>? bookmarkContainers;
|
|
|
|
private BookmarkContainerDto? selectedBookmarkContainer;
|
2021-11-23 06:12:13 +00:00
|
|
|
|
2021-11-21 06:47:10 +00:00
|
|
|
private bool showCreateContainerForm = false;
|
2021-11-23 06:12:13 +00:00
|
|
|
|
|
|
|
private bool showDeleteContainerForm = false;
|
|
|
|
private BookmarkContainerDto? bookmarkContainerToDelete;
|
|
|
|
|
2021-11-21 06:47:10 +00:00
|
|
|
private bool showCreateGroupForm = false;
|
|
|
|
private bool showCreateBookmarkForm = false;
|
|
|
|
|
|
|
|
protected override async Task OnInitializedAsync()
|
|
|
|
{
|
|
|
|
await LoadContainers();
|
|
|
|
}
|
|
|
|
|
|
|
|
protected async Task LoadContainers()
|
|
|
|
{
|
2021-11-24 05:55:04 +00:00
|
|
|
try
|
|
|
|
{
|
2021-11-29 06:32:21 +00:00
|
|
|
ApiResponse<IEnumerable<BookmarkContainerDto>> response = await bookmarkContainersApi
|
|
|
|
.GetAllBookmarkContainers();
|
|
|
|
|
|
|
|
this.bookmarkContainers = response.Content?.ToList();
|
2021-11-21 06:47:10 +00:00
|
|
|
|
2021-11-23 06:12:13 +00:00
|
|
|
if (this.bookmarkContainers == null || !this.bookmarkContainers.Any())
|
|
|
|
{
|
|
|
|
await this.CreateDefaultContainer();
|
2021-11-21 06:47:10 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
await this.OnContainerSelected(await this.GetSelectedContainerId());
|
|
|
|
}
|
2021-11-24 05:55:04 +00:00
|
|
|
catch (AccessTokenNotAvailableException e)
|
|
|
|
{
|
2021-11-21 06:47:10 +00:00
|
|
|
e.Redirect();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2021-11-23 06:12:13 +00:00
|
|
|
protected async Task CreateDefaultContainer()
|
|
|
|
{
|
2021-11-29 06:32:21 +00:00
|
|
|
ApiResponse<BookmarkContainerDto?> response = await bookmarkContainersApi
|
|
|
|
.CreateBookmarkContainer("Default");
|
2021-11-23 06:12:13 +00:00
|
|
|
|
2021-11-29 06:32:21 +00:00
|
|
|
BookmarkContainerDto? container = response.Content;
|
2021-11-23 06:12:13 +00:00
|
|
|
|
|
|
|
if (container != null)
|
|
|
|
await this.OnContainerSelected(container.BookmarkContainerId);
|
|
|
|
}
|
|
|
|
|
2021-11-21 06:47:10 +00:00
|
|
|
protected async Task OnContainerSelected(int bookmarkContainerId)
|
|
|
|
{
|
|
|
|
try
|
|
|
|
{
|
2021-11-22 20:52:41 +00:00
|
|
|
if (!this.bookmarkContainers?.Any(bc => bc.BookmarkContainerId == bookmarkContainerId) ?? false)
|
|
|
|
bookmarkContainerId = this.bookmarkContainers?.First().BookmarkContainerId ?? bookmarkContainerId;
|
|
|
|
|
2021-11-29 06:32:21 +00:00
|
|
|
ApiResponse<BookmarkContainerDto?> response = await bookmarkContainersApi
|
|
|
|
.GetBookmarkContainer(bookmarkContainerId);
|
|
|
|
|
|
|
|
BookmarkContainerDto? container = response.Content;
|
2021-11-21 06:47:10 +00:00
|
|
|
|
|
|
|
await this.SetSelectedContainer(bookmarkContainerId);
|
2021-11-29 06:32:21 +00:00
|
|
|
this.selectedBookmarkContainer = container;
|
2021-11-21 06:47:10 +00:00
|
|
|
}
|
|
|
|
catch (AccessTokenNotAvailableException e)
|
|
|
|
{
|
|
|
|
e.Redirect();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2021-11-23 06:12:13 +00:00
|
|
|
protected void OnDeleteContainerClicked(int bookmarkContainerId)
|
2021-11-21 06:47:10 +00:00
|
|
|
{
|
2021-11-23 06:12:13 +00:00
|
|
|
this.bookmarkContainerToDelete = this.bookmarkContainers
|
|
|
|
?.First(bc => bc.BookmarkContainerId == bookmarkContainerId);
|
|
|
|
this.showDeleteContainerForm = true;
|
2021-11-21 06:47:10 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
protected void OnCreateContainerClicked()
|
|
|
|
{
|
|
|
|
this.showCreateContainerForm = true;
|
|
|
|
}
|
|
|
|
|
|
|
|
protected void OnCloseCreateContainer()
|
|
|
|
{
|
|
|
|
this.showCreateContainerForm = false;
|
|
|
|
}
|
|
|
|
|
|
|
|
protected async Task OnContainerCreated(BookmarkContainerDto newContainer)
|
|
|
|
{
|
|
|
|
if (this.bookmarkContainers == null)
|
|
|
|
return;
|
|
|
|
|
|
|
|
this.bookmarkContainers.Add(newContainer);
|
|
|
|
this.showCreateContainerForm = false;
|
2021-11-22 20:52:41 +00:00
|
|
|
await OnContainerSelected(newContainer.BookmarkContainerId);
|
2021-11-21 06:47:10 +00:00
|
|
|
}
|
|
|
|
|
2021-11-23 06:12:13 +00:00
|
|
|
protected void OnCloseDeleteContainer()
|
|
|
|
{
|
|
|
|
this.showDeleteContainerForm = false;
|
|
|
|
}
|
|
|
|
|
|
|
|
protected async Task OnContainerDeleted(int bookmarkContainerId)
|
|
|
|
{
|
|
|
|
if (!this.bookmarkContainers?.Any(bc => bc.BookmarkContainerId != bookmarkContainerId) ?? false)
|
|
|
|
await this.CreateDefaultContainer();
|
|
|
|
|
|
|
|
if (await this.GetSelectedContainerId() == bookmarkContainerId)
|
|
|
|
await this.OnContainerSelected(
|
|
|
|
this.bookmarkContainers?.First().BookmarkContainerId ?? bookmarkContainerId);
|
|
|
|
|
|
|
|
this.bookmarkContainers = this.bookmarkContainers
|
|
|
|
?.Where(bc => bc.BookmarkContainerId != bookmarkContainerId)
|
|
|
|
.ToList();
|
|
|
|
}
|
|
|
|
|
2021-11-21 06:47:10 +00:00
|
|
|
// 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.bookmarkContainers!.First().BookmarkContainerId;
|
|
|
|
await this.SetSelectedContainer(firstContainer);
|
|
|
|
return firstContainer;
|
|
|
|
}
|
|
|
|
|
|
|
|
protected async Task SetSelectedContainer(int selectedContainerId)
|
|
|
|
{
|
|
|
|
await localStorage.SetItemAsync<int>("SelectedContainer", selectedContainerId);
|
|
|
|
}
|
|
|
|
}
|