1
|
import {
|
2
|
Center,
|
3
|
ScrollView,
|
4
|
VStack
|
5
|
} from "native-base"
|
6
|
import ListView from "../components/listView/ListView"
|
7
|
import SearchForm from "../components/search/SearchForm"
|
8
|
import { useEffect } from "react"
|
9
|
import {
|
10
|
fetchArtists,
|
11
|
fetchCities,
|
12
|
fetchCountries,
|
13
|
fetchInstitutions,
|
14
|
fetchInventories,
|
15
|
fetchNationalities,
|
16
|
fetchPlans,
|
17
|
fetchSubjects,
|
18
|
fetchTechniques
|
19
|
} from "../stores/actions/searchFormThunks"
|
20
|
import { useDispatch, useSelector } from "react-redux"
|
21
|
import { AppDispatch, RootState } from "../stores/store"
|
22
|
import { log } from "../logging/logger"
|
23
|
import { DrawerScreenProps } from "@react-navigation/drawer"
|
24
|
import { RootDrawerParamList } from "./Navigation"
|
25
|
import { loadItemsByInventory } from "../stores/actions/listViewThunks"
|
26
|
|
27
|
|
28
|
const SearchPage = ({route, navigation}: DrawerScreenProps<RootDrawerParamList, 'Search'>) => {
|
29
|
const dispatch = useDispatch<AppDispatch>()
|
30
|
|
31
|
const inventories = useSelector((state: RootState) => state.listView.inventories)
|
32
|
const numberOfResults = useSelector((state: RootState) => state.listView.numOfResults)
|
33
|
|
34
|
const data = useSelector((state: RootState) => state.listView.data)
|
35
|
const dataLoading = useSelector((state: RootState) => state.listView.inventoriesDataLoading)
|
36
|
const pagination = useSelector((state: RootState) => state.listView.loadedPages)
|
37
|
|
38
|
|
39
|
useEffect(() => {
|
40
|
log.debug("SearchPage", "useEffect", "fetchEverything")
|
41
|
|
42
|
dispatch(fetchInventories())
|
43
|
dispatch(fetchNationalities())
|
44
|
dispatch(fetchArtists())
|
45
|
dispatch(fetchSubjects())
|
46
|
dispatch(fetchPlans())
|
47
|
dispatch(fetchTechniques())
|
48
|
dispatch(fetchCountries())
|
49
|
dispatch(fetchCities())
|
50
|
dispatch(fetchInstitutions())
|
51
|
|
52
|
log.debug("SearchPage", "useEffect", "fetchEverything", "done")
|
53
|
}, [dispatch])
|
54
|
|
55
|
|
56
|
useEffect(() => {
|
57
|
log.debug("SearchPage", "props", route.params.inventoryId)
|
58
|
}, [])
|
59
|
|
60
|
console.log(data)
|
61
|
|
62
|
return (
|
63
|
<Center m={ 2 } mr={0} mb={6} flex={1}>
|
64
|
|
65
|
<ScrollView flex={1} w={"100%"} >
|
66
|
<VStack space={ 1 } mr={ 4 }>
|
67
|
<SearchForm inventoryId={route.params.inventoryId}/>
|
68
|
<ListView navigation={navigation}
|
69
|
|
70
|
inventories={inventories}
|
71
|
numOfResults={numberOfResults}
|
72
|
|
73
|
data={data}
|
74
|
loadedPages={pagination}
|
75
|
inventoriesDataLoading={dataLoading}
|
76
|
handleLoadMoreItems={(inventoryName: string, cursor: number) => {
|
77
|
dispatch(loadItemsByInventory(inventoryName))
|
78
|
} }/>
|
79
|
</VStack>
|
80
|
</ScrollView>
|
81
|
</Center>
|
82
|
)
|
83
|
}
|
84
|
|
85
|
export default SearchPage
|