@inject IJSRuntime JS @inject State State @inject RestService api
@code { private Status? _status; public Status? Status { get => _status; set { _status = value; Content = _status?.Content; Emoji = _status?.Emoji; InvokeAsync(StateHasChanged); } } public string? Content { get; set; } public string? Emoji { get; set; } 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(); State.SendRefresh(); 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); if (!string.IsNullOrEmpty(Status?.Id)) { await api.PatchStatus(State.SelectedAddressName, Status.Id, Content, Emoji); await State.RefreshStatuses(); State.SendRefresh(); 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); } }