131 lines
3.4 KiB
Text
131 lines
3.4 KiB
Text
|
@inject IJSRuntime JS
|
||
|
@inject State State
|
||
|
@inject ApiService api
|
||
|
|
||
|
<div class="overlay" data-ui="#@id"></div>
|
||
|
<dialog id="@id">
|
||
|
<div class="row">
|
||
|
<div class="field text label border max">
|
||
|
<InputText @bind-Value="Title"></InputText>
|
||
|
<label>Content</label>
|
||
|
</div>
|
||
|
</div>
|
||
|
<div class="row">
|
||
|
<div class="field textarea label border max">
|
||
|
<InputTextArea @bind-Value="Content"></InputTextArea>
|
||
|
<label>Content</label>
|
||
|
</div>
|
||
|
</div>
|
||
|
<nav class="no-space">
|
||
|
@if (Paste != null)
|
||
|
{
|
||
|
if (confirmDelete)
|
||
|
{
|
||
|
<button @onclick="ConfirmDeletePaste" disabled="@loading" class="red-7-bg white-fg">
|
||
|
<i class="fa-solid fa-exclamation-triangle"></i> <span>Are you sure?</span>
|
||
|
</button>
|
||
|
}
|
||
|
else
|
||
|
{
|
||
|
<button @onclick="DeletePaste" disabled="@loading" class="red-7-bg white-fg">
|
||
|
<i class="fa-solid fa-trash"></i> <span>Delete</span>
|
||
|
</button>
|
||
|
}
|
||
|
}
|
||
|
<div class="max"></div>
|
||
|
<label class="checkbox">
|
||
|
<InputCheckbox @bind-Value="Listed"></InputCheckbox>
|
||
|
<span>Listed?</span>
|
||
|
</label>
|
||
|
<button class="transparent link" data-ui="#@id" disabled="@loading">Cancel</button>
|
||
|
<button @onclick="PostPaste" disabled="@loading">
|
||
|
@if (loading) {
|
||
|
<span>Saving...</span>
|
||
|
}
|
||
|
else {
|
||
|
<i class="fa-solid fa-floppy-disk"></i> <span>Save</span>
|
||
|
}
|
||
|
</button>
|
||
|
</nav>
|
||
|
</dialog>
|
||
|
|
||
|
@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);
|
||
|
|
||
|
}
|
||
|
}
|