Neighbourhood.omg.lol/Components/EditPicDialog.razor

69 lines
1.6 KiB
Text
Raw Normal View History

2024-06-07 04:25:21 +00:00
@inject IJSRuntime JS
@inject State State
@inject RestService 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>
<nav class="right-align no-space">
<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]
public string id { get; set; }
protected override async Task OnInitializedAsync() {
Description = Pic?.Description;
}
public async Task PostPic() {
loading = true;
await InvokeAsync(StateHasChanged);
2024-06-20 05:48:51 +00:00
if(!string.IsNullOrEmpty(Pic?.Id)) {
2024-06-07 04:25:21 +00:00
await api.PostPicDescription(State.SelectedAddressName, Pic.Id, Description);
await State.RefreshPics();
await InvokeAsync(StateHasChanged);
}
await JS.InvokeVoidAsync("ui", "#" + id);
// clear input
Description = string.Empty;
Pic = null;
loading = false;
await InvokeAsync(StateHasChanged);
}
}