@inject IJSRuntime JS @inject State State @inject ApiService api
@code { private Paste? _paste; public Paste? Paste { get => _paste; set { _paste = value; Title = _paste?.Title; Content = _paste?.Content; Listed = _paste?.IsListed ?? false; InvokeAsync(StateHasChanged); } } public string? Title { get; set; } public string? Content { get; set; } public bool Listed { 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(); Title = Paste?.Title; Content = Paste?.Content; Listed = Paste?.IsListed ?? false; } public async Task DeletePaste() { if (!confirmDelete) confirmDelete = true; await InvokeAsync(StateHasChanged); } public async Task ConfirmDeletePaste() { if (confirmDelete) { loading = true; await InvokeAsync(StateHasChanged); if (!string.IsNullOrEmpty(Paste?.Title)) { await api.DeletePaste(State.SelectedAddressName!, Paste.Title); await State.RefreshPastes(); State.SendRefresh(); await InvokeAsync(StateHasChanged); } await JS.InvokeVoidAsync("ui", "#" + id); // clear input Title = string.Empty; Content = string.Empty; Listed = false; loading = false; confirmDelete = false; await InvokeAsync(StateHasChanged); } } public async Task PostPaste() { loading = true; await InvokeAsync(StateHasChanged); if (!string.IsNullOrEmpty(Paste?.Title)) { await api.PostPaste(State.SelectedAddressName!, Title, Content, Listed); await State.RefreshPastes(); State.SendRefresh(); await InvokeAsync(StateHasChanged); } await JS.InvokeVoidAsync("ui", "#" + id); // clear input Paste = null; Title = string.Empty; Content = string.Empty; Listed = false; confirmDelete = false; await InvokeAsync(StateHasChanged); } }