Add creating bookmark groups

This commit is contained in:
Neil Brommer 2021-12-05 15:50:48 -08:00
parent d997655b59
commit 7841d1d1a8
28 changed files with 692 additions and 114 deletions

View file

@ -28,4 +28,20 @@ namespace Start.Client.Store.Features.CurrentContainer {
}
public class FixCurrentContainerAction { }
public class AddBookmarkGroupAction {
public BookmarkGroupDto BookmarkGroup { get; init; }
public AddBookmarkGroupAction(BookmarkGroupDto bookmarkGroup) {
this.BookmarkGroup = bookmarkGroup;
}
}
public class RemoveBookmarkGroupAction {
public int BookmarkGroupId { get; init; }
public RemoveBookmarkGroupAction(int bookmarkGroupId) {
this.BookmarkGroupId = bookmarkGroupId;
}
}
}

View file

@ -9,6 +9,7 @@ using Start.Client.Store.State;
using Start.Client.Store.Features.CreateContainer;
using Start.Shared;
using Start.Shared.Api;
using System;
namespace Start.Client.Store.Features.CurrentContainer {
public class CurrentContainerEffects {
@ -35,11 +36,17 @@ namespace Start.Client.Store.Features.CurrentContainer {
BookmarkContainerDto? container = response.Content;
if (container == null) {
Console.WriteLine("Error fetching container " + action.BookmarkContainerId);
Console.WriteLine(response);
dispatch.Dispatch(new ErrorFetchingCurrentContainerAction(
"Failed to get current bookmark container"));
return;
}
Console.WriteLine("Recieved container " + action.BookmarkContainerId);
Console.WriteLine(response);
dispatch.Dispatch(new ReceivedCurrentContainerAction(container));
await this.LocalStorage

View file

@ -1,5 +1,8 @@
using Fluxor;
using System.Collections.Generic;
using System.Linq;
using Fluxor;
using Start.Client.Store.State;
using Start.Shared;
namespace Start.Client.Store.Features.CurrentContainer {
public static class CurrentContainerReducers {
@ -37,5 +40,43 @@ namespace Start.Client.Store.Features.CurrentContainer {
}
};
}
[ReducerMethod]
public static RootState AddBookmarkGroup(RootState state, AddBookmarkGroupAction action) {
BookmarkContainerDto? container = state.CurrentContainerState.Container;
if (container == null)
return state;
if (action.BookmarkGroup.BookmarkContainerId != container.BookmarkContainerId)
return state;
return state with {
CurrentContainerState = state.CurrentContainerState with {
Container = new BookmarkContainerDto(container.BookmarkContainerId,
container.Title, container.BookmarkGroups?
.Concat(new List<BookmarkGroupDto> { action.BookmarkGroup })
.ToList())
}
};
}
[ReducerMethod]
public static RootState RemoveBookmarkGroup(RootState state,
RemoveBookmarkGroupAction action) {
BookmarkContainerDto? container = state.CurrentContainerState.Container;
if (container == null)
return state;
return state with {
CurrentContainerState = state.CurrentContainerState with {
Container = new BookmarkContainerDto(container.BookmarkContainerId,
container.Title, container.BookmarkGroups?
.Where(g => g.BookmarkGroupId != action.BookmarkGroupId)
.ToList())
}
};
}
}
}