feat: implement real-time reading progress and refactor profile to CQRS

This commit is contained in:
2026-05-10 18:15:29 +02:00
parent 10dc511f2a
commit b456194ea1
20 changed files with 1738 additions and 96 deletions
@@ -118,8 +118,18 @@
{
await Coordinator.OnBlockReachedAsync(blockId, content);
// Debounce sync update (simple version: every 5 seconds or on a timer)
await SyncService.UpdateProgressAsync(blockId);
if (ViewModel != null)
{
// Calculate progress: (CurrentChapter / TotalChapters) * 100
// Simple approximation for now: chapter-based
double progress = ((double)(ViewModel.CurrentChapterIndex + 1) / ViewModel.TotalChapters) * 100;
await SyncService.UpdateProgressAsync(
blockId,
ViewModel.EbookId,
progress,
ViewModel.ChapterTitle);
}
}
private async Task HandleSyncProgressReceived(string blockId, DateTime timestamp)
@@ -5,7 +5,7 @@ namespace NexusReader.UI.Shared.Services;
public interface ISyncService
{
Task<Result> InitializeAsync();
Task<Result> UpdateProgressAsync(string pageId);
Task<Result> UpdateProgressAsync(string pageId, Guid ebookId, double progress, string? chapterTitle);
event Func<string, DateTime, Task> OnProgressReceived;
Task DisposeAsync();
}
@@ -46,6 +46,7 @@ public class SyncService : ISyncService, IAsyncDisposable
_hubConnection.On<string, DateTime>("ProgressUpdated", async (pageId, timestamp) =>
{
// Note: In the future we might want to receive ebookId and progress here too
if (OnProgressReceived != null) await OnProgressReceived(pageId, timestamp);
});
@@ -63,7 +64,7 @@ public class SyncService : ISyncService, IAsyncDisposable
private string? _lastSentPageId;
public async Task<Result> UpdateProgressAsync(string pageId)
public async Task<Result> UpdateProgressAsync(string pageId, Guid ebookId, double progress, string? chapterTitle)
{
if (pageId == _lastSentPageId) return Result.Ok();
@@ -82,7 +83,7 @@ public class SyncService : ISyncService, IAsyncDisposable
if (_hubConnection?.State == HubConnectionState.Connected)
{
await _hubConnection.SendAsync("UpdateProgress", pageId, token);
await _hubConnection.SendAsync("UpdateProgress", pageId, ebookId, progress, chapterTitle, token);
_lastSentPageId = pageId;
}
}