@@ -36,8 +36,8 @@ import {
36
36
MoreHoriz ,
37
37
Refresh
38
38
} from "@mui/icons-material" ;
39
- import { useGlobalInfoStore } from "../../context/globalInfo" ;
40
- import { checkRunsForRecording , deleteRecordingFromStorage , getStoredRecordings } from "../../api/storage" ;
39
+ import { useGlobalInfoStore , useCachedRecordings } from "../../context/globalInfo" ;
40
+ import { checkRunsForRecording , deleteRecordingFromStorage } from "../../api/storage" ;
41
41
import { Add } from "@mui/icons-material" ;
42
42
import { useNavigate } from 'react-router-dom' ;
43
43
import { canCreateBrowserInState , getActiveBrowserId , stopRecording } from "../../api/recording" ;
@@ -150,12 +150,11 @@ export const RecordingsTable = ({
150
150
const { t } = useTranslation ( ) ;
151
151
const [ page , setPage ] = React . useState ( 0 ) ;
152
152
const [ rowsPerPage , setRowsPerPage ] = React . useState ( 10 ) ;
153
- const [ rows , setRows ] = React . useState < Data [ ] > ( [ ] ) ;
153
+ const { data : recordingsData = [ ] , isLoading : isFetching , error , refetch } = useCachedRecordings ( ) ;
154
154
const [ isModalOpen , setModalOpen ] = React . useState ( false ) ;
155
155
const [ searchTerm , setSearchTerm ] = React . useState ( '' ) ;
156
156
const [ isWarningModalOpen , setWarningModalOpen ] = React . useState ( false ) ;
157
157
const [ activeBrowserId , setActiveBrowserId ] = React . useState ( '' ) ;
158
- const [ isFetching , setIsFetching ] = React . useState ( true ) ;
159
158
160
159
const columns = useMemo ( ( ) => [
161
160
{ id : 'interpret' , label : t ( 'recordingtable.run' ) , minWidth : 80 } ,
@@ -238,44 +237,42 @@ export const RecordingsTable = ({
238
237
if ( dateStr . includes ( 'PM' ) || dateStr . includes ( 'AM' ) ) {
239
238
return new Date ( dateStr ) ;
240
239
}
241
-
240
+
242
241
return new Date ( dateStr . replace ( / ( \d + ) \/ ( \d + ) \/ / , '$2/$1/' ) )
243
242
} catch {
244
243
return new Date ( 0 ) ;
245
244
}
246
245
} ;
247
246
248
- const fetchRecordings = useCallback ( async ( ) => {
249
- try {
250
- const recordings = await getStoredRecordings ( ) ;
251
- if ( recordings ) {
252
- const parsedRows = recordings
253
- . map ( ( recording : any , index : number ) => {
254
- if ( recording ?. recording_meta ) {
255
- const parsedDate = parseDateString ( recording . recording_meta . updatedAt ) ;
256
-
257
- return {
258
- id : index ,
259
- ...recording . recording_meta ,
260
- content : recording . recording ,
261
- parsedDate
262
- } ;
263
- }
264
- return null ;
265
- } )
266
- . filter ( Boolean )
267
- . sort ( ( a , b ) => b . parsedDate . getTime ( ) - a . parsedDate . getTime ( ) ) ;
268
-
269
- setRecordings ( parsedRows . map ( ( recording ) => recording . name ) ) ;
270
- setRows ( parsedRows ) ;
271
- }
272
- } catch ( error ) {
273
- console . error ( 'Error fetching recordings:' , error ) ;
274
- notify ( 'error' , t ( 'recordingtable.notifications.fetch_error' ) ) ;
275
- } finally {
276
- setIsFetching ( false ) ;
247
+ const rows = useMemo ( ( ) => {
248
+ if ( ! recordingsData ) return [ ] ;
249
+
250
+ const parsedRows = recordingsData
251
+ . map ( ( recording : any , index : number ) => {
252
+ if ( recording ?. recording_meta ) {
253
+ const parsedDate = parseDateString ( recording . recording_meta . updatedAt ) ;
254
+
255
+ return {
256
+ id : index ,
257
+ ...recording . recording_meta ,
258
+ content : recording . recording ,
259
+ parsedDate
260
+ } ;
261
+ }
262
+ return null ;
263
+ } )
264
+ . filter ( Boolean )
265
+ . sort ( ( a , b ) => b . parsedDate . getTime ( ) - a . parsedDate . getTime ( ) ) ;
266
+
267
+ return parsedRows ;
268
+ } , [ recordingsData ] ) ;
269
+
270
+ useEffect ( ( ) => {
271
+ if ( rows . length > 0 ) {
272
+ setRecordings ( rows . map ( ( recording ) => recording . name ) ) ;
277
273
}
278
- } , [ setRecordings , notify , t ] ) ;
274
+ } , [ rows , setRecordings ] ) ;
275
+
279
276
280
277
const handleNewRecording = useCallback ( async ( ) => {
281
278
const canCreateRecording = await canCreateBrowserInState ( "recording" ) ;
@@ -331,7 +328,7 @@ export const RecordingsTable = ({
331
328
332
329
if ( lastPair ?. what ) {
333
330
if ( Array . isArray ( lastPair . what ) ) {
334
- const gotoAction = lastPair . what . find ( action =>
331
+ const gotoAction = lastPair . what . find ( ( action : any ) =>
335
332
action && typeof action === 'object' && 'action' in action && action . action === "goto"
336
333
) as any ;
337
334
@@ -408,17 +405,12 @@ export const RecordingsTable = ({
408
405
window . sessionStorage . setItem ( 'initialUrl' , event . target . value ) ;
409
406
}
410
407
411
- useEffect ( ( ) => {
412
- fetchRecordings ( ) ;
413
- } , [ fetchRecordings ] ) ;
414
-
415
408
useEffect ( ( ) => {
416
409
if ( rerenderRobots ) {
417
- fetchRecordings ( ) . then ( ( ) => {
418
- setRerenderRobots ( false ) ;
419
- } ) ;
410
+ refetch ( ) ;
411
+ setRerenderRobots ( false ) ;
420
412
}
421
- } , [ rerenderRobots , fetchRecordings , setRerenderRobots ] ) ;
413
+ } , [ rerenderRobots , setRerenderRobots , refetch ] ) ;
422
414
423
415
function useDebounce < T > ( value : T , delay : number ) : T {
424
416
const [ debouncedValue , setDebouncedValue ] = React . useState < T > ( value ) ;
@@ -468,12 +460,11 @@ export const RecordingsTable = ({
468
460
469
461
const success = await deleteRecordingFromStorage ( id ) ;
470
462
if ( success ) {
471
- setRows ( [ ] ) ;
472
463
notify ( 'success' , t ( 'recordingtable.notifications.delete_success' ) ) ;
473
- fetchRecordings ( ) ;
464
+ refetch ( ) ;
474
465
}
475
466
}
476
- } ) , [ handleRunRecording , handleScheduleRecording , handleIntegrateRecording , handleSettingsRecording , handleEditRobot , handleDuplicateRobot , handleRetrainRobot , notify , t ] ) ;
467
+ } ) , [ handleRunRecording , handleScheduleRecording , handleIntegrateRecording , handleSettingsRecording , handleEditRobot , handleDuplicateRobot , handleRetrainRobot , notify , t , refetch ] ) ;
477
468
478
469
return (
479
470
< React . Fragment >
0 commit comments