1 | import React, { Component } from 'react'
|
---|
2 | import UserContext from '../context/UserContext'
|
---|
3 | import GroupedFiltersComponent from './GroupedFiltersComponent/GroupedFiltersComponent'
|
---|
4 | import HeaderComponent from './HeaderComponent/HeaderComponent'
|
---|
5 | import PhoneCardGridComponent from './PhoneCardGridComponent/PhoneCardGridComponent'
|
---|
6 |
|
---|
7 |
|
---|
8 | export class HomepageComponent extends Component {
|
---|
9 |
|
---|
10 | constructor(props) {
|
---|
11 | super(props)
|
---|
12 |
|
---|
13 | this.state = {
|
---|
14 | shops: '',
|
---|
15 | brands: '',
|
---|
16 | priceRange: '',
|
---|
17 | searchValue: '',
|
---|
18 | sortBy: 'mostPopular',
|
---|
19 | ram: '',
|
---|
20 | rom: '',
|
---|
21 | frontcamera: '',
|
---|
22 | backcamera: '',
|
---|
23 | chipset: '',
|
---|
24 | cpu: '',
|
---|
25 | operatingsystem: '',
|
---|
26 | color: '',
|
---|
27 | battery: ''
|
---|
28 | }
|
---|
29 | }
|
---|
30 |
|
---|
31 | changeFilters = (e) => {
|
---|
32 |
|
---|
33 | if(e.hasOwnProperty('priceRange'))
|
---|
34 | {
|
---|
35 | this.setState({
|
---|
36 | priceRange: e.priceRange
|
---|
37 | })
|
---|
38 | }
|
---|
39 |
|
---|
40 | if(e.hasOwnProperty('shops'))
|
---|
41 | {
|
---|
42 | this.setState({
|
---|
43 | shops: e.shops
|
---|
44 | })
|
---|
45 | }
|
---|
46 |
|
---|
47 | if(e.hasOwnProperty('brands'))
|
---|
48 | {
|
---|
49 | this.setState({
|
---|
50 | brands: e.brands
|
---|
51 | })
|
---|
52 | }
|
---|
53 |
|
---|
54 | if(e.hasOwnProperty('searchValue'))
|
---|
55 | {
|
---|
56 | this.setState({
|
---|
57 | searchValue: e.searchValue
|
---|
58 | })
|
---|
59 |
|
---|
60 | }
|
---|
61 |
|
---|
62 | if(e.hasOwnProperty('sortBy'))
|
---|
63 | {
|
---|
64 | this.setState({
|
---|
65 | sortBy: e.sortBy
|
---|
66 | })
|
---|
67 | }
|
---|
68 |
|
---|
69 | if(e.hasOwnProperty('ram'))
|
---|
70 | {
|
---|
71 | this.setState({
|
---|
72 | ram: e.ram
|
---|
73 | })
|
---|
74 |
|
---|
75 | }
|
---|
76 |
|
---|
77 | if(e.hasOwnProperty('rom'))
|
---|
78 | {
|
---|
79 | this.setState({
|
---|
80 | rom: e.rom
|
---|
81 | })
|
---|
82 | }
|
---|
83 |
|
---|
84 | if(e.hasOwnProperty('frontcamera'))
|
---|
85 | {
|
---|
86 | this.setState({
|
---|
87 | frontcamera: e.frontcamera
|
---|
88 | })
|
---|
89 | }
|
---|
90 |
|
---|
91 | if(e.hasOwnProperty('backcamera'))
|
---|
92 | {
|
---|
93 | this.setState({
|
---|
94 | backcamera: e.backcamera
|
---|
95 | })
|
---|
96 |
|
---|
97 | }
|
---|
98 |
|
---|
99 | if(e.hasOwnProperty('chipset'))
|
---|
100 | {
|
---|
101 | this.setState({
|
---|
102 | chipset: e.chipset
|
---|
103 | })
|
---|
104 | }
|
---|
105 |
|
---|
106 | if(e.hasOwnProperty('cpu'))
|
---|
107 | {
|
---|
108 | this.setState({
|
---|
109 | cpu: e.cpu
|
---|
110 | })
|
---|
111 |
|
---|
112 | }
|
---|
113 |
|
---|
114 | if(e.hasOwnProperty('operatingsystem'))
|
---|
115 | {
|
---|
116 | this.setState({
|
---|
117 | operatingsystem: e.operatingsystem
|
---|
118 | })
|
---|
119 | }
|
---|
120 |
|
---|
121 | if(e.hasOwnProperty('color'))
|
---|
122 | {
|
---|
123 | this.setState({
|
---|
124 | color: e.color
|
---|
125 | })
|
---|
126 |
|
---|
127 | }
|
---|
128 |
|
---|
129 | if(e.hasOwnProperty('battery'))
|
---|
130 | {
|
---|
131 | this.setState({
|
---|
132 | battery: e.battery
|
---|
133 | })
|
---|
134 | }
|
---|
135 | }
|
---|
136 |
|
---|
137 | componentDidMount(){
|
---|
138 | if(localStorage.getItem('brands'))
|
---|
139 | {
|
---|
140 | this.setState({
|
---|
141 | brands: localStorage.getItem('brands')
|
---|
142 | })
|
---|
143 | }
|
---|
144 | if(localStorage.getItem('shops'))
|
---|
145 | {
|
---|
146 | this.setState({
|
---|
147 | shops: localStorage.getItem('shops')
|
---|
148 | })
|
---|
149 | }
|
---|
150 | if(localStorage.getItem('priceRange'))
|
---|
151 | {
|
---|
152 | this.setState({
|
---|
153 | priceRange: localStorage.getItem('priceRange')
|
---|
154 | })
|
---|
155 | }
|
---|
156 |
|
---|
157 | if(localStorage.getItem('sortBy'))
|
---|
158 | {
|
---|
159 | this.setState({
|
---|
160 | sortBy: localStorage.getItem('sortBy')
|
---|
161 | })
|
---|
162 | }
|
---|
163 | if(localStorage.getItem('ram'))
|
---|
164 | {
|
---|
165 | this.setState({
|
---|
166 | ram: localStorage.getItem('ram')
|
---|
167 | })
|
---|
168 | }
|
---|
169 | if(localStorage.getItem('rom'))
|
---|
170 | {
|
---|
171 | this.setState({
|
---|
172 | rom: localStorage.getItem('rom')
|
---|
173 | })
|
---|
174 | }
|
---|
175 | if(localStorage.getItem('frontcamera'))
|
---|
176 | {
|
---|
177 | this.setState({
|
---|
178 | frontcamera: localStorage.getItem('frontcamera')
|
---|
179 | })
|
---|
180 | }
|
---|
181 | if(localStorage.getItem('backcamera'))
|
---|
182 | {
|
---|
183 | this.setState({
|
---|
184 | backcamera: localStorage.getItem('backcamera')
|
---|
185 | })
|
---|
186 | }
|
---|
187 | if(localStorage.getItem('chipset'))
|
---|
188 | {
|
---|
189 | this.setState({
|
---|
190 | chipset: localStorage.getItem('chipset')
|
---|
191 | })
|
---|
192 | }
|
---|
193 | if(localStorage.getItem('cpu'))
|
---|
194 | {
|
---|
195 | this.setState({
|
---|
196 | cpu: localStorage.getItem('cpu')
|
---|
197 | })
|
---|
198 | }
|
---|
199 | if(localStorage.getItem('operatingsystem'))
|
---|
200 | {
|
---|
201 | this.setState({
|
---|
202 | operatingsystem: localStorage.getItem('operatingsystem')
|
---|
203 | })
|
---|
204 | }
|
---|
205 | if(localStorage.getItem('color'))
|
---|
206 | {
|
---|
207 | this.setState({
|
---|
208 | color: localStorage.getItem('color')
|
---|
209 | })
|
---|
210 | }
|
---|
211 | if(localStorage.getItem('battery'))
|
---|
212 | {
|
---|
213 | this.setState({
|
---|
214 | battery: localStorage.getItem('battery')
|
---|
215 | })
|
---|
216 | }
|
---|
217 | console.log(this.state)
|
---|
218 | }
|
---|
219 |
|
---|
220 |
|
---|
221 | render() {
|
---|
222 | // console.log(this.context)
|
---|
223 | // console.log(localStorage.getItem('token'))
|
---|
224 | console.log(this.state)
|
---|
225 | return (
|
---|
226 | <>
|
---|
227 | <HeaderComponent/>
|
---|
228 | <GroupedFiltersComponent passFilters={this.changeFilters}/>
|
---|
229 | <PhoneCardGridComponent {...this.state}/>
|
---|
230 | </>
|
---|
231 | )
|
---|
232 | }
|
---|
233 | }
|
---|
234 |
|
---|
235 | HomepageComponent.contextType = UserContext
|
---|
236 |
|
---|
237 |
|
---|
238 | export default HomepageComponent
|
---|