Extract workspace feedback service

This commit is contained in:
2026-04-04 23:57:59 +02:00
parent 4f77d4a702
commit 0124325c20
3 changed files with 61 additions and 29 deletions

View File

@@ -1077,41 +1077,17 @@ public partial class Workspace : IAsyncDisposable
AdminUsers = [];
HasLoadedAdminUsers = false;
IsAdminDataLoading = false;
Toasts.Clear();
Feedback.ClearToasts();
}
private void SetStatus(string message, bool isError)
{
AddToast(message, isError);
Announce(message);
Feedback.SetStatus(message, isError);
}
private void Announce(string message)
{
LiveAnnouncement = message;
}
private void AddToast(string message, bool isError)
{
var toastId = Guid.NewGuid();
Toasts.Add(new WorkspaceToast(toastId, message, isError));
_ = DismissToastLaterAsync(toastId);
}
private async Task DismissToastLaterAsync(Guid toastId)
{
await Task.Delay(ToastDurationMs);
if (Toasts.RemoveAll(toast => toast.Id == toastId) == 0)
return;
try
{
await InvokeAsync(StateHasChanged);
}
catch (ObjectDisposedException)
{
}
Feedback.Announce(message);
}
private void ToggleScreenMenu()
@@ -1220,6 +1196,7 @@ public partial class Workspace : IAsyncDisposable
private bool IsPlayScreen => State.IsPlayScreen;
private bool IsManagementScreen => State.IsManagementScreen;
private bool IsAdminScreen => State.IsAdminScreen;
private WorkspaceFeedbackService Feedback => m_Feedback ??= new(State, () => InvokeAsync(StateHasChanged));
private IReadOnlyList<AppHeaderMenuItem> HeaderMenuItems
{
get
@@ -1250,5 +1227,6 @@ public partial class Workspace : IAsyncDisposable
private const string MobilePanelSessionKey = "play-panel";
private const string RollVisibilitySessionKey = "roll-visibility";
private const int CampaignLogWindowSize = 25;
private const int ToastDurationMs = 3200;
private WorkspaceFeedbackService? m_Feedback;
}