From f63798e897b0ec61fbd02c890089d941cfa344ab Mon Sep 17 00:00:00 2001 From: Neil Brommer Date: Tue, 7 Dec 2021 17:12:20 -0800 Subject: [PATCH] Turn the top nav bar into a sidebar Add an edit mode --- .../Client/Components/BookmarkContainer.razor | 17 ++-- Start/Client/Components/BookmarkGroup.razor | 29 +++++-- Start/Client/Components/Sidebar.razor | 87 +++++++++++++++++++ Start/Client/Pages/Index.razor | 75 ++++++++++------ Start/Client/Shared/MainLayout.razor | 5 -- Start/Client/Start.Client.csproj | 2 + .../Store/Features/Sidebar/SidebarActions.cs | 5 ++ .../Store/Features/Sidebar/SidebarReducers.cs | 27 ++++++ Start/Client/Store/State/RootState.cs | 3 + Start/Client/wwwroot/css/app.css | 64 +++++++++++++- Start/Client/wwwroot/index.html | 1 + 11 files changed, 266 insertions(+), 49 deletions(-) create mode 100644 Start/Client/Components/Sidebar.razor create mode 100644 Start/Client/Store/Features/Sidebar/SidebarActions.cs create mode 100644 Start/Client/Store/Features/Sidebar/SidebarReducers.cs diff --git a/Start/Client/Components/BookmarkContainer.razor b/Start/Client/Components/BookmarkContainer.razor index 1c8834f..ea79e0c 100644 --- a/Start/Client/Components/BookmarkContainer.razor +++ b/Start/Client/Components/BookmarkContainer.razor @@ -58,13 +58,16 @@ } -
- -
+ @if (this.state.Value.EditMode) + { +
+ +
+ } } diff --git a/Start/Client/Components/BookmarkGroup.razor b/Start/Client/Components/BookmarkGroup.razor index e29d746..07e9e41 100644 --- a/Start/Client/Components/BookmarkGroup.razor +++ b/Start/Client/Components/BookmarkGroup.razor @@ -1,14 +1,17 @@ @using System.Drawing +@using Fluxor +@using Start.Client.Store.State + +@inherits Fluxor.Blazor.Web.Components.FluxorComponent + +@inject IState state +@inject IDispatcher dispatch
-

+

@this.Group.Title

-
    @@ -34,6 +37,16 @@ { } + + @if (this.state.Value.EditMode) + { +
  • + +
  • + } }
@@ -44,8 +57,10 @@ [Parameter] public BookmarkGroupDto Group { get; set; } = null!; - protected string ForegroundTitleColorClass { - get { + protected string ForegroundTitleColorClass + { + get + { const int threshold = 105; Color bgColor = ColorTranslator.FromHtml(this.Group.Color); diff --git a/Start/Client/Components/Sidebar.razor b/Start/Client/Components/Sidebar.razor new file mode 100644 index 0000000..9f36ced --- /dev/null +++ b/Start/Client/Components/Sidebar.razor @@ -0,0 +1,87 @@ +@using Microsoft.AspNetCore.Components.Authorization +@using Microsoft.AspNetCore.Components.WebAssembly.Authentication +@using Start.Client.Store.Features.Sidebar +@using Start.Client.Store.State +@using Fluxor + +@inherits Fluxor.Blazor.Web.Components.FluxorComponent + +@inject IState state +@inject IDispatcher dispatch + +@inject NavigationManager Navigation +@inject SignOutSessionStateManager SignOutManager + +
+ @* No off-canvas-toggle - add something that dispatches ShowSidebarAction *@ + + + + + +
+ @this.ChildContent +
+
+ +@code { + [Parameter] + public RenderFragment ChildContent { get; set; } = null!; + + protected void OnSidebarHideClicked() + { + dispatch.Dispatch(new HideSidebarAction()); + } + + protected void OnToggleEditMode() + { + dispatch.Dispatch(new ToggleEditModeAction()); + } + + private async Task BeginSignOut(MouseEventArgs args) + { + await SignOutManager.SetSignOutState(); + Navigation.NavigateTo("authentication/logout"); + } +} diff --git a/Start/Client/Pages/Index.razor b/Start/Client/Pages/Index.razor index d4d1a64..6290e04 100644 --- a/Start/Client/Pages/Index.razor +++ b/Start/Client/Pages/Index.razor @@ -8,6 +8,7 @@ @using Start.Client.Store.Features.CurrentContainer @using Start.Client.Store.Features.CreateContainer @using Start.Client.Store.Features.DeleteContainer +@using Start.Client.Store.Features.Sidebar @using Fluxor @* Distinguish from Refit.Authorize *@ @@ -17,7 +18,8 @@ @inject IState state @inject IDispatcher dispatch -@if (this.state.Value.ContainerListState.ErrorMessage != null) { +@if (this.state.Value.ContainerListState.ErrorMessage != null) +{ Error @this.state.Value.ContainerListState.ErrorMessage @@ -34,41 +36,60 @@ } else { -
    - @foreach (BookmarkContainerDto container in this.state.Value.ContainerListState.Containers) - { - string itemClasses = "tab-item"; - if (container.BookmarkContainerId == this.state.Value.CurrentContainerState.Container?.BookmarkContainerId) - itemClasses += " active"; + -
  • - - @container.Title - - -
  • - } -
  • - -
  • -
+
    + @foreach (BookmarkContainerDto container in this.state.Value.ContainerListState.Containers) + { + string itemClasses = "tab-item"; + if (container.BookmarkContainerId == this.state.Value.CurrentContainerState.Container?.BookmarkContainerId) + itemClasses += " active"; - +
  • + + @container.Title + @if (this.state.Value.EditMode) + { + + } + +
  • + } + @if (this.state.Value.EditMode) + { +
  • + +
  • + } +
+
- - + - + + + + + } @code { + protected void ShowSidebar() + { + dispatch.Dispatch(new ShowSidebarAction()); + } + protected void OnContainerSelected(int bookmarkContainerId) { dispatch.Dispatch(new LoadCurrentContainerAction(bookmarkContainerId)); diff --git a/Start/Client/Shared/MainLayout.razor b/Start/Client/Shared/MainLayout.razor index 36c932d..3179cb7 100644 --- a/Start/Client/Shared/MainLayout.razor +++ b/Start/Client/Shared/MainLayout.razor @@ -2,11 +2,6 @@
-
- - About -
-
@Body
diff --git a/Start/Client/Start.Client.csproj b/Start/Client/Start.Client.csproj index ca3aa70..2e961b1 100644 --- a/Start/Client/Start.Client.csproj +++ b/Start/Client/Start.Client.csproj @@ -47,6 +47,7 @@ + @@ -60,5 +61,6 @@ + diff --git a/Start/Client/Store/Features/Sidebar/SidebarActions.cs b/Start/Client/Store/Features/Sidebar/SidebarActions.cs new file mode 100644 index 0000000..350bcfa --- /dev/null +++ b/Start/Client/Store/Features/Sidebar/SidebarActions.cs @@ -0,0 +1,5 @@ +namespace Start.Client.Store.Features.Sidebar { + public class ShowSidebarAction { } + public class HideSidebarAction { } + public class ToggleEditModeAction { } +} diff --git a/Start/Client/Store/Features/Sidebar/SidebarReducers.cs b/Start/Client/Store/Features/Sidebar/SidebarReducers.cs new file mode 100644 index 0000000..fe028e8 --- /dev/null +++ b/Start/Client/Store/Features/Sidebar/SidebarReducers.cs @@ -0,0 +1,27 @@ +using Fluxor; +using Start.Client.Store.State; + +namespace Start.Client.Store.Features.Sidebar { + public static class SidebarReducers { + [ReducerMethod(typeof(ShowSidebarAction))] + public static RootState ShowSidebar(RootState state) { + return state with { + ShowSidebar = true + }; + } + + [ReducerMethod(typeof(HideSidebarAction))] + public static RootState HideSidebar(RootState state) { + return state with { + ShowSidebar = false + }; + } + + [ReducerMethod(typeof(ToggleEditModeAction))] + public static RootState ToggleEditMode(RootState state) { + return state with { + EditMode = !state.EditMode + }; + } + } +} diff --git a/Start/Client/Store/State/RootState.cs b/Start/Client/Store/State/RootState.cs index ffce2fa..7c35d9c 100644 --- a/Start/Client/Store/State/RootState.cs +++ b/Start/Client/Store/State/RootState.cs @@ -8,6 +8,9 @@ namespace Start.Client.Store.State { public ContainerListState ContainerListState { get; init; } public CurrentContainerState CurrentContainerState { get; init; } + public bool ShowSidebar { get; init; } + public bool EditMode { get; init; } + public RootState() { this.ContainerListState = new ContainerListState(); this.CurrentContainerState = new CurrentContainerState(); diff --git a/Start/Client/wwwroot/css/app.css b/Start/Client/wwwroot/css/app.css index ef425d1..2ef044a 100644 --- a/Start/Client/wwwroot/css/app.css +++ b/Start/Client/wwwroot/css/app.css @@ -47,6 +47,65 @@ align-items: center; } + +#sidebar { + display: flex; + flex-direction: column; +} + +#sidebar #sidebarHeading { + padding: 0.5rem 1.5rem; + display: flex; + flex-direction: row; + align-items: center; + justify-content: space-between; +} + +#sidebar #sidebarHeading h1 { + margin: 0; +} + +#sidebar .nav { + padding: 0.5rem 1.5rem; +} + +#sidebar #sidebarItems { + flex: 1; /* Fill remaining space */ + overflow-y: auto; +} + +#sidebar .accountActions { + border-top: solid 1px #dadee4; +} + +#sidebar .accountActions .accountName { + font-weight: bold; + margin-bottom: 1em; +} + +.off-canvas .off-canvas-content { + padding: 0; +} + +#menubutton .icon { + transform: scale(1.5); +} + +#containerTabStrip { + width: 100%; + display: flex; + align-items: center; +} + +#containerTabStrip #menuButton { + flex: 0 0 auto; + margin-right: 1em; +} + +#containerTabStrip .containerList { + flex: 1 0 0; +} + #bookmarkGroups { margin-top: 1em; margin-left: auto; @@ -71,7 +130,7 @@ } } -@media screen and (min-width: 1280px) { +@media screen and (min-width: 1440) { #bookmarkGroups { grid-template-columns: repeat(3, 1fr); width: 70%; @@ -113,6 +172,5 @@ li.noBookmarksItem { } button.addBookmarkButton { - float: right; - margin-top: 0.5em; + width: 100%; } diff --git a/Start/Client/wwwroot/index.html b/Start/Client/wwwroot/index.html index 0aedfe4..c81bd2a 100644 --- a/Start/Client/wwwroot/index.html +++ b/Start/Client/wwwroot/index.html @@ -10,6 +10,7 @@ +