11using System . ComponentModel . DataAnnotations ;
22using Fluxor ;
33using PocketDDD . BlazorClient . Features . EventScore . Store ;
4+ using PocketDDD . BlazorClient . Features . Sync . Store ;
45using PocketDDD . BlazorClient . Services ;
56using PocketDDD . Shared . API . RequestDTOs ;
67
@@ -27,76 +28,118 @@ public SyncEffects(IState<SyncState> state, IDispatcher dispatcher, LocalStorage
2728 [ EffectMethod ]
2829 public async Task OnSync ( SyncAction action , IDispatcher dispatcher )
2930 {
31+ dispatcher . Dispatch ( new SyncEventAction ( ) ) ;
32+ dispatcher . Dispatch ( new SyncEventFeedbackAction ( ) ) ;
33+ dispatcher . Dispatch ( new SyncSessionFeedbackAction ( ) ) ;
34+ }
35+
36+ [ EffectMethod ]
37+ public async Task OnSyncEvent ( SyncEventAction action , IDispatcher dispatcher )
38+ {
39+ dispatcher . Dispatch ( new SetSyncingEventAction ( true ) ) ;
40+
3041 try
3142 {
3243 var eventData = await _localStorage . EventData . GetAsync ( ) ;
3344 var eventDataVersion = eventData ? . Version ?? 0 ;
3445
35- try
36- {
37- var newEventData = await _pocketDDDAPI . FetchLatestEventData ( new EventDataUpdateRequestDTO { Version = eventDataVersion } ) ;
46+ var newEventData = await _pocketDDDAPI . FetchLatestEventData ( new EventDataUpdateRequestDTO { Version = eventDataVersion } ) ;
3847
39- if ( newEventData is not null )
40- {
41- await _localStorage . EventData . SetAsync ( newEventData ) ;
42- }
43- }
44- catch
45- {
46- // ignored
47- }
48+ if ( newEventData is not null )
49+ await _localStorage . EventData . SetAsync ( newEventData ) ;
50+ }
51+ catch
52+ {
53+ // ignored
54+ }
55+ finally
56+ {
57+ dispatcher . Dispatch ( new SetSyncingEventAction ( false ) ) ;
58+ }
59+ }
4860
61+ [ EffectMethod ]
62+ public async Task OnSyncEventFeedback ( SyncEventFeedbackAction action , IDispatcher dispatcher )
63+ {
64+ try
65+ {
4966 var eventFeedbackItems = await _localStorage . EventFeedbackSync . GetAllSyncItemsAsync ( ) ;
50- var sessionFeedbackItems = await _localStorage . SessionFeedbackSync . GetAllSyncItemsAsync ( ) ;
51-
5267 dispatcher . Dispatch ( new SyncEventFeedbackItemsAction ( eventFeedbackItems ) ) ;
53- dispatcher . Dispatch ( new SyncSessionFeedbackItemsAction ( sessionFeedbackItems ) ) ;
5468 }
5569 catch
5670 {
5771 // ignored
5872 }
59- finally
73+ }
74+
75+ [ EffectMethod ]
76+ public async Task OnSyncSessionFeedback ( SyncSessionFeedbackAction action , IDispatcher dispatcher )
77+ {
78+ try
79+ {
80+ var sessionFeedbackItems = await _localStorage . SessionFeedbackSync . GetAllSyncItemsAsync ( ) ;
81+ dispatcher . Dispatch ( new SyncSessionFeedbackItemsAction ( sessionFeedbackItems ) ) ;
82+ }
83+ catch
6084 {
61- dispatcher . Dispatch ( new SyncCompletedAction ( ) ) ;
85+ // ignored
6286 }
6387 }
6488
89+
6590 [ EffectMethod ]
6691 public async Task OnSyncEventFeedbackItems ( SyncEventFeedbackItemsAction action , IDispatcher dispatcher )
6792 {
68- var syncItems = action . syncItems ;
69- foreach ( var item in syncItems )
93+ dispatcher . Dispatch ( new SetSyncingEventFeedbackAction ( true ) ) ;
94+
95+ try
7096 {
71- try
72- {
73- var result = await _pocketDDDAPI . SubmitClientEventFeedback ( item ) ;
74- await _localStorage . EventFeedbackSync . RemoveSyncItemAsync ( result . ClientId ) ;
75- dispatcher . Dispatch ( new EventScoreUpdatedAction ( result . Score ) ) ;
76- }
77- catch
97+ var syncItems = action . SyncItems ;
98+ foreach ( var item in syncItems )
7899 {
79- // ignored
100+ try
101+ {
102+ var result = await _pocketDDDAPI . SubmitClientEventFeedback ( item ) ;
103+ await _localStorage . EventFeedbackSync . RemoveSyncItemAsync ( result . ClientId ) ;
104+ dispatcher . Dispatch ( new EventScoreUpdatedAction ( result . Score ) ) ;
105+ }
106+ catch
107+ {
108+ // ignored
109+ }
80110 }
81111 }
112+ finally
113+ {
114+ dispatcher . Dispatch ( new SetSyncingEventFeedbackAction ( false ) ) ;
115+ }
82116 }
83117
84118 [ EffectMethod ]
85119 public async Task OnSyncSessionFeedbackItems ( SyncSessionFeedbackItemsAction action , IDispatcher dispatcher )
86120 {
87- var syncItems = action . syncItems ;
88- foreach ( var item in syncItems )
121+ dispatcher . Dispatch ( new SetSyncingSessionFeedbackAction ( true ) ) ;
122+
123+ try
89124 {
90- try
91- {
92- var result = await _pocketDDDAPI . SubmitClientSessionFeedback ( item ) ;
93- await _localStorage . SessionFeedbackSync . RemoveSyncItemAsync ( result . ClientId ) ;
94- dispatcher . Dispatch ( new EventScoreUpdatedAction ( result . Score ) ) ;
95- }
96- catch
125+ var syncItems = action . SyncItems ;
126+ foreach ( var item in syncItems )
97127 {
98- // ignored
128+ try
129+ {
130+ var result = await _pocketDDDAPI . SubmitClientSessionFeedback ( item ) ;
131+ await _localStorage . SessionFeedbackSync . RemoveSyncItemAsync ( result . ClientId ) ;
132+ dispatcher . Dispatch ( new EventScoreUpdatedAction ( result . Score ) ) ;
133+ }
134+ catch
135+ {
136+ // ignored
137+ }
99138 }
100139 }
140+ finally
141+ {
142+ dispatcher . Dispatch ( new SetSyncingSessionFeedbackAction ( false ) ) ;
143+ }
101144 }
102145}
0 commit comments