Ignore:
Timestamp:
01/24/24 17:42:28 (5 months ago)
Author:
darsov2 <62809499+darsov2@…>
Branches:
master
Children:
0f5aa27
Parents:
5528b99
Message:

prefinal fixes

File:
1 edited

Legend:

Unmodified
Added
Removed
  • frontend/src/Pages/SearchPage.js

    r5528b99 r07f4e8b  
    1 import React from "react";
     1import React, {useState} from "react";
    22import Navigation from '../Components/Layout/Navbar/Navigation';
    33import 'bootstrap/dist/css/bootstrap.css';
    44import 'bootstrap/dist/js/bootstrap.js';
    55import HomeCarousel from '../Components/Layout/CarouselHome/Carousel';
    6 import { Card, Container, Nav, Row, Col } from 'react-bootstrap';
     6import {Card, Container, Nav, Row, Col} from 'react-bootstrap';
    77import TabComponent from '../Components/Tab/Tab';
    88import Offers from '../Components/Layout/Offers/Offers';
     
    1111import BecomeAHost from "../Components/BecomeAHost/BecomeAHost"
    1212import HotelLisitng from "../Components/Listings/HotelListing"
    13 import SearchCriterias from "../Components/SearchCriterias/SearchCriteriasBar";
     13import SearchCriteriasHotel from "../Components/SearchCriterias/SearchCriteriasHotel";
    1414import SortButton from "../Components/Listings/SortButton";
    1515import FilterButton from "../Components/Listings/FilterButton";
    1616import TransportListing from "../Components/Listings/TransportListing";
    1717import useGet from "../Components/Hooks/useGet";
    18 import { useParams } from "react-router-dom";
    19 <<<<<<< HEAD
     18import {useParams} from "react-router-dom";
    2019import SearchCriteriasBar from "../Components/SearchCriterias/SearchCriteriasBar";
    2120import RestaurantDetailsPage from "./RestaurantDetailsPage";
    2221import RestaurantListing from "../Components/Listings/RestaurantListing";
    23 =======
    24 >>>>>>> parent of ac19a0c (authContext impl, admin panel impl, search bar fixes, reservations listings impl)
    2522
    2623
     
    2926    const params = useParams();
    3027    console.log(params)
    31 
     28    const [sortingArg, setSortingArg] = useState("")
    3229
    3330    document.body.style.backgroundColor = "white"
     
    4138
    4239    }
    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}`
    49101    console.log(link)
    50102    console.log(params.date)
    51     const { data, isLoading, getData, setData } = useGet(link);
     103    const {data, isLoading, getData, setData} = useGet(link);
    52104    !isLoading && console.log(data)
    53105    return (
    54106        <>
    55107            <Navigation></Navigation>
    56             <SearchCriterias criterias={useParams()}></SearchCriterias>
     108            <SearchCriteriasBar type={props.type} criterias={useParams()}></SearchCriteriasBar>
    57109            <Container className="d-flex justify-content-end gx-5" style={{maxWidth: "60%"}}>
    58110                <Row>
     
    61113                    </Col>
    62114                    <Col>
    63                         <SortButton></SortButton>
     115                        <SortButton setSortingArg={setSortingArg} type={props.type}></SortButton>
    64116                    </Col>
    65117                </Row>
    66118            </Container>
    67119            {props.type === "hotel" && !isLoading && data && <Container fluid>
    68                 {data.map(hotel => {
     120                {data.sort(getSortingFn(props.type, sortingArg)).map(hotel => {
    69121                    return <HotelLisitng from={params.dateFrom} to={params.dateTo} data={hotel}/>
    70122                })}
    71                 </Container>}
     123            </Container>}
    72124            {props.type === "transport" && !isLoading && data && <Container fluid>
    73                 {data.map(transport => {
     125                {data.sort(getSortingFn(props.type, sortingArg)).map(transport => {
    74126                    return <TransportListing params={params} data={transport}/>
    75127                })}
    76128            </Container>}
    77129            {props.type === "restaurant" && !isLoading && data && <Container fluid>
    78                 {data.map(restaurant => {
     130                {data.sort(getSortingFn(props.type, sortingArg)).map(restaurant => {
    79131                    return <RestaurantListing params={params} data={restaurant}/>
    80132                })}
Note: See TracChangeset for help on using the changeset viewer.