diff --git a/Components/EditPicDialog.razor b/Components/EditPicDialog.razor index a8b6f30..c19ad36 100644 --- a/Components/EditPicDialog.razor +++ b/Components/EditPicDialog.razor @@ -13,7 +13,18 @@ Description - + + @if (confirmDelete) { + + Are you sure? + + } + else { + + Delete + + } + Cancel @if (loading) { @@ -42,11 +53,38 @@ private bool loading = false; [Parameter] public string id { get; set; } + private bool confirmDelete { get; set; } protected override async Task OnInitializedAsync() { Description = Pic?.Description; } + public async Task DeletePic() { + if (!confirmDelete) confirmDelete = true; + await InvokeAsync(StateHasChanged); + } + + public async Task ConfirmDeletePic() { + if (confirmDelete) { + loading = true; + await InvokeAsync(StateHasChanged); + + if (!string.IsNullOrEmpty(Pic?.Id)) { + await api.DeletePic(State.SelectedAddressName, Pic.Id); + await State.RefreshPics(); + await InvokeAsync(StateHasChanged); + } + + await JS.InvokeVoidAsync("ui", "#" + id); + // clear input + Description = string.Empty; + Pic = null; + loading = false; + confirmDelete = false; + await InvokeAsync(StateHasChanged); + } + } + public async Task PostPic() { loading = true; await InvokeAsync(StateHasChanged); @@ -62,6 +100,7 @@ Description = string.Empty; Pic = null; loading = false; + confirmDelete = false; await InvokeAsync(StateHasChanged); } diff --git a/Components/EditStatusDialog.razor b/Components/EditStatusDialog.razor index 32e9fcd..c8518e1 100644 --- a/Components/EditStatusDialog.razor +++ b/Components/EditStatusDialog.razor @@ -29,7 +29,18 @@ Status - + + @if (confirmDelete) { + + Are you sure? + + } + else { + + Delete + + } + Cancel @@ -60,12 +71,40 @@ private bool loading = false; [Parameter] public string id { get; set; } + private bool confirmDelete { get; set; } protected override async Task OnInitializedAsync() { Content = Status?.Content; Emoji = Status?.Emoji; } + public async Task DeleteStatus() { + if (!confirmDelete) confirmDelete = true; + await InvokeAsync(StateHasChanged); + } + + public async Task ConfirmDeleteStatus() { + if(confirmDelete) { + loading = true; + await InvokeAsync(StateHasChanged); + + if (!string.IsNullOrEmpty(Status?.Id)) { + await api.DeleteStatus(State.SelectedAddressName, Status.Id); + await State.RefreshStatuses(); + await InvokeAsync(StateHasChanged); + } + + await JS.InvokeVoidAsync("ui", "#" + id); + // clear input + Content = string.Empty; + Emoji = string.Empty; + Status = null; + loading = false; + confirmDelete = false; + await InvokeAsync(StateHasChanged); + } + } + public async Task PatchStatus() { loading = true; await InvokeAsync(StateHasChanged); @@ -82,6 +121,7 @@ Emoji = string.Empty; Status = null; loading = false; + confirmDelete = false; await InvokeAsync(StateHasChanged); } diff --git a/Components/NewStatusDialog.razor b/Components/NewStatusDialog.razor index f02314a..e44415e 100644 --- a/Components/NewStatusDialog.razor +++ b/Components/NewStatusDialog.razor @@ -9,15 +9,15 @@ - @(Emoji ?? "🫥") + @(Emoji ?? "🫥")