Add deleting bookmark groups
This commit is contained in:
parent
1b8460fd3e
commit
64b893b778
12 changed files with 235 additions and 6 deletions
|
|
@ -0,0 +1,33 @@
|
|||
namespace Start.Client.Store.Features.DeleteGroup {
|
||||
public class ShowDeleteGroupFormAction {
|
||||
public int GroupIdToDelete { get; init; }
|
||||
public string GroupTitleToDelete { get; init; }
|
||||
|
||||
public ShowDeleteGroupFormAction(int groupIdToDelete, string groupTitleToDelete) {
|
||||
this.GroupIdToDelete = groupIdToDelete;
|
||||
this.GroupTitleToDelete = groupTitleToDelete;
|
||||
}
|
||||
}
|
||||
|
||||
public class HideDeleteGroupFormAction { }
|
||||
|
||||
public class FetchDeleteGroupFormAction { }
|
||||
|
||||
public class SubmitDeleteGroupFormAction {
|
||||
public int GroupIdToDelete { get; init; }
|
||||
|
||||
public SubmitDeleteGroupFormAction(int groupIdToDelete) {
|
||||
this.GroupIdToDelete = groupIdToDelete;
|
||||
}
|
||||
}
|
||||
|
||||
public class ReceivedDeleteGroupAction { }
|
||||
|
||||
public class ErrorFetchingDeleteGroupAction {
|
||||
public string ErrorMessage { get; init; }
|
||||
|
||||
public ErrorFetchingDeleteGroupAction(string errorMessage) {
|
||||
this.ErrorMessage = errorMessage;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
@ -0,0 +1,49 @@
|
|||
using System.Threading.Tasks;
|
||||
using Fluxor;
|
||||
using Microsoft.AspNetCore.Components.WebAssembly.Authentication;
|
||||
using Start.Shared.Api;
|
||||
using Start.Client.Store.Features.CurrentContainer;
|
||||
|
||||
namespace Start.Client.Store.Features.DeleteGroup {
|
||||
public class DeleteGroupEffects {
|
||||
public IBookmarkGroupsApi BookmarkGroupsApi { get; init; }
|
||||
|
||||
public DeleteGroupEffects(IBookmarkGroupsApi bookmarkGroupsApi) {
|
||||
this.BookmarkGroupsApi = bookmarkGroupsApi;
|
||||
}
|
||||
|
||||
[EffectMethod]
|
||||
public async Task SubmitDeleteGroupForm(SubmitDeleteGroupFormAction action,
|
||||
IDispatcher dispatch) {
|
||||
dispatch.Dispatch(new FetchDeleteGroupFormAction());
|
||||
|
||||
try {
|
||||
System.Net.Http.HttpResponseMessage? apiResonse = await this.BookmarkGroupsApi
|
||||
.DeleteBookmarkGroup(action.GroupIdToDelete);
|
||||
|
||||
if (apiResonse == null) {
|
||||
dispatch.Dispatch(new ErrorFetchingDeleteGroupAction(
|
||||
"Failed to submit request"));
|
||||
return;
|
||||
}
|
||||
|
||||
if (apiResonse.StatusCode == System.Net.HttpStatusCode.NotFound) {
|
||||
dispatch.Dispatch(new ErrorFetchingDeleteGroupAction(
|
||||
"The bookmark group to delete doesn't exist"));
|
||||
return;
|
||||
}
|
||||
|
||||
if (!apiResonse.IsSuccessStatusCode) {
|
||||
dispatch.Dispatch(new ErrorFetchingDeleteGroupAction(
|
||||
"There was an error deleting the bookmark group"));
|
||||
return;
|
||||
}
|
||||
|
||||
dispatch.Dispatch(new RemoveBookmarkGroupAction(action.GroupIdToDelete));
|
||||
dispatch.Dispatch(new ReceivedDeleteGroupAction());
|
||||
} catch (AccessTokenNotAvailableException e) {
|
||||
e.Redirect();
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
@ -0,0 +1,11 @@
|
|||
using Fluxor;
|
||||
|
||||
namespace Start.Client.Store.Features.DeleteGroup {
|
||||
public class DeleteGroupFeature : Feature<DeleteGroupState> {
|
||||
public override string GetName() => "Delete Group";
|
||||
|
||||
protected override DeleteGroupState GetInitialState() {
|
||||
return new DeleteGroupState();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
@ -0,0 +1,49 @@
|
|||
using Fluxor;
|
||||
|
||||
namespace Start.Client.Store.Features.DeleteGroup {
|
||||
public static class DeleteGroupReducers {
|
||||
[ReducerMethod]
|
||||
public static DeleteGroupState ShowDeleteGroupForm(DeleteGroupState state,
|
||||
ShowDeleteGroupFormAction action) {
|
||||
return state with {
|
||||
ShowDeleteGroupForm = true,
|
||||
BookmarkGroupIdToDelete = action.GroupIdToDelete,
|
||||
BookmarkGroupTitleToDelete = action.GroupTitleToDelete,
|
||||
IsLoadingDeleteGroup = false,
|
||||
DeleteGroupErrorMessage = null
|
||||
};
|
||||
}
|
||||
|
||||
[ReducerMethod(typeof(HideDeleteGroupFormAction))]
|
||||
public static DeleteGroupState HideDeleteGroupForm(DeleteGroupState state) {
|
||||
return state with {
|
||||
ShowDeleteGroupForm = false
|
||||
};
|
||||
}
|
||||
|
||||
[ReducerMethod(typeof(FetchDeleteGroupFormAction))]
|
||||
public static DeleteGroupState FetchDeleteGroup(DeleteGroupState state) {
|
||||
return state with {
|
||||
IsLoadingDeleteGroup = true,
|
||||
DeleteGroupErrorMessage = null
|
||||
};
|
||||
}
|
||||
|
||||
[ReducerMethod(typeof(ReceivedDeleteGroupAction))]
|
||||
public static DeleteGroupState ReceivedDeleteGroup(DeleteGroupState state) {
|
||||
return state with {
|
||||
IsLoadingDeleteGroup = false,
|
||||
ShowDeleteGroupForm = false
|
||||
};
|
||||
}
|
||||
|
||||
[ReducerMethod]
|
||||
public static DeleteGroupState ErrorFetchingDeleteGroup(DeleteGroupState state,
|
||||
ErrorFetchingDeleteGroupAction action) {
|
||||
return state with {
|
||||
IsLoadingDeleteGroup = false,
|
||||
DeleteGroupErrorMessage = action.ErrorMessage
|
||||
};
|
||||
}
|
||||
}
|
||||
}
|
||||
24
Start/Client/Store/Features/DeleteGroup/DeleteGroupState.cs
Normal file
24
Start/Client/Store/Features/DeleteGroup/DeleteGroupState.cs
Normal file
|
|
@ -0,0 +1,24 @@
|
|||
using System;
|
||||
namespace Start.Client.Store.Features.DeleteGroup {
|
||||
public record DeleteGroupState {
|
||||
public bool ShowDeleteGroupForm { get; init; }
|
||||
public int BookmarkGroupIdToDelete { get; init; }
|
||||
public string BookmarkGroupTitleToDelete { get; init; }
|
||||
public bool IsLoadingDeleteGroup { get; init; }
|
||||
public string? DeleteGroupErrorMessage { get; init; }
|
||||
|
||||
public DeleteGroupState() {
|
||||
this.BookmarkGroupTitleToDelete = "";
|
||||
}
|
||||
|
||||
public DeleteGroupState(bool showDeleteGroupForm, int bookmarkGroupIdToDelete,
|
||||
string bookmarkTitleToDelete, bool isLoadingDeleteGroup,
|
||||
string? deleteGroupErrorMessage) {
|
||||
this.ShowDeleteGroupForm = showDeleteGroupForm;
|
||||
this.BookmarkGroupIdToDelete = bookmarkGroupIdToDelete;
|
||||
this.BookmarkGroupTitleToDelete = bookmarkTitleToDelete;
|
||||
this.IsLoadingDeleteGroup = isLoadingDeleteGroup;
|
||||
this.DeleteGroupErrorMessage = deleteGroupErrorMessage;
|
||||
}
|
||||
}
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue