Add creating bookmark groups
This commit is contained in:
parent
d997655b59
commit
7841d1d1a8
28 changed files with 692 additions and 114 deletions
|
|
@ -0,0 +1,35 @@
|
|||
using Start.Shared;
|
||||
|
||||
namespace Start.Client.Store.Features.CreateGroup {
|
||||
public class ShowCreateGroupFormAction {
|
||||
public int ContainerId { get; init; }
|
||||
public string ContainerTitle { get; init; }
|
||||
|
||||
public ShowCreateGroupFormAction(int containerId, string containerTitle) {
|
||||
this.ContainerId = containerId;
|
||||
this.ContainerTitle = containerTitle;
|
||||
}
|
||||
}
|
||||
|
||||
public class HideCreateGroupFormAction { }
|
||||
|
||||
public class FetchCreateGroupAction { }
|
||||
|
||||
public class RecievedCreateGroupAction { }
|
||||
|
||||
public class ErrorFetchingCreateGroupAction {
|
||||
public string ErrorMessage { get; init; }
|
||||
|
||||
public ErrorFetchingCreateGroupAction(string errorMessage) {
|
||||
this.ErrorMessage = errorMessage;
|
||||
}
|
||||
}
|
||||
|
||||
public class SubmitCreateGroupAction {
|
||||
public BookmarkGroupDto NewGroup { get; init; }
|
||||
|
||||
public SubmitCreateGroupAction(BookmarkGroupDto newGroup) {
|
||||
this.NewGroup = newGroup;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
@ -0,0 +1,44 @@
|
|||
using Start.Shared.Api;
|
||||
using Fluxor;
|
||||
using System.Threading.Tasks;
|
||||
using Microsoft.AspNetCore.Components.WebAssembly.Authentication;
|
||||
using Refit;
|
||||
using Start.Shared;
|
||||
using Start.Client.Store.Features.CurrentContainer;
|
||||
using System;
|
||||
|
||||
namespace Start.Client.Store.Features.CreateGroup {
|
||||
public class CreateGroupEffects {
|
||||
public IBookmarkGroupsApi BookmarkGroupsApi { get; init; }
|
||||
|
||||
public CreateGroupEffects(IBookmarkGroupsApi bookmarksApi) {
|
||||
this.BookmarkGroupsApi = bookmarksApi;
|
||||
}
|
||||
|
||||
[EffectMethod]
|
||||
public async Task SubmitCreateBookmarkGroup(SubmitCreateGroupAction action,
|
||||
IDispatcher dispatch) {
|
||||
dispatch.Dispatch(new FetchCreateGroupAction());
|
||||
|
||||
try {
|
||||
ApiResponse<BookmarkGroupDto?> apiResponse = await this.BookmarkGroupsApi
|
||||
.CreateBookmarkGroup(action.NewGroup.Title, action.NewGroup.Color,
|
||||
action.NewGroup.BookmarkContainerId);
|
||||
|
||||
Console.WriteLine("Status code: " + apiResponse.StatusCode);
|
||||
|
||||
if (!apiResponse.IsSuccessStatusCode) {
|
||||
dispatch.Dispatch(new ErrorFetchingCreateGroupAction(
|
||||
"Error creating bookmark group"));
|
||||
return;
|
||||
}
|
||||
|
||||
dispatch.Dispatch(new AddBookmarkGroupAction(action.NewGroup));
|
||||
dispatch.Dispatch(new RecievedCreateGroupAction());
|
||||
dispatch.Dispatch(new HideCreateGroupFormAction());
|
||||
} catch (AccessTokenNotAvailableException e) {
|
||||
e.Redirect();
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
@ -0,0 +1,11 @@
|
|||
using Fluxor;
|
||||
|
||||
namespace Start.Client.Store.Features.CreateGroup {
|
||||
public class CreateGroupFeature : Feature<CreateGroupState> {
|
||||
public override string GetName() => "Create Group";
|
||||
|
||||
protected override CreateGroupState GetInitialState() {
|
||||
return new CreateGroupState();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
@ -0,0 +1,54 @@
|
|||
using System;
|
||||
using Fluxor;
|
||||
|
||||
namespace Start.Client.Store.Features.CreateGroup {
|
||||
public static class CreateGroupReducers {
|
||||
[ReducerMethod]
|
||||
public static CreateGroupState ShowCreateGroupForm(CreateGroupState state,
|
||||
ShowCreateGroupFormAction action) {
|
||||
return state with {
|
||||
ShowCreateGroupForm = true,
|
||||
ContainerId = action.ContainerId,
|
||||
ContainerTitle = action.ContainerTitle,
|
||||
IsLoadingCreateGroup = false,
|
||||
CreateGroupErrorMessage = null
|
||||
};
|
||||
}
|
||||
|
||||
[ReducerMethod(typeof(HideCreateGroupFormAction))]
|
||||
public static CreateGroupState HideCreateContainerForm(CreateGroupState state) {
|
||||
return state with {
|
||||
ShowCreateGroupForm = false,
|
||||
IsLoadingCreateGroup = false,
|
||||
CreateGroupErrorMessage = null,
|
||||
ContainerId = 0,
|
||||
ContainerTitle = ""
|
||||
};
|
||||
}
|
||||
|
||||
[ReducerMethod(typeof(FetchCreateGroupAction))]
|
||||
public static CreateGroupState FetchCreateGroup(CreateGroupState state) {
|
||||
return state with {
|
||||
IsLoadingCreateGroup = true,
|
||||
CreateGroupErrorMessage = null
|
||||
};
|
||||
}
|
||||
|
||||
[ReducerMethod(typeof(RecievedCreateGroupAction))]
|
||||
public static CreateGroupState RecievedCreateGroup(CreateGroupState state) {
|
||||
return state with {
|
||||
IsLoadingCreateGroup = false,
|
||||
CreateGroupErrorMessage = null
|
||||
};
|
||||
}
|
||||
|
||||
[ReducerMethod]
|
||||
public static CreateGroupState ErrorFetchingCreateGroup(CreateGroupState state,
|
||||
ErrorFetchingCreateGroupAction action) {
|
||||
return state with {
|
||||
CreateGroupErrorMessage = action.ErrorMessage,
|
||||
IsLoadingCreateGroup = false
|
||||
};
|
||||
}
|
||||
}
|
||||
}
|
||||
25
Start/Client/Store/Features/CreateGroup/CreateGroupState.cs
Normal file
25
Start/Client/Store/Features/CreateGroup/CreateGroupState.cs
Normal file
|
|
@ -0,0 +1,25 @@
|
|||
using Start.Client.Store.State;
|
||||
|
||||
namespace Start.Client.Store.Features.CreateGroup {
|
||||
public record CreateGroupState : RootState {
|
||||
public bool ShowCreateGroupForm { get; init; }
|
||||
public int ContainerId { get; init; }
|
||||
public string ContainerTitle { get; init; }
|
||||
public bool IsLoadingCreateGroup { get; init; }
|
||||
public string? CreateGroupErrorMessage { get; init; }
|
||||
|
||||
public CreateGroupState() {
|
||||
this.ContainerTitle = "";
|
||||
}
|
||||
|
||||
public CreateGroupState(ContainerListState containerList,
|
||||
CurrentContainerState currentContainer, bool showCreateGroupForm, string containerTitle,
|
||||
bool isLoadingCreateGroup, string? createGroupErrorMessage)
|
||||
: base(containerList, currentContainer) {
|
||||
this.ShowCreateGroupForm = showCreateGroupForm;
|
||||
this.ContainerTitle = containerTitle;
|
||||
this.IsLoadingCreateGroup = isLoadingCreateGroup;
|
||||
this.CreateGroupErrorMessage = createGroupErrorMessage;
|
||||
}
|
||||
}
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue