2024-06-07 04:25:21 +00:00
|
|
|
@inject IJSRuntime JS
|
|
|
|
@inject State State
|
2024-07-16 00:45:33 +00:00
|
|
|
@inject ApiService api
|
2024-06-07 04:25:21 +00:00
|
|
|
|
|
|
|
<div class="overlay" data-ui="#@id"></div>
|
|
|
|
<dialog id="@id">
|
2024-06-20 05:48:51 +00:00
|
|
|
<div class="padding center-align">
|
|
|
|
<img src="@Pic?.Url" class="small-height square" />
|
|
|
|
</div>
|
2024-06-07 04:25:21 +00:00
|
|
|
<div class="row">
|
|
|
|
<div class="field textarea label border max">
|
|
|
|
<InputTextArea @bind-Value="Description"></InputTextArea>
|
|
|
|
<label>Description</label>
|
|
|
|
</div>
|
|
|
|
</div>
|
2024-06-20 06:46:12 +00:00
|
|
|
<nav class="no-space">
|
|
|
|
@if (confirmDelete) {
|
|
|
|
<button @onclick="ConfirmDeletePic" 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="DeletePic" disabled="@loading" class="red-7-bg white-fg">
|
|
|
|
<i class="fa-solid fa-trash"></i> <span>Delete</span>
|
|
|
|
</button>
|
|
|
|
}
|
|
|
|
<div class="max"></div>
|
2024-06-07 04:25:21 +00:00
|
|
|
<button class="transparent link" data-ui="#@id" disabled="@loading">Cancel</button>
|
|
|
|
<button @onclick="PostPic" disabled="@loading">
|
|
|
|
@if (loading) {
|
|
|
|
<span>Saving...</span>
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
<i class="fa-solid fa-floppy-disk"></i> <span>Save</span>
|
|
|
|
}
|
|
|
|
</button>
|
|
|
|
</nav>
|
|
|
|
</dialog>
|
|
|
|
|
|
|
|
@code {
|
|
|
|
private Pic? _pic;
|
2024-06-11 07:24:52 +00:00
|
|
|
|
2024-06-07 04:25:21 +00:00
|
|
|
public Pic? Pic {
|
|
|
|
get => _pic;
|
|
|
|
set {
|
|
|
|
_pic = value;
|
|
|
|
Description = _pic?.Description;
|
2024-06-20 05:48:51 +00:00
|
|
|
InvokeAsync(StateHasChanged);
|
2024-06-07 04:25:21 +00:00
|
|
|
}
|
|
|
|
}
|
2024-06-20 05:48:51 +00:00
|
|
|
|
2024-06-07 04:25:21 +00:00
|
|
|
public string? Description { get; set; }
|
|
|
|
private bool loading = false;
|
|
|
|
[Parameter]
|
2024-07-02 00:13:52 +00:00
|
|
|
public string? id { get; set; }
|
2024-06-20 06:46:12 +00:00
|
|
|
private bool confirmDelete { get; set; }
|
2024-06-07 04:25:21 +00:00
|
|
|
|
|
|
|
protected override async Task OnInitializedAsync() {
|
2024-07-02 00:13:52 +00:00
|
|
|
await base.OnInitializedAsync();
|
2024-06-07 04:25:21 +00:00
|
|
|
Description = Pic?.Description;
|
|
|
|
}
|
|
|
|
|
2024-06-20 06:46:12 +00:00
|
|
|
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)) {
|
2024-07-02 00:13:52 +00:00
|
|
|
await api.DeletePic(State.SelectedAddressName!, Pic.Id);
|
2024-06-20 06:46:12 +00:00
|
|
|
await State.RefreshPics();
|
2024-06-24 04:52:45 +00:00
|
|
|
State.SendRefresh();
|
2024-06-20 06:46:12 +00:00
|
|
|
await InvokeAsync(StateHasChanged);
|
|
|
|
}
|
|
|
|
|
|
|
|
await JS.InvokeVoidAsync("ui", "#" + id);
|
|
|
|
// clear input
|
|
|
|
Description = string.Empty;
|
|
|
|
Pic = null;
|
|
|
|
loading = false;
|
|
|
|
confirmDelete = false;
|
|
|
|
await InvokeAsync(StateHasChanged);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2024-06-07 04:25:21 +00:00
|
|
|
public async Task PostPic() {
|
|
|
|
loading = true;
|
|
|
|
await InvokeAsync(StateHasChanged);
|
|
|
|
|
2024-06-20 05:48:51 +00:00
|
|
|
if(!string.IsNullOrEmpty(Pic?.Id)) {
|
2024-07-02 00:13:52 +00:00
|
|
|
await api.PostPicDescription(State.SelectedAddressName!, Pic.Id, Description);
|
2024-06-07 04:25:21 +00:00
|
|
|
await State.RefreshPics();
|
2024-06-24 04:52:45 +00:00
|
|
|
State.SendRefresh();
|
2024-06-07 04:25:21 +00:00
|
|
|
await InvokeAsync(StateHasChanged);
|
|
|
|
}
|
|
|
|
|
|
|
|
await JS.InvokeVoidAsync("ui", "#" + id);
|
|
|
|
// clear input
|
|
|
|
Description = string.Empty;
|
|
|
|
Pic = null;
|
|
|
|
loading = false;
|
2024-06-20 06:46:12 +00:00
|
|
|
confirmDelete = false;
|
2024-06-07 04:25:21 +00:00
|
|
|
await InvokeAsync(StateHasChanged);
|
|
|
|
|
|
|
|
}
|
|
|
|
}
|