[dbd4834] | 1 | import React, { Component } from 'react'
|
---|
[7e88e46] | 2 | import UserContext from '../context/UserContext'
|
---|
[dbd4834] | 3 | import GroupedFiltersComponent from './GroupedFiltersComponent/GroupedFiltersComponent'
|
---|
| 4 | import HeaderComponent from './HeaderComponent/HeaderComponent'
|
---|
| 5 | import PhoneCardGridComponent from './PhoneCardGridComponent/PhoneCardGridComponent'
|
---|
| 6 |
|
---|
[e5b84dc] | 7 |
|
---|
[dbd4834] | 8 | export class HomepageComponent extends Component {
|
---|
| 9 |
|
---|
| 10 | constructor(props) {
|
---|
| 11 | super(props)
|
---|
| 12 |
|
---|
| 13 | this.state = {
|
---|
[e5b84dc] | 14 | shops: '',
|
---|
| 15 | brands: '',
|
---|
| 16 | priceRange: '',
|
---|
| 17 | searchValue: '',
|
---|
[d66b8eb] | 18 | sortBy: 'mostPopular',
|
---|
| 19 | ram: '',
|
---|
| 20 | rom: '',
|
---|
| 21 | frontcamera: '',
|
---|
| 22 | backcamera: '',
|
---|
| 23 | chipset: '',
|
---|
| 24 | cpu: '',
|
---|
| 25 | operatingsystem: '',
|
---|
| 26 | color: '',
|
---|
| 27 | battery: ''
|
---|
[dbd4834] | 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 | })
|
---|
[e5b84dc] | 59 |
|
---|
[dbd4834] | 60 | }
|
---|
[7e88e46] | 61 |
|
---|
[dbd4834] | 62 | if(e.hasOwnProperty('sortBy'))
|
---|
| 63 | {
|
---|
| 64 | this.setState({
|
---|
| 65 | sortBy: e.sortBy
|
---|
| 66 | })
|
---|
| 67 | }
|
---|
[d66b8eb] | 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 | }
|
---|
[dbd4834] | 217 | }
|
---|
| 218 |
|
---|
[e5b84dc] | 219 |
|
---|
[dbd4834] | 220 | render() {
|
---|
[d66b8eb] | 221 | // console.log(this.context)
|
---|
[48f3030] | 222 | console.log(localStorage.getItem('token'))
|
---|
[436e0da] | 223 | // console.log(this.state)
|
---|
[dbd4834] | 224 | return (
|
---|
| 225 | <>
|
---|
| 226 | <HeaderComponent/>
|
---|
| 227 | <GroupedFiltersComponent passFilters={this.changeFilters}/>
|
---|
[e5b84dc] | 228 | <PhoneCardGridComponent {...this.state}/>
|
---|
[dbd4834] | 229 | </>
|
---|
| 230 | )
|
---|
| 231 | }
|
---|
| 232 | }
|
---|
| 233 |
|
---|
[7e88e46] | 234 | HomepageComponent.contextType = UserContext
|
---|
| 235 |
|
---|
| 236 |
|
---|
[dbd4834] | 237 | export default HomepageComponent
|
---|