Skip to content

Commit f0f65db

Browse files
committed
Add in sync item count
1 parent d81d9e6 commit f0f65db

5 files changed

Lines changed: 24 additions & 1 deletion

File tree

PocketDDD.BlazorClient/PocketDDD.BlazorClient.LocalStorage/LocalStorageContext.cs

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -114,6 +114,11 @@ public async ValueTask<IList<T>> GetAllSyncItemsAsync()
114114
}
115115
return items;
116116
}
117+
public async ValueTask<int> GetItemCountAsync()
118+
{
119+
var keys = await _localStorage.KeysAsync();
120+
return keys.Count(x => x.StartsWith(_keyPrefix));
121+
}
117122

118123
public ValueTask AddSyncItemAsync(T item, string clientId) =>
119124
_localStorage.SetItemAsync(_keyPrefix + clientId, item);

PocketDDD.BlazorClient/PocketDDD.BlazorClient/Features/Sync/Services/SyncService.cs

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -67,6 +67,7 @@ public async Task SyncEventFeedback()
6767
public async Task SyncEventFeedbackItems(IList<SubmitEventFeedbackDTO> syncItems)
6868
{
6969
_dispatcher.Dispatch(new SetSyncingEventFeedbackAction(true));
70+
_dispatcher.Dispatch(new SetOutstandingEventFeedbackSyncCountAction(syncItems.Count));
7071

7172
try
7273
{
@@ -83,6 +84,9 @@ public async Task SyncEventFeedbackItems(IList<SubmitEventFeedbackDTO> syncItems
8384
// ignored
8485
}
8586
}
87+
88+
var newItemCount = await _localStorage.EventFeedbackSync.GetItemCountAsync();
89+
_dispatcher.Dispatch(new SetOutstandingEventFeedbackSyncCountAction(newItemCount));
8690
}
8791
finally
8892
{
@@ -106,6 +110,7 @@ public async Task SyncSessionFeedback()
106110
public async Task SyncSessionFeedbackItems(IList<SubmitSessionFeedbackDTO> syncItems)
107111
{
108112
_dispatcher.Dispatch(new SetSyncingSessionFeedbackAction(true));
113+
_dispatcher.Dispatch(new SetOutstandingSessionFeedbackSyncCountAction(syncItems.Count));
109114

110115
try
111116
{
@@ -122,6 +127,9 @@ public async Task SyncSessionFeedbackItems(IList<SubmitSessionFeedbackDTO> syncI
122127
// ignored
123128
}
124129
}
130+
131+
var newItemCount = await _localStorage.SessionFeedbackSync.GetItemCountAsync();
132+
_dispatcher.Dispatch(new SetOutstandingSessionFeedbackSyncCountAction(newItemCount));
125133
}
126134
finally
127135
{

PocketDDD.BlazorClient/PocketDDD.BlazorClient/Features/Sync/Store/SyncActions.cs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,3 +7,5 @@ public record SyncAction;
77
public record SetSyncingEventAction(bool Syncing);
88
public record SetSyncingEventFeedbackAction(bool Syncing);
99
public record SetSyncingSessionFeedbackAction(bool Syncing);
10+
public record SetOutstandingEventFeedbackSyncCountAction(int Count);
11+
public record SetOutstandingSessionFeedbackSyncCountAction(int Count);

PocketDDD.BlazorClient/PocketDDD.BlazorClient/Features/Sync/Store/SyncReducer.cs

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,10 +10,18 @@ public static class SyncReducer
1010
public static SyncState OnSetSyncingEvent(SyncState state, SetSyncingEventAction action) =>
1111
state with { IsSyncingEvent = action.Syncing };
1212

13+
[ReducerMethod]
14+
public static SyncState OnSetOutstandingEventFeedbackSyncCount(SyncState state, SetOutstandingEventFeedbackSyncCountAction action) =>
15+
state with { OutstandingEventFeedbackSyncCount = action.Count };
16+
1317
[ReducerMethod]
1418
public static SyncState OnSetSyncingEventFeedback(SyncState state, SetSyncingEventFeedbackAction action) =>
1519
state with { IsSyncingEventFeedback = action.Syncing };
1620

21+
[ReducerMethod]
22+
public static SyncState OnSetOutstandingSessionFeedbackSyncCountAction(SyncState state, SetOutstandingSessionFeedbackSyncCountAction action) =>
23+
state with { OutstandingSessionFeedbackSyncCount = action.Count };
24+
1725
[ReducerMethod]
1826
public static SyncState OnSetSyncingSessionFeedbackAction(SyncState state, SetSyncingSessionFeedbackAction action) =>
1927
state with { IsSyncingSessionFeedback = action.Syncing };

PocketDDD.BlazorClient/PocketDDD.BlazorClient/wwwroot/index.html

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@
2424
<script>
2525
if (window.location.hostname.includes("localhost") || window.location.hostname.includes("development")) {
2626
Blazor.start({
27-
environment: "Development"
27+
environment: "Test"
2828
});
2929
} else if (window.location.hostname.includes("test")) {
3030
Blazor.start({

0 commit comments

Comments
 (0)