source: frontend/src/Pages/SearchPage.js@ 07f4e8b

Last change on this file since 07f4e8b was 07f4e8b, checked in by darsov2 <62809499+darsov2@…>, 5 months ago

prefinal fixes

  • Property mode set to 100644
File size: 5.7 KB
Line 
1import React, {useState} from "react";
2import Navigation from '../Components/Layout/Navbar/Navigation';
3import 'bootstrap/dist/css/bootstrap.css';
4import 'bootstrap/dist/js/bootstrap.js';
5import HomeCarousel from '../Components/Layout/CarouselHome/Carousel';
6import {Card, Container, Nav, Row, Col} from 'react-bootstrap';
7import TabComponent from '../Components/Tab/Tab';
8import Offers from '../Components/Layout/Offers/Offers';
9import MostVisitedBar from '../Components/MostVisited/MostVisitedBar';
10import MostPopularRoutesCont from '../Components/MostPopularRoutes/MostPopularRoutesCont';
11import BecomeAHost from "../Components/BecomeAHost/BecomeAHost"
12import HotelLisitng from "../Components/Listings/HotelListing"
13import SearchCriteriasHotel from "../Components/SearchCriterias/SearchCriteriasHotel";
14import SortButton from "../Components/Listings/SortButton";
15import FilterButton from "../Components/Listings/FilterButton";
16import TransportListing from "../Components/Listings/TransportListing";
17import useGet from "../Components/Hooks/useGet";
18import {useParams} from "react-router-dom";
19import SearchCriteriasBar from "../Components/SearchCriterias/SearchCriteriasBar";
20import RestaurantDetailsPage from "./RestaurantDetailsPage";
21import RestaurantListing from "../Components/Listings/RestaurantListing";
22
23
24const SearchPage = (props) => {
25
26 const params = useParams();
27 console.log(params)
28 const [sortingArg, setSortingArg] = useState("")
29
30 document.body.style.backgroundColor = "white"
31 var hotelData = {
32 "hotelName": "Име на сместувањето",
33 "hotelLocation": "Скопје, Македонија",
34 "hotelCaption": "Краток опис",
35 "hotelDescription": "Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua. Ut enim ad minim veniam, quis nostrud exercitation",
36 "hotelPrice": 504.99,
37 "hotelRating": 9.1
38
39 }
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}`
101 console.log(link)
102 console.log(params.date)
103 const {data, isLoading, getData, setData} = useGet(link);
104 !isLoading && console.log(data)
105 return (
106 <>
107 <Navigation></Navigation>
108 <SearchCriteriasBar type={props.type} criterias={useParams()}></SearchCriteriasBar>
109 <Container className="d-flex justify-content-end gx-5" style={{maxWidth: "60%"}}>
110 <Row>
111 <Col>
112 <FilterButton></FilterButton>
113 </Col>
114 <Col>
115 <SortButton setSortingArg={setSortingArg} type={props.type}></SortButton>
116 </Col>
117 </Row>
118 </Container>
119 {props.type === "hotel" && !isLoading && data && <Container fluid>
120 {data.sort(getSortingFn(props.type, sortingArg)).map(hotel => {
121 return <HotelLisitng from={params.dateFrom} to={params.dateTo} data={hotel}/>
122 })}
123 </Container>}
124 {props.type === "transport" && !isLoading && data && <Container fluid>
125 {data.sort(getSortingFn(props.type, sortingArg)).map(transport => {
126 return <TransportListing params={params} data={transport}/>
127 })}
128 </Container>}
129 {props.type === "restaurant" && !isLoading && data && <Container fluid>
130 {data.sort(getSortingFn(props.type, sortingArg)).map(restaurant => {
131 return <RestaurantListing params={params} data={restaurant}/>
132 })}
133 </Container>}
134 </>
135 )
136}
137
138export default SearchPage;
Note: See TracBrowser for help on using the repository browser.