Neighbourhood.omg.lol/Components/NewStatusDialog.razor

97 lines
3.2 KiB
Text
Raw Normal View History

2024-06-05 12:41:08 +00:00
@inject IJSRuntime JS
@inject State State
@inject RestService api
@inject NavigationManager navigationManager
2024-06-05 12:41:08 +00:00
<div class="overlay @(Active ? "active" : string.Empty)" data-ui="#@id"></div>
<dialog id="@id" class="@(Active ? "active" : string.Empty)" open="@Active">
2024-06-05 12:41:08 +00:00
<h5>Share your status</h5>
<div class="row">
<div class="min square extra">
<button class="transparent square extra no-margin">
2024-06-20 06:46:12 +00:00
<object id="new-status-emoji" class="large emoji @(Emoji == null ? "animated" : string.Empty)" data-emoji="@(Emoji ?? "🫥")">@(Emoji ?? "🫥")</object>
2024-06-05 12:41:08 +00:00
<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 => {
2024-06-20 06:46:12 +00:00
document.getElementById('new-status-emoji').setAttribute('data-emoji', event.detail.unicode)
const input = document.getElementById('new-status-emoji-input')
2024-06-05 12:41:08 +00:00
input.value = event.detail.unicode
var event = new Event('change');
input.dispatchEvent(event);
})
</script>
</menu>
</button>
</div>
<div class="field textarea border max">
<InputTextArea @bind-Value="Content"></InputTextArea>
2024-06-05 12:41:08 +00:00
</div>
</div>
<nav class="right-align no-space">
@if (State?.SelectedAddress?.Preferences?.Statuslog?.MastodonPosting ?? false) {
<label class="checkbox">
<InputCheckbox @bind-Value="postToMastodon"></InputCheckbox>
<span>Post this to Mastodon</span>
</label>
}
2024-06-20 06:46:12 +00:00
<InputText id="new-status-emoji-input" class="invisible" @bind-Value="Emoji"></InputText>
2024-06-05 12:41:08 +00:00
<button class="transparent link" data-ui="#@id" disabled="@loading">Cancel</button>
<button @onclick="PostStatus" disabled="@loading">
@if (loading) {
<span>Saving...</span>
}
else {
<i class="fa-solid fa-floppy-disk"></i> <span>Save</span>
}
</button>
</nav>
</dialog>
@code {
[Parameter]
2024-07-02 00:13:52 +00:00
public string? id { get; set; }
[Parameter]
public bool Active { get; set; }
[Parameter]
public string Content { get; set; } = string.Empty;
[Parameter]
public string? Emoji { get; set; } = null;
[Parameter]
public bool postToMastodon { get; set; } = true;
private bool loading = false;
2024-06-05 12:41:08 +00:00
public async Task PostStatus() {
StatusPost post = new StatusPost
{
Emoji = Emoji,
Content = Content
2024-06-05 12:41:08 +00:00
};
if (State?.SelectedAddress?.Preferences?.Statuslog?.MastodonPosting ?? false){
post.SkipMastodonPost = !postToMastodon;
}
loading = true;
await InvokeAsync(StateHasChanged);
var result = await api.StatusPost(State!.SelectedAddressName!, post);
2024-06-05 12:41:08 +00:00
if(result != null){
await State.RefreshStatuses();
2024-06-24 04:52:45 +00:00
State.SendRefresh();
await InvokeAsync(StateHasChanged);
2024-06-24 04:52:45 +00:00
// navigationManager.NavigateTo("/statuslog/latest");
2024-06-05 12:41:08 +00:00
}
this.Active = false;
2024-06-05 12:41:08 +00:00
await JS.InvokeVoidAsync("ui", "#" + id);
Content = string.Empty;
Emoji = null;
2024-06-05 12:41:08 +00:00
postToMastodon = true;
loading = false;
}
}