Add sorting columns
This commit is contained in:
parent
adf24cbd5c
commit
90adbcfb7c
34 changed files with 833 additions and 80 deletions
|
|
@ -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(
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue