diff --git a/Pkmds.Web/Components/EditForms/PokemonEditForm.razor b/Pkmds.Web/Components/EditForms/PokemonEditForm.razor index 955c4a95..71ae850b 100644 --- a/Pkmds.Web/Components/EditForms/PokemonEditForm.razor +++ b/Pkmds.Web/Components/EditForms/PokemonEditForm.razor @@ -31,6 +31,26 @@ AppState.SelectedSlotsAreValid) Save + + Copy + + + + Paste + + RefreshService.OnAppStateChanged += StateHasChanged; @@ -65,4 +69,75 @@ void OnDeleteConfirm(bool confirmed) } } } + + private void OnClickCopy() + { + if (Pokemon is null) + { + return; + } + + CopiedPokemon = Pokemon.Clone(); + + Snackbar.Add("The selected Pokémon has been copied."); + } + + private void OnClickPaste() + { + if (CopiedPokemon is null) + { + return; + } + + if (Pokemon is { Species: > (int)Species.None }) + { + ShowPasteConfirmation(); + } + else + { + PastePokemon(); + } + + void ShowPasteConfirmation() + { + var parameters = new DialogParameters + { + { nameof(ConfirmActionDialog.Title), "Paste Pokémon" }, + { nameof(ConfirmActionDialog.Message), "Are you sure you want to paste the copied Pokémon? The Pokémon in the selected slot will be replaced." }, + { nameof(ConfirmActionDialog.ConfirmText), "Paste" }, + { nameof(ConfirmActionDialog.ConfirmIcon), Icons.Material.Filled.Delete }, + { nameof(ConfirmActionDialog.ConfirmColor), Color.Default }, + { nameof(ConfirmActionDialog.CancelText), "Cancel" }, + { nameof(ConfirmActionDialog.CancelIcon), Icons.Material.Filled.Clear }, + { nameof(ConfirmActionDialog.CancelColor), Color.Primary}, + { nameof(ConfirmActionDialog.OnConfirm), EventCallback.Factory.Create(this, OnPasteConfirm) } + }; + + DialogService.Show( + "Confirm Action", + parameters, + new DialogOptions + { + CloseOnEscapeKey = true, + MaxWidth = MaxWidth.Small, + }); + } + + void OnPasteConfirm(bool confirmed) + { + if (!confirmed) + { + return; + } + + PastePokemon(); + } + + void PastePokemon() + { + Pokemon = CopiedPokemon.Clone(); + AppService.SavePokemon(Pokemon); + Snackbar.Add("The copied Pokémon has been pasted."); + } + } } diff --git a/Pkmds.Web/Program.cs b/Pkmds.Web/Program.cs index 906dc003..8c48c829 100644 --- a/Pkmds.Web/Program.cs +++ b/Pkmds.Web/Program.cs @@ -4,9 +4,15 @@ builder.RootComponents.Add("#app"); builder.RootComponents.Add("head::after"); +services + .AddMudServices(config => + { + config.SnackbarConfiguration.PreventDuplicates = false; + config.SnackbarConfiguration.ClearAfterNavigation = true; + }); + services .AddScoped(_ => new HttpClient { BaseAddress = new Uri(builder.HostEnvironment.BaseAddress) }) - .AddMudServices() .AddFileSystemAccessService() .AddScoped() .AddScoped() diff --git a/Pkmds.Web/_Imports.razor b/Pkmds.Web/_Imports.razor index 25852b2c..9b01aa5d 100644 --- a/Pkmds.Web/_Imports.razor +++ b/Pkmds.Web/_Imports.razor @@ -18,6 +18,7 @@ @inject IJSRuntime JSRuntime @inject IDialogService DialogService +@inject ISnackbar Snackbar @inject IAppState AppState @inject IRefreshService RefreshService @inject IAppService AppService