-
-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
FW Lite push entry changes to frontend (#1029)
* setup a change event bus to allow the signalR hub to notify the client of changes. * create an event bus in the frontend to push changes to the project view * add SignalR hub to lexbox to allow listening to changes in a crdt project. * allow background sync to be triggered by project guid * setup fw lite backend to connect to the lexbox project change hub. * eliminate duplicate entry updated notifications * add logging on project updated listener * pass client Id to server when adding changes so that project update notifications can be filtered by client id * push change notifications when Senses or ExampleSentences are changed
- Loading branch information
Showing
21 changed files
with
398 additions
and
75 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,50 @@ | ||
using System.Reactive.Linq; | ||
using System.Reactive.Subjects; | ||
using LcmCrdt; | ||
using LcmCrdt.Objects; | ||
using LocalWebApp.Hubs; | ||
using Microsoft.AspNetCore.SignalR; | ||
|
||
namespace LocalWebApp.Services; | ||
|
||
public class ChangeEventBus(ProjectContext projectContext, IHubContext<CrdtMiniLcmApiHub, ILexboxHubClient> hubContext, ILogger<ChangeEventBus> logger) | ||
: IDisposable | ||
{ | ||
private IDisposable? _subscription; | ||
|
||
public void SetupGlobalSignalRSubscription() | ||
{ | ||
if (_subscription is not null) return; | ||
_subscription = _entryUpdated.Subscribe(notification => | ||
{ | ||
logger.LogInformation("Sending notification for {EntryId} to {ProjectName}", notification.Entry.Id, notification.ProjectName); | ||
_ = hubContext.Clients.Group(CrdtMiniLcmApiHub.ProjectGroup(notification.ProjectName)).OnEntryUpdated(notification.Entry); | ||
}); | ||
} | ||
|
||
private record struct ChangeNotification(Entry Entry, string ProjectName); | ||
|
||
private readonly Subject<ChangeNotification> _entryUpdated = new(); | ||
|
||
public IObservable<Entry> OnEntryUpdated | ||
{ | ||
get | ||
{ | ||
var projectName = projectContext.Project?.Name ?? throw new InvalidOperationException("Not in a project"); | ||
return _entryUpdated | ||
.Where(n => n.ProjectName == projectName) | ||
.Select(n => n.Entry); | ||
} | ||
} | ||
|
||
public void NotifyEntryUpdated(Entry entry) | ||
{ | ||
_entryUpdated.OnNext(new ChangeNotification(entry, | ||
projectContext.Project?.Name ?? throw new InvalidOperationException("Not in a project"))); | ||
} | ||
|
||
public void Dispose() | ||
{ | ||
_subscription?.Dispose(); | ||
} | ||
} |
Oops, something went wrong.