From 7841d1d1a810b5b0559c2a894895e61ebfa7055c Mon Sep 17 00:00:00 2001 From: Neil Brommer Date: Sun, 5 Dec 2021 15:50:48 -0800 Subject: [PATCH] Add creating bookmark groups --- Start/Client/Components/Bookmark.razor | 20 ++++ .../Client/Components/BookmarkContainer.razor | 69 +++++++++++-- Start/Client/Components/BookmarkGroup.razor | 61 ++++++++---- Start/Client/Components/CreateContainer.razor | 1 + Start/Client/Components/CreateGroup.razor | 82 ++++++++++++++++ Start/Client/Components/Dialog.razor | 6 +- Start/Client/Pages/Index.razor | 38 ++------ Start/Client/Program.cs | 5 + Start/Client/Start.Client.csproj | 2 + .../CreateContainer/CreateContainerEffects.cs | 14 ++- .../CreateContainerReducers.cs | 3 +- .../CreateGroup/CreateGroupActions.cs | 35 +++++++ .../CreateGroup/CreateGroupEffects.cs | 44 +++++++++ .../CreateGroup/CreateGroupFeature.cs | 11 +++ .../CreateGroup/CreateGroupReducers.cs | 54 +++++++++++ .../Features/CreateGroup/CreateGroupState.cs | 25 +++++ .../CurrentContainerActions.cs | 16 ++++ .../CurrentContainerEffects.cs | 7 ++ .../CurrentContainerReducers.cs | 43 ++++++++- .../Store/State/StoreInitializedEffects.cs | 41 ++++++++ Start/Client/wwwroot/css/app.css | 96 +++++++++++++++---- .../Controllers/BookmarkGroupsController.cs | 67 +++++++++++++ .../Server/Controllers/BookmarksController.cs | 5 +- Start/Server/Extensions/BookmarkMaps.cs | 6 +- Start/Shared/Api/IBookmarkGroupsApi.cs | 17 ++++ Start/Shared/Api/IBookmarksApi.cs | 8 +- Start/Shared/BookmarkContainerDto.cs | 3 +- Start/Shared/BookmarkGroupDto.cs | 27 ++++-- 28 files changed, 692 insertions(+), 114 deletions(-) create mode 100644 Start/Client/Components/Bookmark.razor create mode 100644 Start/Client/Components/CreateGroup.razor create mode 100644 Start/Client/Store/Features/CreateGroup/CreateGroupActions.cs create mode 100644 Start/Client/Store/Features/CreateGroup/CreateGroupEffects.cs create mode 100644 Start/Client/Store/Features/CreateGroup/CreateGroupFeature.cs create mode 100644 Start/Client/Store/Features/CreateGroup/CreateGroupReducers.cs create mode 100644 Start/Client/Store/Features/CreateGroup/CreateGroupState.cs create mode 100644 Start/Client/Store/State/StoreInitializedEffects.cs create mode 100644 Start/Server/Controllers/BookmarkGroupsController.cs create mode 100644 Start/Shared/Api/IBookmarkGroupsApi.cs diff --git a/Start/Client/Components/Bookmark.razor b/Start/Client/Components/Bookmark.razor new file mode 100644 index 0000000..193daea --- /dev/null +++ b/Start/Client/Components/Bookmark.razor @@ -0,0 +1,20 @@ +
  • + @if (!String.IsNullOrEmpty(this.Model.Notes)) + { +
    + + @this.Model.Title + + @this.Model.Notes +
    + } + else + { + @this.Model.Title + } +
  • + +@code { + [Parameter] + public BookmarkDto Model { get; set; } = null!; +} diff --git a/Start/Client/Components/BookmarkContainer.razor b/Start/Client/Components/BookmarkContainer.razor index 35aafe4..1c8834f 100644 --- a/Start/Client/Components/BookmarkContainer.razor +++ b/Start/Client/Components/BookmarkContainer.razor @@ -1,5 +1,21 @@ -
    - @if (this.Container == null) +@using Start.Client.Store.State +@using Start.Client.Store.Features.CreateGroup +@using Fluxor + +@inherits Fluxor.Blazor.Web.Components.FluxorComponent + +@inject IDispatcher dispatch +@inject IState state + +
    + @if (this.state.Value.CurrentContainerState.ErrorMessage != null) + { + + @this.state.Value.CurrentContainerState.ErrorMessage + + } + + @if (this.state.Value.CurrentContainerState.IsLoadingCurrentContainer) {
    @@ -7,27 +23,60 @@

    Loading Bookmarks

    -

    Loading Bookmarks

    } - else if (!this.Container.BookmarkGroups?.Any() ?? true) + else if (this.state.Value.CurrentContainerState.Container == null) + { +
    +
    + +
    +

    Failed To Load Container

    +
    + } + else if (this.state.Value.CurrentContainerState.Container.BookmarkGroups == null + || (!(this.state.Value.CurrentContainerState.Container.BookmarkGroups?.Any()) ?? true)) {

    No Bookmark Groups

    +
    + +
    } else { - foreach (BookmarkGroupDto group in this.Container.BookmarkGroups!) - { - - } +
    + @* The compiler doesn't pick up that null has already been checked for, + so the ! is needed *@ + @foreach (BookmarkGroupDto group in this.state.Value.CurrentContainerState.Container.BookmarkGroups!) + { + + } + +
    + +
    +
    }
    @code { - [Parameter] - public BookmarkContainerDto? Container { get; set; } + public void ShowCreateGroupForm() + { + if (this.state.Value.CurrentContainerState.Container == null) + return; + + dispatch.Dispatch(new ShowCreateGroupFormAction( + this.state.Value.CurrentContainerState.Container.BookmarkContainerId, + this.state.Value.CurrentContainerState.Container.Title)); + } } diff --git a/Start/Client/Components/BookmarkGroup.razor b/Start/Client/Components/BookmarkGroup.razor index 64a7381..a644691 100644 --- a/Start/Client/Components/BookmarkGroup.razor +++ b/Start/Client/Components/BookmarkGroup.razor @@ -1,24 +1,47 @@ -

    - @this.Group.Title -

    -
      - @if (this.Group.Bookmarks == null || !this.Group.Bookmarks.Any()) - { -
    • No Bookmarks
    • - } - else - { - foreach (BookmarkDto bookmark in this.Group.Bookmarks!) - { -
    • - @bookmark.Title -
    • - } - } -
    +
    +
    +

    @this.Group.Title

    + +
    +
    +
      + @if (this.Group.Bookmarks == null || !this.Group.Bookmarks.Any()) + { +
    • +
      +
      + +
      +

      No Bookmarks

      +
      + +
      +
      +
    • + } + else + { + foreach (BookmarkDto bookmark in this.Group.Bookmarks) + { + + } + } +
    +
    +
    @code { [Parameter] - public BookmarkGroupDto Group { get; set; } = null!; // [Required] is a .net 6 feature + public BookmarkGroupDto Group { get; set; } = null!; + + protected void OnCreateBookmarkClicked() + { + // Placeholder + } } diff --git a/Start/Client/Components/CreateContainer.razor b/Start/Client/Components/CreateContainer.razor index bf013f6..d9ac20b 100644 --- a/Start/Client/Components/CreateContainer.razor +++ b/Start/Client/Components/CreateContainer.razor @@ -14,6 +14,7 @@ @this.state.Value.CreateContainerErrorMessage } +
    diff --git a/Start/Client/Components/CreateGroup.razor b/Start/Client/Components/CreateGroup.razor new file mode 100644 index 0000000..85be69b --- /dev/null +++ b/Start/Client/Components/CreateGroup.razor @@ -0,0 +1,82 @@ +@using Start.Client.Store.Features.CreateGroup +@using Fluxor + +@inherits Fluxor.Blazor.Web.Components.FluxorComponent + +@inject IActionSubscriber actionSubscriber +@inject IDispatcher dispatch +@inject IState state + + + + + + @if (this.state.Value.CreateGroupErrorMessage != null) + { + + @this.state.Value.CreateGroupErrorMessage + + } + + + +
    +
    +
    +
    + + +
    +
    + + +
    +
    +
    +
    +
    +
    + @if (this.state.Value.IsLoadingCreateGroup) + { + + } + else + { + + } +
    +
    +
    +
    +
    +
    + +@code { + private BookmarkGroupDto Model { get; set; } = new("", "", 0); + + protected override void OnInitialized() + { + base.OnInitialized(); + + this.Model = new BookmarkGroupDto("", "", state.Value.ContainerId); + + // Keep the model's container ID up to date + actionSubscriber.SubscribeToAction(this, + (a) => this.Model.BookmarkContainerId = a.ContainerId); + } + + protected void OnSubmit() + { + dispatch.Dispatch(new SubmitCreateGroupAction(this.Model)); + } + + protected void OnDialogClose() + { + dispatch.Dispatch(new HideCreateGroupFormAction()); + } +} diff --git a/Start/Client/Components/Dialog.razor b/Start/Client/Components/Dialog.razor index 9ddd797..6b35968 100644 --- a/Start/Client/Components/Dialog.razor +++ b/Start/Client/Components/Dialog.razor @@ -1,4 +1,8 @@ -