Neighbourhood.omg.lol/Components/StatusList.razor

52 lines
1.4 KiB
Text
Raw Normal View History

@implements IDisposable
@inject IJSRuntime JS
@inject State State
2024-06-13 10:02:51 +00:00
@if (Editable) {
<EditStatusDialog @ref="Dialog" id="EditStatusModal"></EditStatusDialog>
}
@if(statuses != null) foreach(Status status in statuses) {
2024-06-13 10:02:51 +00:00
<StatusCard Status="@status" Editable="Editable" Dialog="Dialog"></StatusCard>
}
<LoadingCard id="statusLoading" icon="fa-solid fa-message-smile"></LoadingCard>
2024-06-05 12:41:08 +00:00
@code {
[Parameter]
2024-07-02 00:13:52 +00:00
public Func<bool, Task<List<Status>?>>? StatusFunc { get; set; }
[Parameter]
public bool Editable { get; set; } = false;
2024-06-13 10:02:51 +00:00
public EditStatusDialog? Dialog { get; set; }
2024-06-24 04:52:45 +00:00
private List<Status>? statuses;
2024-06-13 00:26:43 +00:00
protected override async Task OnInitializedAsync() {
await base.OnInitializedAsync();
2024-07-02 00:13:52 +00:00
if (StatusFunc == null) return;
if (statuses == null || statuses.Count == 0) statuses = await StatusFunc(false);
State.PropertyChanged += StateChanged;
State.CanRefresh = true;
await InvokeAsync(StateHasChanged);
await JS.InvokeVoidAsync("removeElementById", "statusLoading");
2024-06-13 00:26:43 +00:00
}
private async void StateChanged(object? sender, PropertyChangedEventArgs e) {
2024-07-02 00:13:52 +00:00
if (StatusFunc == null) return;
if (e.PropertyName == nameof(State.IsRefreshing) && State.IsRefreshing) {
2024-06-24 04:52:45 +00:00
using (State.GetRefreshToken()) {
statuses = await StatusFunc(true);
await InvokeAsync(StateHasChanged);
}
}
}
public void Dispose() {
State.PropertyChanged -= StateChanged;
State.CanRefresh = false;
}
2024-06-05 12:41:08 +00:00
}