2024-06-05 12:41:08 +00:00
@page "/ephemeral"
2024-06-18 01:44:18 +00:00
@implements IDisposable
2024-06-13 04:46:24 +00:00
@inject IJSRuntime JS
@inject State State
2024-06-18 01:44:18 +00:00
<RefreshButton></RefreshButton>
2024-06-13 04:46:24 +00:00
<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-13 04:46:24 +00:00
<div id="ephemeral" class="responsive">
2024-06-05 12:41:08 +00:00
2024-06-13 04:46:24 +00:00
@if (messages != null) {
foreach (MarkupString message in messages) {
<article class="ephemeral center">
@message
</article>
}
}
2024-06-05 12:41:08 +00:00
2024-06-13 04:46:24 +00:00
<LoadingCard id="ephemeral-loading" icon="fa-light fa-comment-dots"></LoadingCard>
</div>
2024-06-05 12:41:08 +00:00
@code {
2024-06-13 04:46:24 +00:00
private List<MarkupString>? messages;
2024-06-05 12:41:08 +00:00
protected override async Task OnInitializedAsync() {
2024-06-13 04:46:24 +00:00
await base.OnInitializedAsync();
if (messages == null || messages.Count == 0) messages = await State.GetEphemeralMessages();
2024-06-18 01:44:18 +00:00
State.PropertyChanged += StateChanged;
State.CanRefresh = true;
2024-06-13 04:46:24 +00:00
await InvokeAsync(StateHasChanged);
await JS.InvokeVoidAsync("removeElementById", "ephemeral-loading");
2024-06-05 12:41:08 +00:00
}
2024-06-18 01:44:18 +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);
}
2024-06-18 01:44:18 +00:00
}
}
public void Dispose() {
State.PropertyChanged -= StateChanged;
State.CanRefresh = false;
}
2024-06-13 04:46:24 +00:00
}