@@ -21,29 +21,48 @@ export const useReportSync = () => {
2121
2222 // Only fetch the latest if the current report instance is older, or doesn't exist.
2323 if ( report && ( ! instance || instance . version !== message . version ) ) {
24- const response = await getReportInstance ( message . id , true ) ;
25- if ( response . status === 200 && response . data ) {
26- const instance = response . data ;
24+ if ( message . message === 'status' ) {
25+ // Update the status of the instance.
2726 storeMyReports ( ( reports ) => {
28- let addInstance = true ;
29- let instances = report . instances . map ( ( i ) => {
30- if ( i . id === message . id ) {
31- addInstance = false ;
32- return instance ;
33- }
34- return i ;
35- } ) ;
36- if ( addInstance ) instances = [ instance , ...instances ] ;
3727 const results = reports . map ( ( r ) =>
3828 r . id === report . id
3929 ? {
4030 ...report ,
41- instances,
31+ instances : report . instances . map ( ( i ) =>
32+ i . id === message . id
33+ ? { ...i , status : message . status , version : message . version }
34+ : i ,
35+ ) ,
4236 }
4337 : r ,
4438 ) ;
4539 return results ;
4640 } ) ;
41+ } else {
42+ const response = await getReportInstance ( message . id , true ) ;
43+ if ( response . status === 200 && response . data ) {
44+ const instance = response . data ;
45+ storeMyReports ( ( reports ) => {
46+ let addInstance = true ;
47+ let instances = report . instances . map ( ( i ) => {
48+ if ( i . id === message . id ) {
49+ addInstance = false ;
50+ return instance ;
51+ }
52+ return i ;
53+ } ) ;
54+ if ( addInstance ) instances = [ instance , ...instances ] ;
55+ const results = reports . map ( ( r ) =>
56+ r . id === report . id
57+ ? {
58+ ...report ,
59+ instances,
60+ }
61+ : r ,
62+ ) ;
63+ return results ;
64+ } ) ;
65+ }
4766 }
4867 }
4968 } catch { }
0 commit comments