1 |
af8eb9a6
|
Schwobik
|
import {
|
2 |
|
|
Box,
|
3 |
|
|
Button,
|
4 |
|
|
CloseIcon,
|
5 |
|
|
ScrollView,
|
6 |
|
|
VStack
|
7 |
|
|
} from "native-base"
|
8 |
9c55d3bb
|
Schwobik
|
import { useDispatch, useSelector } from "react-redux"
|
9 |
af8eb9a6
|
Schwobik
|
import { useEffect, useState } from "react"
|
10 |
9c55d3bb
|
Schwobik
|
import { AppDispatch, RootState } from "../../stores/store"
|
11 |
|
|
import { Inventory } from "../../types/searchFormTypes"
|
12 |
|
|
import { search } from "../../stores/actions/listViewThunks"
|
13 |
af8eb9a6
|
Schwobik
|
import MultiSelect from "./MultiSelect"
|
14 |
|
|
import SwitchWithLabel from "./SwitchWithLabel"
|
15 |
|
|
import { log } from "../../logging/logger"
|
16 |
9c55d3bb
|
Schwobik
|
|
17 |
af8eb9a6
|
Schwobik
|
interface SearchFormProps {
|
18 |
|
|
isFilterOpen: boolean,
|
19 |
|
|
}
|
20 |
9c55d3bb
|
Schwobik
|
|
21 |
af8eb9a6
|
Schwobik
|
|
22 |
|
|
const SearchForm = (props: SearchFormProps) => {
|
23 |
9c55d3bb
|
Schwobik
|
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 |
af8eb9a6
|
Schwobik
|
const techniques = useSelector((state: RootState) => state.searchForm.techniques)
|
29 |
9c55d3bb
|
Schwobik
|
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 |
af8eb9a6
|
Schwobik
|
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 |
9c55d3bb
|
Schwobik
|
|
43 |
af8eb9a6
|
Schwobik
|
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 |
9c55d3bb
|
Schwobik
|
|
49 |
|
|
const dispatch = useDispatch<AppDispatch>()
|
50 |
|
|
|
51 |
af8eb9a6
|
Schwobik
|
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 |
9c55d3bb
|
Schwobik
|
|
70 |
af8eb9a6
|
Schwobik
|
const clearForm = () => {
|
71 |
|
|
log.debug("SearchForm", "clearForm")
|
72 |
9c55d3bb
|
Schwobik
|
|
73 |
af8eb9a6
|
Schwobik
|
setSelectedInventories([])
|
74 |
|
|
setSelectedNationalities([])
|
75 |
|
|
setSelectedArtists([])
|
76 |
|
|
setSelectedSubjects([])
|
77 |
|
|
setSelectedRooms([])
|
78 |
|
|
setSelectedTechniques([])
|
79 |
|
|
setSelectedCountries([])
|
80 |
|
|
setSelectedCities([])
|
81 |
|
|
setSelectedInstitutions([])
|
82 |
9c55d3bb
|
Schwobik
|
}
|
83 |
|
|
|
84 |
|
|
return (
|
85 |
af8eb9a6
|
Schwobik
|
<>
|
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 |
9c55d3bb
|
Schwobik
|
>
|
176 |
af8eb9a6
|
Schwobik
|
<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 |
9c55d3bb
|
Schwobik
|
)
|
205 |
|
|
}
|
206 |
|
|
|
207 |
|
|
export default SearchForm
|