Projekt

Obecné

Profil

« Předchozí | Další » 

Revize 96066e3b

Přidáno uživatelem Michal Schwob před téměř 2 roky(ů)

Revert "Merge branch 'searchpage' into 'main'"

This reverts merge request !5

Zobrazit rozdíly:

src/components/search/SearchForm.tsx
1
import {
2
    Box,
3
    Button,
4
    CloseIcon,
5
    ScrollView,
6
    VStack
7
} from "native-base"
1
import { Button, Center, CheckIcon, FormControl, KeyboardAvoidingView, ScrollView, Select, Text } from "native-base"
8 2
import { useDispatch, useSelector } from "react-redux"
9
import { useEffect, useState } from "react"
3
import React, { useEffect, useState } from "react"
10 4
import { AppDispatch, RootState } from "../../stores/store"
11 5
import { Inventory } from "../../types/searchFormTypes"
6
import {
7
    fetchArtists, fetchCities, fetchCountries, fetchInstitutions,
8
    fetchInventories,
9
    fetchNationalities,
10
    fetchPlans,
11
    fetchSubjects
12
} from "../../stores/actions/searchFormThunks"
13
import SearchFormControl from "./SearchFormControl"
14
import { Platform } from "react-native"
12 15
import { search } from "../../stores/actions/listViewThunks"
13
import MultiSelect from "./MultiSelect"
14
import SwitchWithLabel from "./SwitchWithLabel"
15
import { log } from "../../logging/logger"
16 16

  
17
interface SearchFormProps {
18
    isFilterOpen: boolean,
19
}
20 17

  
21

  
22
const SearchForm = (props: SearchFormProps) => {
18
const SearchForm = () => {
23 19
    const inventories: Inventory[] = useSelector((state: RootState) => state.searchForm.inventories)
24 20
    const nationalities = useSelector((state: RootState) => state.searchForm.nationalities)
25 21
    const artists = useSelector((state: RootState) => state.searchForm.artists)
26 22
    const subjects = useSelector((state: RootState) => state.searchForm.subjects)
27 23
    const rooms = useSelector((state: RootState) => state.searchForm.rooms)
28
    const techniques = useSelector((state: RootState) => state.searchForm.techniques)
29 24
    const countries = useSelector((state: RootState) => state.searchForm.countries)
30 25
    const cities = useSelector((state: RootState) => state.searchForm.cities)
31 26
    const institutions = useSelector((state: RootState) => state.searchForm.institutions)
32 27

  
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 28

  
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)
29
    const [selectedInventories, setSelectedInventories] = useState<string[]>([])
30
    const [selectedNationalities, setSelectedNationalities] = useState<string[]>([])
31
    const [selectedArtists, setSelectedArtists] = useState<string[]>([])
32
    const [selectedSubjects, setSelectedSubjects] = useState<string[]>([])
33
    const [selectedRooms, setSelectedRooms] = useState<string[]>([])
34
    const [selectedCountries, setSelectedCountries] = useState<string[]>([])
35
    const [selectedCities, setSelectedCities] = useState<string[]>([])
36
    const [selectedInstitutions, setSelectedInstitutions] = useState<string[]>([])
48 37

  
49 38
    const dispatch = useDispatch<AppDispatch>()
50 39

  
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
    }
40
    useEffect(() => {
41
        dispatch(fetchInventories())
42
        dispatch(fetchNationalities())
43
        dispatch(fetchArtists())
44
        dispatch(fetchSubjects())
45
        dispatch(fetchPlans())
46
        dispatch(fetchCountries())
47
        dispatch(fetchCities())
48
        dispatch(fetchInstitutions())
49
    }, [dispatch])
69 50

  
70
    const clearForm = () => {
71
        log.debug("SearchForm", "clearForm")
72 51

  
73
        setSelectedInventories([])
74
        setSelectedNationalities([])
75
        setSelectedArtists([])
76
        setSelectedSubjects([])
77
        setSelectedRooms([])
78
        setSelectedTechniques([])
79
        setSelectedCountries([])
80
        setSelectedCities([])
81
        setSelectedInstitutions([])
52
    const searchSubmit = () => {
53
        dispatch(search({inventory: selectedInventories ? selectedInventories[0] : undefined}))
82 54
    }
83 55

  
84 56
    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 }
57
        <Center>
58
            <ScrollView>
59
                <SearchFormControl
60
                    data={ inventories.map(inventory => {
61
                        return {label: inventory.label, value: inventory.name, key: inventory.name}
62
                    }) }
63
                    label="Inventory"
64
                    placeholder="Choose Inventory"
65
                    selectedItems={ selectedInventories }
66
                    onSelectedItemsChange={ setSelectedInventories }
67
                />
68
                <SearchFormControl
69
                    data={ rooms.map(room => {
70
                        return {label: room.label, value: room.id.toString(), key: room.id.toString()}
71
                    }) }
72
                    label="Rooms"
73
                    placeholder="Room..."
74
                    selectedItems={ selectedRooms }
75
                    onSelectedItemsChange={ setSelectedRooms }
76
                />
77
                <SearchFormControl
78
                    data={ artists.map(art => {
79
                        return {label: art.display_name, value: art.display_name, key: art.display_name}
80
                    }) }
81
                    label="Artists/Copyists"
82
                    placeholder="Artist/Copyist..."
83
                    selectedItems={ selectedArtists }
84
                    onSelectedItemsChange={ setSelectedArtists }
85
                />
86
                <SearchFormControl
87
                    data={ nationalities.map(nat => {
88
                        return {label: nat, value: nat, key: nat}
89
                    }) }
90
                    label="Artist`s Origin"
91
                    placeholder="Nationality..."
92
                    selectedItems={ selectedNationalities }
93
                    onSelectedItemsChange={ setSelectedNationalities }
94
                />
95
                <FormControl key={ "lab" }>
96
                    <FormControl.Label>label</FormControl.Label>
97
                    <Select
98
                        placeholder={ "Select" }
99
                        minWidth="100"
100
                        accessibilityLabel="Choose Service"
101
                        _selectedItem={ {
102
                            bg: "teal.600",
103
                            endIcon: <CheckIcon size={ 5 }/>
104
                        } }
105
                        mt="1"
106
                        key={ "props.label" }
107

  
175 108
                    >
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
        </>
109
                        { inventories.map((row) => (
110
                            <Select.Item label={ row.label } value={ row.name } key={ row.name }/>
111
                        )) }
112
                    </Select>
113
                </FormControl>
114
                <Button
115
                    onPress={ () => searchSubmit()}
116
                    colorScheme="primary.100"
117
                >
118
                    Submit
119
                </Button>
120
            </ScrollView>
121

  
122
        </Center>
204 123
    )
205 124
}
206 125

  

Také k dispozici: Unified diff