Changeset 07f4e8b for frontend/src/Pages/SearchPage.js
- Timestamp:
- 01/24/24 17:42:28 (5 months ago)
- Branches:
- master
- Children:
- 0f5aa27
- Parents:
- 5528b99
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
frontend/src/Pages/SearchPage.js
r5528b99 r07f4e8b 1 import React from "react";1 import React, {useState} from "react"; 2 2 import Navigation from '../Components/Layout/Navbar/Navigation'; 3 3 import 'bootstrap/dist/css/bootstrap.css'; 4 4 import 'bootstrap/dist/js/bootstrap.js'; 5 5 import HomeCarousel from '../Components/Layout/CarouselHome/Carousel'; 6 import { Card, Container, Nav, Row, Col} from 'react-bootstrap';6 import {Card, Container, Nav, Row, Col} from 'react-bootstrap'; 7 7 import TabComponent from '../Components/Tab/Tab'; 8 8 import Offers from '../Components/Layout/Offers/Offers'; … … 11 11 import BecomeAHost from "../Components/BecomeAHost/BecomeAHost" 12 12 import HotelLisitng from "../Components/Listings/HotelListing" 13 import SearchCriterias from "../Components/SearchCriterias/SearchCriteriasBar";13 import SearchCriteriasHotel from "../Components/SearchCriterias/SearchCriteriasHotel"; 14 14 import SortButton from "../Components/Listings/SortButton"; 15 15 import FilterButton from "../Components/Listings/FilterButton"; 16 16 import TransportListing from "../Components/Listings/TransportListing"; 17 17 import useGet from "../Components/Hooks/useGet"; 18 import { useParams } from "react-router-dom"; 19 <<<<<<< HEAD 18 import {useParams} from "react-router-dom"; 20 19 import SearchCriteriasBar from "../Components/SearchCriterias/SearchCriteriasBar"; 21 20 import RestaurantDetailsPage from "./RestaurantDetailsPage"; 22 21 import RestaurantListing from "../Components/Listings/RestaurantListing"; 23 =======24 >>>>>>> parent of ac19a0c (authContext impl, admin panel impl, search bar fixes, reservations listings impl)25 22 26 23 … … 29 26 const params = useParams(); 30 27 console.log(params) 31 28 const [sortingArg, setSortingArg] = useState("") 32 29 33 30 document.body.style.backgroundColor = "white" … … 41 38 42 39 } 43 44 <<<<<<< HEAD 45 let link = props.type === "transport" ? `/transport/search?from=${params.from}&to=${params.to}&date=${params.date}&numPassengers=${params.numPassengers}` : props.type === "hotel" ? `/hotel/search?hotelLocation=${params.hotelLocation}&dateFrom=${params.dateFrom}&dateTo=${params.dateTo}&numBeds=${params.numBeds}` : `/restaurant/search?restaurantLocation=${params.restaurantLocation}&date=${params.date}&hourFrom=${params.hourFrom}&hourTo=${params.hourTo}&numPeople=${params.numPeople}` 46 ======= 47 let link = props.type === "transport" ? `/transport/search?from=${params.from}&to=${params.to}&date=${params.date}` : props.type === "hotel" ? `/hotel/search?hotelLocation=${params.hotelLocation}&dateFrom=${params.dateFrom}&dateTo=${params.dateTo}&numBeds=${params.numBeds}` : "" 48 >>>>>>> parent of ac19a0c (authContext impl, admin panel impl, search bar fixes, reservations listings impl) 40 41 const getSortingFn = (type, arg) => { 42 if (type === 'hotel') { 43 if (arg === "priceAsc") 44 { 45 return (a, b) => { 46 return a.totalPrice - b.totalPrice; 47 } 48 } 49 else if (arg === "priceDesc") 50 { 51 return (a, b) => { 52 return -(a.totalPrice - b.totalPrice); 53 } 54 } 55 else if (arg === 'nameAsc') 56 { 57 return (a, b) => { 58 return a.hotelName.localeCompare(b.hotelName); 59 } 60 } 61 else if(arg === 'nameDesc') 62 { 63 return (a, b) => { 64 return -a.hotelName.localeCompare(b.hotelName); 65 } 66 } 67 } 68 else if (type === 'transport') 69 { 70 if (arg === "priceAsc") 71 { 72 return (a, b) => { 73 return a.price - b.price; 74 } 75 } 76 else if (arg === "priceDesc") 77 { 78 return (a, b) => { 79 return -(a.price - b.price); 80 } 81 } 82 } 83 else if (type === 'restaurant') 84 { 85 if (arg === 'nameAsc') 86 { 87 return (a, b) => { 88 return a.restaurantName.localeCompare(b.restaurantName); 89 } 90 } 91 else if(arg === 'nameDesc') 92 { 93 return (a, b) => { 94 return -a.restaurantName.localeCompare(b.restaurantName); 95 } 96 } 97 } 98 } 99 100 let link = props.type === "transport" ? `/transport/search?from=${params.from}&to=${params.to}&date=${params.date}&numPassengers=${params.numPassengers}` : props.type === "hotel" ? `/hotel/search?hotelLocation=${params.hotelLocation}&dateFrom=${params.dateFrom}&dateTo=${params.dateTo}&numBeds=${params.numBeds}&flexible=${params.flexible}` : `/restaurant/search?restaurantLocation=${params.restaurantLocation}&date=${params.date}&hourFrom=${params.hourFrom}&hourTo=${params.hourTo}&numPeople=${params.numPeople}` 49 101 console.log(link) 50 102 console.log(params.date) 51 const { data, isLoading, getData, setData} = useGet(link);103 const {data, isLoading, getData, setData} = useGet(link); 52 104 !isLoading && console.log(data) 53 105 return ( 54 106 <> 55 107 <Navigation></Navigation> 56 <SearchCriterias criterias={useParams()}></SearchCriterias>108 <SearchCriteriasBar type={props.type} criterias={useParams()}></SearchCriteriasBar> 57 109 <Container className="d-flex justify-content-end gx-5" style={{maxWidth: "60%"}}> 58 110 <Row> … … 61 113 </Col> 62 114 <Col> 63 <SortButton ></SortButton>115 <SortButton setSortingArg={setSortingArg} type={props.type}></SortButton> 64 116 </Col> 65 117 </Row> 66 118 </Container> 67 119 {props.type === "hotel" && !isLoading && data && <Container fluid> 68 {data. map(hotel => {120 {data.sort(getSortingFn(props.type, sortingArg)).map(hotel => { 69 121 return <HotelLisitng from={params.dateFrom} to={params.dateTo} data={hotel}/> 70 122 })} 71 123 </Container>} 72 124 {props.type === "transport" && !isLoading && data && <Container fluid> 73 {data. map(transport => {125 {data.sort(getSortingFn(props.type, sortingArg)).map(transport => { 74 126 return <TransportListing params={params} data={transport}/> 75 127 })} 76 128 </Container>} 77 129 {props.type === "restaurant" && !isLoading && data && <Container fluid> 78 {data. map(restaurant => {130 {data.sort(getSortingFn(props.type, sortingArg)).map(restaurant => { 79 131 return <RestaurantListing params={params} data={restaurant}/> 80 132 })}
Note:
See TracChangeset
for help on using the changeset viewer.