-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathApp.tsx
55 lines (47 loc) · 1.67 KB
/
App.tsx
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
import { useEffect, useState } from 'react'
import { Box, Typography } from '@mui/material'
import { QueryClientProvider } from 'react-query'
import { EinsatzTable, FilterSelections } from './components'
import { CURRENT_YEAR, queryClient } from './config'
import { useGetEinsaetze } from './hooks'
import { ApiEinsatzResponse } from './@types'
import TableSkeleton from './components/TableSkeleton'
const AppRoot = () => {
const [keyword, selectedKeyword] = useState('alle')
const [year, selectYear] = useState(CURRENT_YEAR)
const [einsaetze, setEinsaetze] = useState<Array<ApiEinsatzResponse> | undefined>(undefined)
const { data, isLoading } = useGetEinsaetze({
params: { year },
options: {
onSuccess: data => {
// const fakedData = [...data, data[0].FZG = '10/1, 12/1, 40/1, 40/2']
// console.log(fakedData)
// @ts-ignore
keyword === 'alle' ? setEinsaetze(data) : setEinsaetze(data.filter(e => e.KAT === keyword))
},
},
})
useEffect(() => {
if (!isLoading && data) {
keyword === 'alle' ? setEinsaetze(data) : setEinsaetze(data.filter(e => e.KAT === keyword))
}
}, [keyword])
return (
<Box>
<Typography variant="h4" component="div" sx={{ my: 2, mx: 2, color: '#D0121A', fontWeight: 'bold' }}>
Übersicht Einsätze
</Typography>
<FilterSelections keyword={keyword} year={year} onChangeKeyboard={selectedKeyword} onChangeYear={selectYear} />
{isLoading ? <TableSkeleton /> : <EinsatzTable einsaetze={einsaetze} />
}
</Box>
)
}
function App() {
return (
<QueryClientProvider client={queryClient}>
<AppRoot />
</QueryClientProvider>
)
}
export default App