Neighbourhood.omg.lol/Components/Pages/Ephemeral.razor

59 lines
1.7 KiB
Text
Raw Permalink Normal View History

2024-06-05 12:41:08 +00:00
@page "/ephemeral"
@implements IDisposable
@inject IJSRuntime JS
@inject State State
<RefreshButton></RefreshButton>
<PageHeading title="Eph.emer.al" icon="fa-light fa-comment-dots">
<Description><a href="https://eph.emer.al">Eph.emer.al</a> is a place for fleeting thoughts. Everything on this page will disappear after a while.</Description>
</PageHeading>
2024-06-05 12:41:08 +00:00
2024-06-30 23:44:55 +00:00
<AuthorizeView>
<Authorized>
<button class="fab circle extra large-elevate" data-ui="#ephemeral-modal">
<i class="fa-light fa-comment-plus"></i>
</button>
<NewEphemeral id="ephemeral-modal"></NewEphemeral>
</Authorized>
</AuthorizeView>
<div id="ephemeral" class="responsive">
2024-06-05 12:41:08 +00:00
@if (messages != null) {
foreach (MarkupString message in messages) {
2024-07-02 02:55:07 +00:00
<article class="ephemeral">
@message
</article>
}
}
2024-06-05 12:41:08 +00:00
<LoadingCard id="ephemeral-loading" icon="fa-light fa-comment-dots"></LoadingCard>
</div>
2024-06-05 12:41:08 +00:00
@code {
private List<MarkupString>? messages;
2024-06-05 12:41:08 +00:00
protected override async Task OnInitializedAsync() {
await base.OnInitializedAsync();
if (messages == null || messages.Count == 0) messages = await State.GetEphemeralMessages();
State.PropertyChanged += StateChanged;
State.CanRefresh = true;
await InvokeAsync(StateHasChanged);
await JS.InvokeVoidAsync("removeElementById", "ephemeral-loading");
2024-06-05 12:41:08 +00:00
}
private async void StateChanged(object? sender, PropertyChangedEventArgs e) {
if (e.PropertyName == nameof(State.IsRefreshing) && State.IsRefreshing) {
2024-06-24 04:52:45 +00:00
using (State.GetRefreshToken()) {
messages = await State.GetEphemeralMessages(true);
await InvokeAsync(StateHasChanged);
}
}
}
public void Dispose() {
State.PropertyChanged -= StateChanged;
State.CanRefresh = false;
}
}