source: phonelux-frontend/src/components/FiltersComponents/FilterSelectComponent.js@ d66b8eb

Last change on this file since d66b8eb was d66b8eb, checked in by Marko <Marko@…>, 22 months ago

Component for editing offers added

  • Property mode set to 100644
File size: 7.2 KB
Line 
1
2import * as React from 'react';
3import OutlinedInput from '@mui/material/OutlinedInput';
4import InputLabel from '@mui/material/InputLabel';
5import MenuItem from '@mui/material/MenuItem';
6import FormControl from '@mui/material/FormControl';
7import ListItemText from '@mui/material/ListItemText';
8import Select from '@mui/material/Select';
9import Checkbox from '@mui/material/Checkbox';
10import "./FilterSelectComponent.css"
11import axios from 'axios';
12
13export class FilterSelectComponent extends React.Component {
14
15 constructor(props) {
16 super(props)
17 const {type} = this.props
18 console.log(type)
19 this.state = {
20 pickedItems: localStorage.getItem(type) ? localStorage.getItem(type).split(',') : [],
21 items: [],
22 type: '',
23 ITEM_HEIGHT: 48,
24 ITEM_PADDING_TOP: 8,
25 MenuProps: {}
26 }
27
28 }
29
30 componentDidMount(){
31 this.state.MenuProps = {
32 PaperProps: {
33 style: {
34 maxHeight: this.state.ITEM_HEIGHT * 5.5 + this.state.ITEM_PADDING_TOP,
35 width: 250,
36 },
37 },
38 }
39
40 let endpoint
41 switch (this.props.type) {
42
43 case 'brands':
44 endpoint = '/brands'
45 this.setState({
46 type: 'Брендови'
47 })
48 break;
49 case 'shops':
50 endpoint = '/shops'
51 this.setState({
52 type: 'Продавници'
53 })
54 break;
55
56 case 'ram':
57 endpoint = '/specifications/ram'
58 this.setState({
59 type: 'РАМ меморија'
60 })
61 break;
62
63 case 'rom':
64 endpoint = '/specifications/rom'
65 this.setState({
66 type: 'РОМ меморија'
67 })
68 break;
69
70 case 'frontcamera':
71 endpoint = '/specifications/frontcamera'
72 this.setState({
73 type: 'Предна камера'
74 })
75 break;
76
77 case 'backcamera':
78 endpoint = '/specifications/backcamera'
79 this.setState({
80 type: 'Задна камера'
81 })
82 break;
83
84 case 'chipset':
85 endpoint = '/specifications/chipset'
86 this.setState({
87 type: 'Чипсет'
88 })
89 break;
90
91 case 'cpu':
92 endpoint = '/specifications/cpu'
93 this.setState({
94 type: 'Процесор'
95 })
96 break;
97
98
99 case 'operatingsystem':
100 endpoint = '/specifications/operatingsystem'
101 this.setState({
102 type: 'Оперативен систем'
103 })
104 break;
105
106
107 case 'color':
108 endpoint = '/specifications/color'
109 this.setState({
110 type: 'Боја'
111 })
112 break;
113
114 case 'battery':
115 endpoint = '/specifications/battery'
116 this.setState({
117 type: 'Батерија'
118 })
119 break;
120
121 default:
122 break;
123 }
124
125 axios.get(endpoint)
126 .then(response => this.setState({items: response.data}))
127 .catch(error => console.log(error))
128 }
129
130 handleChange = (event) => {
131 let value = event.target.value
132 this.setState({
133 pickedItems: typeof value === 'string' ? value.split(',') : value
134 }, ()=>{
135
136 switch (this.props.type) {
137 case 'brands':
138 this.props.changeHandler({brands: this.state.pickedItems.join(',')})
139 localStorage.setItem('brands', this.state.pickedItems.join(','))
140 break;
141
142 case 'shops':
143 this.props.changeHandler({shops: this.state.pickedItems.join(',')})
144 localStorage.setItem('shops', this.state.pickedItems.join(','))
145 break;
146
147 case 'ram':
148 this.props.changeHandler({ram: this.state.pickedItems.join(',')})
149 localStorage.setItem('ram', this.state.pickedItems.join(','))
150 break;
151 case 'rom':
152 this.props.changeHandler({rom: this.state.pickedItems.join(',')})
153 localStorage.setItem('rom', this.state.pickedItems.join(','))
154 break;
155 case 'frontcamera':
156 this.props.changeHandler({frontcamera: this.state.pickedItems.join(',')})
157 localStorage.setItem('frontcamera', this.state.pickedItems.join(','))
158 break;
159
160 case 'backcamera':
161 this.props.changeHandler({backcamera: this.state.pickedItems.join(',')})
162 localStorage.setItem('backcamera', this.state.pickedItems.join(','))
163 break;
164
165 case 'chipset':
166 this.props.changeHandler({chipset: this.state.pickedItems.join(',')})
167 localStorage.setItem('chipset', this.state.pickedItems.join(','))
168 break;
169
170 case 'cpu':
171 this.props.changeHandler({cpu: this.state.pickedItems.join(',')})
172 localStorage.setItem('cpu', this.state.pickedItems.join(','))
173 break;
174
175 case 'operatingsystem':
176 this.props.changeHandler({operatingsystem: this.state.pickedItems.join(',')})
177 localStorage.setItem('operatingsystem', this.state.pickedItems.join(','))
178 break;
179
180 case 'color':
181 this.props.changeHandler({color: this.state.pickedItems.join(',')})
182 localStorage.setItem('color', this.state.pickedItems.join(','))
183 break;
184
185 case 'battery':
186 this.props.changeHandler({battery: this.state.pickedItems.join(',')})
187 localStorage.setItem('battery', this.state.pickedItems.join(','))
188 break;
189
190 default:
191 break;
192 }
193 // if(this.props.type == 'brands')
194 // {
195 // this.props.changeHandler({brands: this.state.pickedItems.join(',')})
196 // }
197
198 // if(this.props.type == 'shops')
199 // {
200 // this.props.changeHandler({shops: this.state.pickedItems.join(',')})
201 // }
202
203 })
204
205
206 };
207 // sx={{ m: 1, width: 250 }} kaj formcontrol
208
209 render() {
210 return (
211 <div>
212 <FormControl className="form-select-component" sx={{ m: 1, width: this.props.width}}>
213 <InputLabel className="input-select-label">{this.state.type}</InputLabel>
214 <Select
215 size={"small"}
216 labelId="input-label-id"
217 className="input-select-option"
218 multiple
219 value={this.state.pickedItems}
220 onChange={this.handleChange}
221 input={<OutlinedInput className='inner-input-selectfilter' label={this.state.type} />}
222 renderValue={(selected) => selected.join(', ')}
223 MenuProps={this.state.MenuProps}
224 >
225 {this.state.items.map((item) => (
226 <MenuItem key={item} value={item} >
227 <Checkbox checked={this.state.pickedItems.indexOf(item) > -1} />
228 <ListItemText className='list-item-text-filters' primary={item} />
229 </MenuItem>
230 ))}
231 </Select>
232 </FormControl>
233 </div>
234 )
235 }
236}
237
238export default FilterSelectComponent
Note: See TracBrowser for help on using the repository browser.