@inject IJSRuntime JS @inject State State @inject RestService api
@code { private Pic? _pic; public Pic? Pic { get => _pic; set { _pic = value; Description = _pic?.Description; InvokeAsync(StateHasChanged); } } public string? Description { get; set; } private bool loading = false; [Parameter] public string? id { get; set; } private bool confirmDelete { get; set; } protected override async Task OnInitializedAsync() { await base.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(); State.SendRefresh(); 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); if(!string.IsNullOrEmpty(Pic?.Id)) { await api.PostPicDescription(State.SelectedAddressName!, Pic.Id, Description); await State.RefreshPics(); State.SendRefresh(); await InvokeAsync(StateHasChanged); } await JS.InvokeVoidAsync("ui", "#" + id); // clear input Description = string.Empty; Pic = null; loading = false; confirmDelete = false; await InvokeAsync(StateHasChanged); } }