1- import { ReactNode , useEffect } from "react" ;
1+ import { ReactNode } from "react" ;
22import { useTranslation } from "react-i18next" ;
33import TableFilters from "../shared/TableFilters" ;
44import Table , { TemplateMap } from "../shared/Table" ;
55import Notifications from "../shared/Notifications" ;
6- import { fetchFilters } from "../../slices/tableFilterSlice" ;
76import { CreateType , NavBarLink } from "../NavBar" ;
8- import { AppThunk , RootState , useAppDispatch , useAppSelector } from "../../store" ;
9- import { resetTableProperties , Resource } from "../../slices/tableSlice" ;
7+ import { AppThunk , RootState , useAppSelector } from "../../store" ;
8+ import { Resource } from "../../slices/tableSlice" ;
109import { AsyncThunk } from "@reduxjs/toolkit" ;
1110import { ParseKeys } from "i18next" ;
12- import { useLocation } from "react-router" ;
1311import MainPage from "./MainPage" ;
1412
1513/**
@@ -39,43 +37,9 @@ const TablePage = ({
3937 children ?: ReactNode
4038} ) => {
4139 const { t } = useTranslation ( ) ;
42- const dispatch = useAppDispatch ( ) ;
43-
44- const location = useLocation ( ) ;
4540
4641 const numberOfRows = useAppSelector ( state => getTotalResources ( state ) ) ;
4742
48- useEffect ( ( ) => {
49- // State variable for interrupting the load function
50- let allowLoadIntoTable = true ;
51-
52- // Clear table of previous data
53- dispatch ( resetTableProperties ( ) ) ;
54-
55- dispatch ( fetchFilters ( resource ) ) ;
56-
57- // Load resource on mount
58- const loadResource = async ( ) => {
59- // Fetching resources from server
60- await dispatch ( fetchResource ( ) ) ;
61-
62- // Load resources into table
63- if ( allowLoadIntoTable ) {
64- dispatch ( loadResourceIntoTable ( ) ) ;
65- }
66- } ;
67- loadResource ( ) ;
68-
69- // Fetch resources every minute
70- const fetchResourceInterval = setInterval ( loadResource , 5000 ) ;
71-
72- return ( ) => {
73- allowLoadIntoTable = false ;
74- clearInterval ( fetchResourceInterval ) ;
75- } ;
76- // eslint-disable-next-line react-hooks/exhaustive-deps
77- } , [ location . hash ] ) ;
78-
7943 return (
8044 < MainPage
8145 navBarLinks = { navBarLinks }
@@ -100,7 +64,11 @@ const TablePage = ({
10064 < h4 > { t ( "TABLE_SUMMARY" , { numberOfRows } ) } </ h4 >
10165 </ div >
10266 { /* Include table component */ }
103- < Table templateMap = { templateMap } />
67+ < Table
68+ templateMap = { templateMap }
69+ fetchResource = { fetchResource }
70+ loadResourceIntoTable = { loadResourceIntoTable }
71+ />
10472 </ MainPage >
10573 ) ;
10674} ;
0 commit comments