diff --git a/CulinaryCommandApp/Components/Pages/Assignments/AdminAssignTask.razor b/CulinaryCommandApp/Components/Pages/Assignments/AdminAssignTask.razor
index 9480631..c8364e4 100644
--- a/CulinaryCommandApp/Components/Pages/Assignments/AdminAssignTask.razor
+++ b/CulinaryCommandApp/Components/Pages/Assignments/AdminAssignTask.razor
@@ -14,6 +14,7 @@
@inject LocationState LocationState
@inject ITaskAssignmentService TaskService
@inject IRecipeService RecipeService
+@inject ITaskNotificationService TaskNotifier
@implements IDisposable
@rendermode InteractiveServer
@@ -416,6 +417,9 @@ else
// RecipeId left null; choose fresh per task
};
+ //
+ await TaskNotifier.NotifyTasksChangedAsync(selectedLocationId.Value);
+
await InvokeAsync(StateHasChanged);
}
diff --git a/CulinaryCommandApp/Components/Pages/Assignments/MyTasks.razor b/CulinaryCommandApp/Components/Pages/Assignments/MyTasks.razor
index fd8b81c..655235f 100644
--- a/CulinaryCommandApp/Components/Pages/Assignments/MyTasks.razor
+++ b/CulinaryCommandApp/Components/Pages/Assignments/MyTasks.razor
@@ -11,8 +11,9 @@
@inject ITaskAssignmentService TaskService
@inject LocationState LocationState
@inject NavigationManager Nav
+@inject ITaskNotificationService TaskNotifier
-@implements IDisposable
+@implements IDisposable
@rendermode InteractiveServer
My Tasks
@@ -67,6 +68,9 @@ else
{
_ctx = await UserCtx.GetAsync();
+ TaskNotifier.OnTasksChanged -= HandleTasksNotification;
+ TaskNotifier.OnTasksChanged += HandleTasksNotification;
+
// If not authenticated, bounce to Cognito login
if (_ctx.IsAuthenticated != true)
{
@@ -99,6 +103,17 @@ else
ready = true;
}
+ private async Task HandleTasksNotification(int locationId)
+ {
+ // only handle notifications for location we are viewing
+ if (locationId != selectedLocationId) return;
+
+ await InvokeAsync(async() => {
+ await LoadTasksAsync();
+ StateHasChanged();
+ });
+ }
+
private async Task LoadTasksAsync()
{
if (_isLoadingTasks) return;
@@ -161,5 +176,7 @@ else
public void Dispose()
{
LocationState.OnChange -= HandleLocationStateChanged;
+ TaskNotifier.OnTasksChanged -= HandleTasksNotification;
+
}
}
diff --git a/CulinaryCommandApp/Program.cs b/CulinaryCommandApp/Program.cs
index b00b8a3..e9fe014 100644
--- a/CulinaryCommandApp/Program.cs
+++ b/CulinaryCommandApp/Program.cs
@@ -170,6 +170,7 @@
builder.Services.AddScoped();
builder.Services.AddScoped();
builder.Services.AddScoped();
+builder.Services.AddSingleton();
builder.Services.AddHttpClient();
diff --git a/CulinaryCommandApp/Services/TaskNotificationService.cs b/CulinaryCommandApp/Services/TaskNotificationService.cs
new file mode 100644
index 0000000..40335ed
--- /dev/null
+++ b/CulinaryCommandApp/Services/TaskNotificationService.cs
@@ -0,0 +1,18 @@
+namespace CulinaryCommand.Services;
+
+public interface ITaskNotificationService
+{
+ event Func? OnTasksChanged; // locationId
+ Task NotifyTasksChangedAsync(int locationId);
+}
+
+public class TaskNotificationService : ITaskNotificationService
+{
+ public event Func? OnTasksChanged;
+
+ public async Task NotifyTasksChangedAsync(int locationId)
+ {
+ if (OnTasksChanged is not null)
+ await OnTasksChanged.Invoke(locationId);
+ }
+}
\ No newline at end of file