11import { type FC } from 'react' ;
2- import { useDispatch } from 'react-redux' ;
2+ import { useDispatch , useStore } from 'react-redux' ;
33
44import type { StagedAction } from '~transitions' ;
55
@@ -9,11 +9,16 @@ import { ProjectBoard } from '~usecases/lib/components/projects/ProjectBoard';
99import { Layout , type UsecaseDescription } from '~usecases/lib/components/todo/Layout' ;
1010import { TodoApp } from '~usecases/lib/components/todo/TodoApp' ;
1111import { useAutoRetry } from '~usecases/lib/hooks/useAutoRetry' ;
12+ import { activitySelectors } from '~usecases/lib/store/activity/reducer' ;
1213import { dismissActivity , editActivity , logActivity } from '~usecases/lib/store/activity/actions' ;
1314import { createEpic , deleteEpic , editEpic } from '~usecases/lib/store/epics/actions' ;
15+ import { epicsSelectors } from '~usecases/lib/store/epics/reducer' ;
16+ import { profileSelectors } from '~usecases/lib/store/profile/reducer' ;
1417import { updateProfile } from '~usecases/lib/store/profile/actions' ;
18+ import { projectsSelectors } from '~usecases/lib/store/projects/reducer' ;
1519import { createProjectTodo , deleteProjectTodo , editProjectTodo } from '~usecases/lib/store/projects/actions' ;
1620import type { ActivityEntry , Epic , Profile , ProjectTodo } from '~usecases/lib/store/types' ;
21+ import type { State } from '~usecases/lib/store/store' ;
1722import { generateId , simulateAPIRequest } from '~usecases/lib/utils/mock-api' ;
1823
1924import { C , F , O } from '~usecases/lib/components/todo/CodeTags' ;
@@ -144,14 +149,27 @@ export const App: FC = () => {
144149 } ;
145150
146151 /** Route failed transitions through the correct lifecycle handler on reconnect */
147- useAutoRetry ( ( action : StagedAction ) => {
152+ const store = useStore < State > ( ) ;
153+
154+ const retryAction = ( action : StagedAction ) => {
148155 if ( createEpic . stage . match ( action ) ) return handleCreateEpic ( action . payload ) ;
149156 if ( editEpic . stage . match ( action ) ) return handleEditEpic ( action . payload as Epic ) ;
150157 if ( updateProfile . stage . match ( action ) ) return handleUpdateProfile ( action . payload ) ;
151158 if ( createProjectTodo . stage . match ( action ) ) return handleCreateProjectTodo ( action . payload ) ;
152159 if ( editProjectTodo . stage . match ( action ) ) return handleEditProjectTodo ( action . payload as ProjectTodo ) ;
153160 if ( logActivity . stage . match ( action ) ) return handleLogActivity ( action . payload ) ;
154161 if ( editActivity . stage . match ( action ) ) return handleEditActivity ( action . payload as ActivityEntry ) ;
162+ } ;
163+
164+ useAutoRetry ( ( ) => {
165+ const state = store . getState ( ) ;
166+ const failed = [
167+ ...epicsSelectors . selectFailures ( state . epics ) ,
168+ ...profileSelectors . selectFailures ( state . profile ) ,
169+ ...projectsSelectors . selectFailures ( state . projects ) ,
170+ ...activitySelectors . selectFailures ( state . activity ) ,
171+ ] ;
172+ failed . forEach ( retryAction ) ;
155173 } ) ;
156174
157175 return (
0 commit comments