2024-06-13 10:02:51 +00:00
|
|
|
@inject IJSRuntime JS
|
|
|
|
@inject State State
|
2024-06-14 07:20:04 +00:00
|
|
|
@inject RestService api
|
2024-06-13 10:02:51 +00:00
|
|
|
|
|
|
|
<div class="overlay" data-ui="#@id"></div>
|
|
|
|
<dialog id="@id">
|
|
|
|
<div class="row">
|
|
|
|
<div class="min square extra">
|
|
|
|
<button class="transparent square extra no-margin">
|
|
|
|
<object id="status-emoji" class="large emoji @(Emoji == null ? "animated" : string.Empty)" data-emoji="@(Emoji ?? "🫥")">@(Emoji ?? "🫥")</object>
|
|
|
|
<menu class="no-wrap">
|
|
|
|
<script type="module" src="https://cdn.jsdelivr.net/npm/emoji-picker-element@@^1/index.js"></script>
|
|
|
|
<emoji-picker emoji-version="15.1"></emoji-picker>
|
|
|
|
<script>
|
|
|
|
document.querySelector('emoji-picker')
|
|
|
|
.addEventListener('emoji-click', event => {
|
|
|
|
document.getElementById('status-emoji').setAttribute('data-emoji', event.detail.unicode)
|
|
|
|
const input = document.getElementById('status-emoji-input')
|
|
|
|
input.value = event.detail.unicode
|
|
|
|
var event = new Event('change');
|
|
|
|
input.dispatchEvent(event);
|
|
|
|
})
|
|
|
|
</script>
|
|
|
|
</menu>
|
|
|
|
</button>
|
|
|
|
</div>
|
|
|
|
<div class="field textarea label border max">
|
|
|
|
<InputTextArea @bind-Value="Content"></InputTextArea>
|
|
|
|
<label>Status</label>
|
|
|
|
</div>
|
|
|
|
</div>
|
2024-06-20 06:46:12 +00:00
|
|
|
<nav class="no-space">
|
|
|
|
@if (confirmDelete) {
|
|
|
|
<button @onclick="ConfirmDeleteStatus" 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="DeleteStatus" 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-13 10:02:51 +00:00
|
|
|
<InputText id="status-emoji-input" class="invisible" @bind-Value="Emoji"></InputText>
|
|
|
|
<button class="transparent link" data-ui="#@id" disabled="@loading">Cancel</button>
|
|
|
|
<button @onclick="PatchStatus" disabled="@loading">
|
|
|
|
@if (loading) {
|
|
|
|
<span>Saving...</span>
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
<i class="fa-solid fa-floppy-disk"></i> <span>Save</span>
|
|
|
|
}
|
|
|
|
</button>
|
|
|
|
</nav>
|
|
|
|
</dialog>
|
|
|
|
|
|
|
|
@code {
|
|
|
|
private Status? _status;
|
|
|
|
|
|
|
|
public Status? Status {
|
|
|
|
get => _status;
|
|
|
|
set {
|
|
|
|
_status = value;
|
|
|
|
Content = _status?.Content;
|
|
|
|
Emoji = _status?.Emoji;
|
|
|
|
InvokeAsync(StateHasChanged);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
public string? Content { get; set; }
|
|
|
|
public string? Emoji { get; set; }
|
|
|
|
private bool loading = false;
|
|
|
|
[Parameter]
|
|
|
|
public string id { get; set; }
|
2024-06-20 06:46:12 +00:00
|
|
|
private bool confirmDelete { get; set; }
|
2024-06-13 10:02:51 +00:00
|
|
|
|
|
|
|
protected override async Task OnInitializedAsync() {
|
|
|
|
Content = Status?.Content;
|
|
|
|
Emoji = Status?.Emoji;
|
|
|
|
}
|
|
|
|
|
2024-06-20 06:46:12 +00:00
|
|
|
public async Task DeleteStatus() {
|
|
|
|
if (!confirmDelete) confirmDelete = true;
|
|
|
|
await InvokeAsync(StateHasChanged);
|
|
|
|
}
|
|
|
|
|
|
|
|
public async Task ConfirmDeleteStatus() {
|
|
|
|
if(confirmDelete) {
|
|
|
|
loading = true;
|
|
|
|
await InvokeAsync(StateHasChanged);
|
|
|
|
|
|
|
|
if (!string.IsNullOrEmpty(Status?.Id)) {
|
|
|
|
await api.DeleteStatus(State.SelectedAddressName, Status.Id);
|
|
|
|
await State.RefreshStatuses();
|
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
|
|
|
|
Content = string.Empty;
|
|
|
|
Emoji = string.Empty;
|
|
|
|
Status = null;
|
|
|
|
loading = false;
|
|
|
|
confirmDelete = false;
|
|
|
|
await InvokeAsync(StateHasChanged);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2024-06-13 10:02:51 +00:00
|
|
|
public async Task PatchStatus() {
|
|
|
|
loading = true;
|
|
|
|
await InvokeAsync(StateHasChanged);
|
|
|
|
|
|
|
|
if (!string.IsNullOrEmpty(Status?.Id)) {
|
|
|
|
await api.PatchStatus(State.SelectedAddressName, Status.Id, Content, Emoji);
|
|
|
|
await State.RefreshStatuses();
|
2024-06-24 04:52:45 +00:00
|
|
|
State.SendRefresh();
|
2024-06-13 10:02:51 +00:00
|
|
|
await InvokeAsync(StateHasChanged);
|
|
|
|
}
|
|
|
|
|
|
|
|
await JS.InvokeVoidAsync("ui", "#" + id);
|
|
|
|
// clear input
|
|
|
|
Content = string.Empty;
|
|
|
|
Emoji = string.Empty;
|
|
|
|
Status = null;
|
|
|
|
loading = false;
|
2024-06-20 06:46:12 +00:00
|
|
|
confirmDelete = false;
|
2024-06-13 10:02:51 +00:00
|
|
|
await InvokeAsync(StateHasChanged);
|
|
|
|
|
|
|
|
}
|
|
|
|
}
|