-
Notifications
You must be signed in to change notification settings - Fork 20
/
NotificationInitializer.razor.cs
54 lines (43 loc) · 1.55 KB
/
NotificationInitializer.razor.cs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
using Microsoft.AspNetCore.Components;
using Fluxor;
using Fluxor.Blazor.Web.Components;
using Luthetus.Common.RazorLib.Notifications.States;
using Luthetus.Common.RazorLib.Contexts.Displays;
using Luthetus.Common.RazorLib.Dynamics.Models;
namespace Luthetus.Common.RazorLib.Notifications.Displays;
public partial class NotificationInitializer : FluxorComponent
{
[Inject]
private IState<NotificationState> NotificationStateWrap { get; set; } = null!;
[Inject]
private IDispatcher Dispatcher { get; set; } = null!;
private bool _disposedValue;
private ContextBoundary? _notificationContextBoundary;
private Task HandleOnFocusIn(INotification notification)
{
var localNotificationContextBoundary = _notificationContextBoundary;
if (localNotificationContextBoundary is not null)
localNotificationContextBoundary.HandleOnFocusIn();
return Task.CompletedTask;
}
private Task HandleOnFocusOut(INotification notification)
{
return Task.CompletedTask;
}
protected override ValueTask DisposeAsyncCore(bool disposing)
{
if (!_disposedValue)
{
if (disposing)
{
var notificationState = NotificationStateWrap.Value;
foreach (var notification in notificationState.DefaultList)
{
Dispatcher.Dispatch(new NotificationState.DisposeAction(notification.DynamicViewModelKey));
}
}
_disposedValue = true;
}
return base.DisposeAsyncCore(disposing);
}
}