Add create bookmark

This commit is contained in:
Neil Brommer 2021-12-13 16:27:13 -08:00
parent 64b893b778
commit 55625b1be4
19 changed files with 382 additions and 13 deletions

View file

@ -44,4 +44,20 @@ namespace Start.Client.Store.Features.CurrentContainer {
this.BookmarkGroupId = bookmarkGroupId;
}
}
public class AddBookmarkAction {
public BookmarkDto Bookmark { get; init; }
public AddBookmarkAction(BookmarkDto bookmark) {
this.Bookmark = bookmark;
}
}
public class RemoveBookmarkAction {
public int BookmarkId { get; init; }
public RemoveBookmarkAction(int bookmarkId) {
this.BookmarkId = bookmarkId;
}
}
}

View file

@ -78,5 +78,56 @@ namespace Start.Client.Store.Features.CurrentContainer {
}
};
}
[ReducerMethod]
public static RootState AddBookmark(RootState state, AddBookmarkAction action) {
BookmarkContainerDto? container = state.CurrentContainerState.Container;
if (container == null)
return state;
List<BookmarkGroupDto>? groups = container.BookmarkGroups
?.Select(bg => {
if (bg.BookmarkGroupId == action.Bookmark.BookmarkGroupId) {
return new BookmarkGroupDto(bg.BookmarkGroupId, bg.Title, bg.Color,
bg.BookmarkContainerId,
bg.Bookmarks?
.Concat(new List<BookmarkDto> { action.Bookmark })
.ToList());
}
return bg;
})
.ToList();
return state with {
CurrentContainerState = state.CurrentContainerState with {
Container = new BookmarkContainerDto(container.BookmarkContainerId,
container.Title, groups)
}
};
}
[ReducerMethod]
public static RootState RemoveBookmark(RootState state, RemoveBookmarkAction action) {
BookmarkContainerDto? container = state.CurrentContainerState.Container;
if (container == null)
return state;
List<BookmarkGroupDto>? groups = container.BookmarkGroups
?.Select(bg => new BookmarkGroupDto(bg.BookmarkGroupId, bg.Title, bg.Color,
bg.BookmarkContainerId, bg.Bookmarks
?.Where(b => b.BookmarkId != action.BookmarkId)
.ToList()))
.ToList();
return state with {
CurrentContainerState = state.CurrentContainerState with {
Container = new BookmarkContainerDto(container.BookmarkContainerId,
container.Title, groups)
}
};
}
}
}