- Timestamp:
- 09/11/22 18:03:58 (2 years ago)
- Branches:
- master
- Children:
- 775e15e
- Parents:
- 527b93f
- Location:
- phonelux-frontend/src/components/PhoneCardGridComponent
- Files:
-
- 2 edited
Legend:
- Unmodified
- Added
- Removed
-
phonelux-frontend/src/components/PhoneCardGridComponent/PhoneCardGridComponent.css
r527b93f re5b84dc 15 15 } 16 16 17 .pagination-wrapper{ 18 margin-top: 40px; 19 padding-bottom: 40px; 20 display: flex; 21 justify-content: center; 22 } 17 23 24 25 -
phonelux-frontend/src/components/PhoneCardGridComponent/PhoneCardGridComponent.js
r527b93f re5b84dc 1 import { Grid } from '@mui/material'1 import { Grid, Pagination } from '@mui/material' 2 2 import axios from 'axios' 3 3 import React, { Component } from 'react' 4 import PaginationComponent from '../PaginationComponent/PaginationComponent'5 4 import '../PhoneCardComponent/PhoneCardComponent' 6 5 import PhoneCardComponent from '../PhoneCardComponent/PhoneCardComponent' … … 15 14 this.state = { 16 15 phones: [], 17 loading: true,18 16 currentPage: 1, 19 17 phonesPerPage: 12, … … 24 22 } 25 23 24 componentDidUpdate(prevProps) { 25 if(JSON.stringify(prevProps) != JSON.stringify(this.props)){ 26 let filters = '?' 27 28 if(this.props.shops) 29 { 30 filters += 'shops='+this.props.shops+'&' 31 } 32 if(this.props.brands) 33 { 34 filters += 'brands='+this.props.brands+'&' 35 } 36 if(this.props.priceRange) 37 { 38 filters += 'priceRange='+this.props.priceRange+'&' 39 } 40 if(this.props.searchValue) 41 { 42 filters += 'searchValue='+this.props.searchValue+'&' 43 } 44 45 if(this.props.sortBy) 46 { 47 filters += 'sortBy='+this.props.sortBy+'&' 48 } 49 50 axios.get('/phones'+filters) 51 .then(response => { 52 this.setState({ 53 phones: response.data, 54 numberOfPages: Math.ceil(response.data.length / this.state.phonesPerPage) 55 },(e) => this.setNewPage(e,this.state.currentPage)) 56 } 57 ) 58 .catch(error => console.log(error)) 59 console.log(filters) 60 } 61 } 62 26 63 componentDidMount() { 27 28 64 axios.get('/phones') 29 65 .then(response => { 30 66 this.setState({ 31 67 phones: response.data, 32 loading: false,33 68 numberOfPages: Math.ceil(response.data.length / this.state.phonesPerPage) 34 },( ) => this.setNewPage(this.state.currentPage))69 },(e) => this.setNewPage(e,this.state.currentPage)) 35 70 } 36 71 ) … … 38 73 } 39 74 40 setNewPage = (newPage) => {41 if(newPage == '')42 {43 newPage = this.state.currentPage-144 }45 75 46 if(newPage == '') 47 { 48 newPage = this.state.currentPage+1 49 } 76 setNewPage = (event,page) => { 50 77 51 52 const indexOfLastPhone = parseInt(newPage) * this.state.phonesPerPage; 78 const indexOfLastPhone = parseInt(page) * this.state.phonesPerPage; 53 79 const indexOfFirstPhone = indexOfLastPhone - this.state.phonesPerPage; 54 80 … … 56 82 57 83 this.setState({ 58 currentPage: parseInt( newPage),84 currentPage: parseInt(page), 59 85 currentPhones: currPhones 60 86 }) … … 63 89 64 90 render() { 91 65 92 return ( 66 93 <div className='phonecardgrid-wrapper'> … … 71 98 spacing={2}> 72 99 73 {this.state.currentPhones.map((phone ) => <GridclassName='phonecardgrid-item' item md={3}>74 <PhoneCardComponent key={phone.id}id={phone.id} brand={phone.brand}100 {this.state.currentPhones.map((phone,idx) => <Grid key={idx} className='phonecardgrid-item' item md={3}> 101 <PhoneCardComponent id={phone.id} brand={phone.brand} 75 102 model={phone.model} image_url={phone.image_url == null ? phoneImage : phone.image_url} total_offers={phone.total_offers} lowestPrice={phone.lowestPrice}/></Grid>)} 76 103 77 {/* <Grid item xs={12} md={12}>78 <PaginationComponent79 currentPage={this.state.currentPage}80 changePageHandler={this.setNewPage}81 numberOfPages={this.state.numberOfPages} />82 </Grid> */}83 104 </Grid> 84 <PaginationComponent 85 currentPage={this.state.currentPage} 86 changePageHandler={this.setNewPage} 87 numberOfPages={this.state.numberOfPages} /> 105 106 <div className='pagination-wrapper'> 107 <Pagination className='paginationcomponent-pagination' onChange={this.setNewPage} page={this.state.currentPage} 108 count={this.state.numberOfPages} color="primary" /> 109 </div> 110 88 111 </div> 89 112 )
Note:
See TracChangeset
for help on using the changeset viewer.