1
|
import {
|
2
|
Box,
|
3
|
Button,
|
4
|
CloseIcon,
|
5
|
ScrollView,
|
6
|
VStack
|
7
|
} from "native-base"
|
8
|
import { useDispatch, useSelector } from "react-redux"
|
9
|
import { useEffect, useState } from "react"
|
10
|
import { AppDispatch, RootState } from "../../stores/store"
|
11
|
import { Inventory } from "../../types/searchFormTypes"
|
12
|
import { search } from "../../stores/actions/listViewThunks"
|
13
|
import MultiSelect from "./MultiSelect"
|
14
|
import SwitchWithLabel from "./SwitchWithLabel"
|
15
|
import { log } from "../../logging/logger"
|
16
|
|
17
|
interface SearchFormProps {
|
18
|
isFilterOpen: boolean,
|
19
|
}
|
20
|
|
21
|
|
22
|
const SearchForm = (props: SearchFormProps) => {
|
23
|
const inventories: Inventory[] = useSelector((state: RootState) => state.searchForm.inventories)
|
24
|
const nationalities = useSelector((state: RootState) => state.searchForm.nationalities)
|
25
|
const artists = useSelector((state: RootState) => state.searchForm.artists)
|
26
|
const subjects = useSelector((state: RootState) => state.searchForm.subjects)
|
27
|
const rooms = useSelector((state: RootState) => state.searchForm.rooms)
|
28
|
const techniques = useSelector((state: RootState) => state.searchForm.techniques)
|
29
|
const countries = useSelector((state: RootState) => state.searchForm.countries)
|
30
|
const cities = useSelector((state: RootState) => state.searchForm.cities)
|
31
|
const institutions = useSelector((state: RootState) => state.searchForm.institutions)
|
32
|
|
33
|
const [selectedInventories, setSelectedInventories] = useState<{ label: string, value: string }[]>([])
|
34
|
const [selectedNationalities, setSelectedNationalities] = useState<{ label: string, value: string }[]>([])
|
35
|
const [selectedArtists, setSelectedArtists] = useState<{ label: string, value: string }[]>([])
|
36
|
const [selectedSubjects, setSelectedSubjects] = useState<{ label: string, value: string }[]>([])
|
37
|
const [selectedRooms, setSelectedRooms] = useState<{ label: string, value: string }[]>([])
|
38
|
const [selectedTechniques, setSelectedTechniques] = useState<{ label: string, value: string }[]>([])
|
39
|
const [selectedCountries, setSelectedCountries] = useState<{ label: string, value: string }[]>([])
|
40
|
const [selectedCities, setSelectedCities] = useState<{ label: string, value: string }[]>([])
|
41
|
const [selectedInstitutions, setSelectedInstitutions] = useState<{ label: string, value: string }[]>([])
|
42
|
|
43
|
const [isSchoolOfPrague, setIsSchoolOfPrague] = useState(false)
|
44
|
const [isOriginal, setIsOriginal] = useState(false)
|
45
|
const [isCopy, setIsCopy] = useState(false)
|
46
|
const [isHighQuality, setIsHighQuality] = useState(false)
|
47
|
const [isLowQuality, setIsLowQuality] = useState(false)
|
48
|
|
49
|
const dispatch = useDispatch<AppDispatch>()
|
50
|
|
51
|
const searchSubmit = () => {
|
52
|
dispatch(search({
|
53
|
inventories: selectedInventories.map(i => i.value),
|
54
|
nationalities: selectedNationalities.map(n => n.value),
|
55
|
artists: selectedArtists.map(a => a.value),
|
56
|
subjects: selectedSubjects.map(s => s.value),
|
57
|
rooms: selectedRooms.map(r => r.value),
|
58
|
techniques: selectedTechniques.map(t => t.value),
|
59
|
countries: selectedCountries.map(c => c.value),
|
60
|
cities: selectedCities.map(c => c.value),
|
61
|
institutions: selectedInstitutions.map(i => i.value),
|
62
|
isSchoolOfPrague,
|
63
|
isOriginal,
|
64
|
isCopy,
|
65
|
isHighQuality,
|
66
|
isLowQuality
|
67
|
}))
|
68
|
}
|
69
|
|
70
|
const clearForm = () => {
|
71
|
log.debug("SearchForm", "clearForm")
|
72
|
|
73
|
setSelectedInventories([])
|
74
|
setSelectedNationalities([])
|
75
|
setSelectedArtists([])
|
76
|
setSelectedSubjects([])
|
77
|
setSelectedRooms([])
|
78
|
setSelectedTechniques([])
|
79
|
setSelectedCountries([])
|
80
|
setSelectedCities([])
|
81
|
setSelectedInstitutions([])
|
82
|
}
|
83
|
|
84
|
return (
|
85
|
<>
|
86
|
{ props.isFilterOpen && (
|
87
|
<>
|
88
|
<MultiSelect
|
89
|
data={ inventories.map((inventory, index) => {
|
90
|
return {label: inventory.label, value: inventory.name, index}
|
91
|
}) }
|
92
|
label="Inventory (OR)"
|
93
|
selectedItems={ selectedInventories }
|
94
|
onSelectedItemsChange={ setSelectedInventories }
|
95
|
/>
|
96
|
<MultiSelect
|
97
|
data={ rooms.map((room, index) => {
|
98
|
return {label: `${ room.id } - ${ room.label }`, value: room.id.toString(), index}
|
99
|
}) }
|
100
|
label="Rooms (OR)"
|
101
|
selectedItems={ selectedRooms }
|
102
|
onSelectedItemsChange={ setSelectedRooms }
|
103
|
/>
|
104
|
<MultiSelect
|
105
|
data={ artists.map((art, index) => {
|
106
|
return {label: art.display_name, value: art.getty_id, index}
|
107
|
}) }
|
108
|
label="Artists/Copyists (OR)"
|
109
|
selectedItems={ selectedArtists }
|
110
|
onSelectedItemsChange={ setSelectedArtists }
|
111
|
/>
|
112
|
<MultiSelect
|
113
|
data={ nationalities.map((nat, index) => {
|
114
|
return {label: nat, value: nat, index}
|
115
|
}) }
|
116
|
label="Artist`s Origin (OR)"
|
117
|
selectedItems={ selectedNationalities }
|
118
|
onSelectedItemsChange={ setSelectedNationalities }
|
119
|
/>
|
120
|
<MultiSelect
|
121
|
data={ subjects.map((subj, index) => {
|
122
|
return {label: subj, value: subj, index}
|
123
|
}) }
|
124
|
label="Subject (AND)"
|
125
|
selectedItems={ selectedSubjects }
|
126
|
onSelectedItemsChange={ setSelectedSubjects }
|
127
|
/>
|
128
|
<MultiSelect
|
129
|
data={ techniques.map((tech, index) => {
|
130
|
return {label: tech, value: tech, index}
|
131
|
}) }
|
132
|
label="Technique (OR)"
|
133
|
selectedItems={ selectedTechniques }
|
134
|
onSelectedItemsChange={ setSelectedTechniques }
|
135
|
/>
|
136
|
<MultiSelect
|
137
|
data={ institutions.map((institution, index) => {
|
138
|
return {label: institution, value: institution, index}
|
139
|
}) }
|
140
|
label="Institution (OR)"
|
141
|
selectedItems={ selectedInstitutions }
|
142
|
onSelectedItemsChange={ setSelectedInstitutions }
|
143
|
/>
|
144
|
<MultiSelect
|
145
|
data={ cities.map((city, index) => {
|
146
|
return {label: city, value: city, index}
|
147
|
}) }
|
148
|
label="City (OR)"
|
149
|
selectedItems={ selectedCities }
|
150
|
onSelectedItemsChange={ setSelectedCities }
|
151
|
/>
|
152
|
<MultiSelect
|
153
|
data={ countries.map((country, index) => {
|
154
|
return {label: country, value: country, index}
|
155
|
}) }
|
156
|
label="Country (OR)"
|
157
|
selectedItems={ selectedCountries }
|
158
|
onSelectedItemsChange={ setSelectedCountries }
|
159
|
/>
|
160
|
<VStack space={ 2 } mt={ 1 }>
|
161
|
<SwitchWithLabel label={ "School of Prague" } value={ isSchoolOfPrague }
|
162
|
onValueChange={ setIsSchoolOfPrague }/>
|
163
|
<SwitchWithLabel label={ "Original" } value={ isOriginal } onValueChange={ setIsOriginal }/>
|
164
|
<SwitchWithLabel label={ "Copy" } value={ isCopy } onValueChange={ setIsCopy }/>
|
165
|
<SwitchWithLabel label={ "High Quality" } value={ isHighQuality }
|
166
|
onValueChange={ setIsHighQuality }/>
|
167
|
<SwitchWithLabel label={ "Low Quality" } value={ isLowQuality }
|
168
|
onValueChange={ setIsLowQuality }/>
|
169
|
</VStack>
|
170
|
<Box
|
171
|
flex={ 1 }
|
172
|
flexDirection="row"
|
173
|
justifyContent={ "flex-end" }
|
174
|
pt={ 2 }
|
175
|
>
|
176
|
<Button
|
177
|
borderRadius={ 10 }
|
178
|
startIcon={
|
179
|
<CloseIcon size="xs"/>
|
180
|
}
|
181
|
onPress={ clearForm }
|
182
|
variant="outline"
|
183
|
color="primary.500"
|
184
|
borderColor="primary.500"
|
185
|
mr={ 2 }
|
186
|
size={ "sm" }
|
187
|
>
|
188
|
Reset
|
189
|
</Button>
|
190
|
<Button
|
191
|
borderRadius={ 10 }
|
192
|
onPress={ () => searchSubmit() }
|
193
|
colorScheme="primary"
|
194
|
background={ "primary.500" }
|
195
|
variant="solid"
|
196
|
size={ "sm" }
|
197
|
>
|
198
|
Search
|
199
|
</Button>
|
200
|
</Box>
|
201
|
</>
|
202
|
) }
|
203
|
</>
|
204
|
)
|
205
|
}
|
206
|
|
207
|
export default SearchForm
|