Add sorting columns

This commit is contained in:
Neil Brommer 2022-04-19 13:04:38 -07:00
parent adf24cbd5c
commit 90adbcfb7c
34 changed files with 833 additions and 80 deletions

View file

@ -73,13 +73,13 @@
</Dialog>
@code {
protected BookmarkDto Model { get; set; } = new BookmarkDto("", "", null, 0);
protected BookmarkDto Model { get; set; } = new BookmarkDto("", "", null, 0, 0);
protected override void OnInitialized()
{
base.OnInitialized();
this.Model = new BookmarkDto("", "", null, this.state.Value.GroupId);
this.Model = new BookmarkDto("", "", null, 0, this.state.Value.GroupId);
actionSubscriber.SubscribeToAction<ShowCreateBookmarkFormAction>(this,
a => this.Model.BookmarkGroupId = a.GroupId);

View file

@ -65,7 +65,7 @@
[Parameter]
public EventCallback<BookmarkContainerDto> OnCreated { get; set; }
private BookmarkContainerDto Model { get; set; } = new BookmarkContainerDto("");
private BookmarkContainerDto Model { get; set; } = new BookmarkContainerDto("", 0);
protected void OnSubmit()
{

View file

@ -63,13 +63,13 @@
</Dialog>
@code {
private BookmarkGroupDto Model { get; set; } = new("", "", 0);
private BookmarkGroupDto Model { get; set; } = new("", "", 0, 0);
protected override void OnInitialized()
{
base.OnInitialized();
this.Model = new BookmarkGroupDto("", "", state.Value.ContainerId);
this.Model = new BookmarkGroupDto("", "", 0, state.Value.ContainerId);
// Keep the model's container ID up to date
actionSubscriber.SubscribeToAction<ShowCreateGroupFormAction>(this,

View file

@ -21,7 +21,9 @@ namespace Start.Client.Store.Features.ContainersList {
RecievedContainerListAction action) {
return state with {
ContainerListState = state.ContainerListState with {
Containers = action.Containers.ToImmutableList(),
Containers = action.Containers
.SortContainers()
.ToImmutableList(),
IsLoadingContainersList = false,
ErrorMessage = null
}
@ -43,7 +45,10 @@ namespace Start.Client.Store.Features.ContainersList {
AddContainerToListAction action) {
return state with {
ContainerListState = state.ContainerListState with {
Containers = state.ContainerListState.Containers.Add(action.NewContainer)
Containers = state.ContainerListState.Containers
.Add(action.NewContainer)
.SortContainers()
.ToImmutableList()
}
};
}
@ -55,6 +60,7 @@ namespace Start.Client.Store.Features.ContainersList {
ContainerListState = state.ContainerListState with {
Containers = state.ContainerListState.Containers
.Where(c => c.BookmarkContainerId != action.ContainerIdToRemove)
.SortContainers()
.ToImmutableList()
}
};

View file

@ -1,4 +1,5 @@
using System.Threading.Tasks;
using System.Linq;
using Fluxor;
using Microsoft.AspNetCore.Components.WebAssembly.Authentication;
using Start.Shared.Api;
@ -7,9 +8,12 @@ using Start.Client.Store.Features.CurrentContainer;
namespace Start.Client.Store.Features.CreateBookmark {
public class CreateBookmarkEffects {
public IBookmarksApi BookmarksApi { get; init; }
public IBookmarkGroupsApi BookmarkGroupsApi { get; init; }
public CreateBookmarkEffects(IBookmarksApi bookmarksApi) {
public CreateBookmarkEffects(IBookmarksApi bookmarksApi,
IBookmarkGroupsApi bookmarkGroupsApi) {
this.BookmarksApi = bookmarksApi;
this.BookmarkGroupsApi = bookmarkGroupsApi;
}
[EffectMethod]
@ -18,9 +22,25 @@ namespace Start.Client.Store.Features.CreateBookmark {
dispatch.Dispatch(new FetchCreateBookmarkAction());
try {
Refit.ApiResponse<Start.Shared.BookmarkGroupDto?>? groupResponse = await this
.BookmarkGroupsApi
.GetBookmarkGroup(action.NewBookmark.BookmarkGroupId);
if (groupResponse == null || groupResponse.Content == null) {
dispatch.Dispatch(new ErrorFetchingCreateBookmarkAction(
"There was an error checking the bookmark group"));
return;
}
// Set the sort order to highest in the group + 1
// .Max throws an exception if Bookmarks is empty
int sortOrder = !(groupResponse.Content.Bookmarks?.Any() ?? false)
? 0
: groupResponse.Content.Bookmarks.Max(b => b.SortOrder) + 1;
Refit.ApiResponse<Start.Shared.BookmarkDto?>? apiResponse = await this.BookmarksApi
.CreateBookmark(action.NewBookmark.Title, action.NewBookmark.Url,
action.NewBookmark.Notes, action.NewBookmark.BookmarkGroupId);
action.NewBookmark.Notes, sortOrder, action.NewBookmark.BookmarkGroupId);
if (!apiResponse.IsSuccessStatusCode) {
dispatch.Dispatch(new ErrorFetchingCreateBookmarkAction(

View file

@ -5,6 +5,8 @@ using Refit;
using Start.Shared;
using Start.Shared.Api;
using Start.Client.Store.Features.ContainersList;
using System.Collections.Generic;
using System.Linq;
namespace Start.Client.Store.Features.CreateContainer {
public class CreateContainerEffects {
@ -20,8 +22,22 @@ namespace Start.Client.Store.Features.CreateContainer {
dispatch.Dispatch(new FetchCreateContainerAction());
try {
ApiResponse<IEnumerable<BookmarkContainerDto>>? containersResponse = await this
.BookmarkContainersApi
.GetAllBookmarkContainers();
if (containersResponse == null || containersResponse.Content == null) {
dispatch.Dispatch(new ErrorFetchingCreateContainerAction(
"There was an error checking bookmark containers"));
return;
}
int sortOrder = !containersResponse.Content.Any()
? 0
: containersResponse.Content.Max(c => c.SortOrder) + 1;
ApiResponse<BookmarkContainerDto?> apiResponse = await this.BookmarkContainersApi
.CreateBookmarkContainer(action.NewContainer.Title);
.CreateBookmarkContainer(action.NewContainer.Title, sortOrder);
BookmarkContainerDto? container = apiResponse.Content;

View file

@ -6,13 +6,17 @@ using Refit;
using Start.Shared;
using Start.Client.Store.Features.CurrentContainer;
using System;
using System.Linq;
namespace Start.Client.Store.Features.CreateGroup {
public class CreateGroupEffects {
public IBookmarkGroupsApi BookmarkGroupsApi { get; init; }
public IBookmarkContainersApi BookmarkContainersApi { get; init; }
public CreateGroupEffects(IBookmarkGroupsApi bookmarksApi) {
public CreateGroupEffects(IBookmarkGroupsApi bookmarksApi,
IBookmarkContainersApi bookmarkContainersApi) {
this.BookmarkGroupsApi = bookmarksApi;
this.BookmarkContainersApi = bookmarkContainersApi;
}
[EffectMethod]
@ -21,8 +25,22 @@ namespace Start.Client.Store.Features.CreateGroup {
dispatch.Dispatch(new FetchCreateGroupAction());
try {
ApiResponse<BookmarkContainerDto?>? containerResponse = await this
.BookmarkContainersApi
.GetBookmarkContainer(action.NewGroup.BookmarkContainerId);
if (containerResponse == null || containerResponse.Content == null) {
dispatch.Dispatch(new ErrorFetchingCreateGroupAction(
"There was an error checking the new group's bookmark container"));
return;
}
int sortOrder = !(containerResponse.Content.BookmarkGroups?.Any() ?? false)
? 0
: containerResponse.Content.BookmarkGroups.Max(g => g.SortOrder) + 1;
ApiResponse<BookmarkGroupDto?> apiResponse = await this.BookmarkGroupsApi
.CreateBookmarkGroup(action.NewGroup.Title, action.NewGroup.Color,
.CreateBookmarkGroup(action.NewGroup.Title, action.NewGroup.Color, sortOrder,
action.NewGroup.BookmarkContainerId);
Console.WriteLine("Status code: " + apiResponse.StatusCode);

View file

@ -62,7 +62,7 @@ namespace Start.Client.Store.Features.CurrentContainer {
#pragma warning restore CS1998 // Async method lacks 'await' operators and will run synchronously
if (!this.RootState.Value.ContainerListState.Containers.Any()) {
dispatch.Dispatch(new SubmitCreateContainerAction(
new BookmarkContainerDto("Default")));
new BookmarkContainerDto("Default", 0)));
return;
}

View file

@ -20,6 +20,11 @@ namespace Start.Client.Store.Features.CurrentContainer {
[ReducerMethod]
public static RootState ReceivedCurrentContainer(RootState state,
ReceivedCurrentContainerAction action) {
BookmarkContainerDto? container = action.BookmarkContainer;
container.BookmarkGroups = container.BookmarkGroups
?.SortGroups()
.ToList();
return state with {
CurrentContainerState = state.CurrentContainerState with {
Container = action.BookmarkContainer,
@ -54,8 +59,9 @@ namespace Start.Client.Store.Features.CurrentContainer {
return state with {
CurrentContainerState = state.CurrentContainerState with {
Container = new BookmarkContainerDto(container.BookmarkContainerId,
container.Title, container.BookmarkGroups?
container.Title, container.SortOrder, container.BookmarkGroups?
.Concat(new List<BookmarkGroupDto> { action.BookmarkGroup })
.SortGroups()
.ToList())
}
};
@ -72,7 +78,7 @@ namespace Start.Client.Store.Features.CurrentContainer {
return state with {
CurrentContainerState = state.CurrentContainerState with {
Container = new BookmarkContainerDto(container.BookmarkContainerId,
container.Title, container.BookmarkGroups?
container.Title, container.SortOrder, container.BookmarkGroups?
.Where(g => g.BookmarkGroupId != action.BookmarkGroupId)
.ToList())
}
@ -90,9 +96,9 @@ namespace Start.Client.Store.Features.CurrentContainer {
?.Select(bg => {
if (bg.BookmarkGroupId == action.Bookmark.BookmarkGroupId) {
return new BookmarkGroupDto(bg.BookmarkGroupId, bg.Title, bg.Color,
bg.BookmarkContainerId,
bg.Bookmarks?
bg.SortOrder, bg.BookmarkContainerId, bg.Bookmarks?
.Concat(new List<BookmarkDto> { action.Bookmark })
.SortBookmarks()
.ToList());
}
@ -103,7 +109,7 @@ namespace Start.Client.Store.Features.CurrentContainer {
return state with {
CurrentContainerState = state.CurrentContainerState with {
Container = new BookmarkContainerDto(container.BookmarkContainerId,
container.Title, groups)
container.Title, container.SortOrder, groups)
}
};
}
@ -117,7 +123,7 @@ namespace Start.Client.Store.Features.CurrentContainer {
List<BookmarkGroupDto>? groups = container.BookmarkGroups
?.Select(bg => new BookmarkGroupDto(bg.BookmarkGroupId, bg.Title, bg.Color,
bg.BookmarkContainerId, bg.Bookmarks
bg.SortOrder, bg.BookmarkContainerId, bg.Bookmarks
?.Where(b => b.BookmarkId != action.BookmarkId)
.ToList()))
.ToList();
@ -125,7 +131,7 @@ namespace Start.Client.Store.Features.CurrentContainer {
return state with {
CurrentContainerState = state.CurrentContainerState with {
Container = new BookmarkContainerDto(container.BookmarkContainerId,
container.Title, groups)
container.Title, container.SortOrder, groups)
}
};
}