Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@
@inject LocationState LocationState
@inject ITaskAssignmentService TaskService
@inject IRecipeService RecipeService
@inject ITaskNotificationService TaskNotifier

@implements IDisposable
@rendermode InteractiveServer
Expand Down Expand Up @@ -416,6 +417,9 @@ else
// RecipeId left null; choose fresh per task
};

//
await TaskNotifier.NotifyTasksChangedAsync(selectedLocationId.Value);

await InvokeAsync(StateHasChanged);
}

Expand Down
19 changes: 18 additions & 1 deletion CulinaryCommandApp/Components/Pages/Assignments/MyTasks.razor
Original file line number Diff line number Diff line change
Expand Up @@ -11,8 +11,9 @@
@inject ITaskAssignmentService TaskService
@inject LocationState LocationState
@inject NavigationManager Nav
@inject ITaskNotificationService TaskNotifier

@implements IDisposable
@implements IDisposable
@rendermode InteractiveServer

<PageTitle>My Tasks</PageTitle>
Expand Down Expand Up @@ -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)
{
Expand Down Expand Up @@ -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;
Expand Down Expand Up @@ -161,5 +176,7 @@ else
public void Dispose()
{
LocationState.OnChange -= HandleLocationStateChanged;
TaskNotifier.OnTasksChanged -= HandleTasksNotification;

}
}
1 change: 1 addition & 0 deletions CulinaryCommandApp/Program.cs
Original file line number Diff line number Diff line change
Expand Up @@ -170,6 +170,7 @@
builder.Services.AddScoped<IVendorService, VendorService>();
builder.Services.AddScoped<LogoDevService>();
builder.Services.AddScoped<IFeedbackService, FeedbackService>();
builder.Services.AddSingleton<ITaskNotificationService, TaskNotificationService>();
builder.Services.AddHttpClient();


Expand Down
18 changes: 18 additions & 0 deletions CulinaryCommandApp/Services/TaskNotificationService.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
namespace CulinaryCommand.Services;

public interface ITaskNotificationService
{
event Func<int, Task>? OnTasksChanged; // locationId
Task NotifyTasksChangedAsync(int locationId);
}

public class TaskNotificationService : ITaskNotificationService
{
public event Func<int, Task>? OnTasksChanged;

public async Task NotifyTasksChangedAsync(int locationId)
{
if (OnTasksChanged is not null)
await OnTasksChanged.Invoke(locationId);
}
}
Loading