Skip to content

Commit

Permalink
Merge pull request #317 from ReDI-School/313-filterpricemodal
Browse files Browse the repository at this point in the history
PriceRange-PopUp
  • Loading branch information
grabinskij authored Dec 6, 2024
2 parents 6adcf2c + e5206b7 commit 3415719
Show file tree
Hide file tree
Showing 10 changed files with 464 additions and 124 deletions.
10 changes: 10 additions & 0 deletions src/App.css
Original file line number Diff line number Diff line change
Expand Up @@ -36,3 +36,13 @@
.host {
color: grey;
}

.overlay {
position: fixed;
top: 0;
left: 0;
width: 100vw;
height: 100vh;
background-color: rgba(0, 0, 0, 0.6);
z-index: 1100;
}
34 changes: 13 additions & 21 deletions src/App.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -5,32 +5,18 @@ import "./App.css";
import CategoryTabs from "./components/CategoryTabs/CategoryTabs";
import ProductCard from "./components/ProductCard/ProductCard";
import CalendarToggle from "./components/calendarToggle/CalendarToggle";
import PriceRangeFilter from "./components/priceRange/PriceRangeFilter";
import { BASE_URL } from "./constants/constants";
import PriceRangeModal from "./components/PriceRangeModal/PriceRangeModal";


function App() {
const [places, setPlaces] = useState([]);
const [selectPlaceId, setSelectPlaceId] = useState(null);
const [searchParams] = useSearchParams();
const [isModalOpen, setModalOpen] = useState(false);
const [histogramData, setHistogramData] = useState([]);

const histogramData = [
{ from: 16, to: 23, count: 2 },
{ from: 37, to: 44, count: 13 },
{ from: 55, to: 63, count: 30 },
{ from: 76, to: 84, count: 50 },
{ from: 95, to: 103, count: 90 },
{ from: 116, to: 123, count: 60 },
{ from: 135, to: 143, count: 20 },
{ from: 156, to: 156, count: 12 },
{ from: 174, to: 182, count: 15 },
{ from: 194, to: 202, count: 8 },
{ from: 216, to: 224, count: 5 },
{ from: 233, to: 242, count: 10 },
{ from: 254, to: 261, count: 25 },
{ from: 273, to: 281, count: 40 },
{ from: 292, to: 304, count: 22 },
];
const toggleModal = () => setModalOpen((prev) => !prev);

useEffect(() => {
axios
Expand Down Expand Up @@ -59,9 +45,7 @@ function App() {
<CalendarToggle />
</div>

<CategoryTabs />

<PriceRangeFilter histogramData= {histogramData}/>
<CategoryTabs toggleModal={toggleModal} setHistogramData={setHistogramData} />

<div className="grid">
{places.map((place) => {
Expand All @@ -82,6 +66,14 @@ function App() {
);
})}
</div>
{isModalOpen && (
<PriceRangeModal
isOpen={isModalOpen}
className="overlay"
onClose={toggleModal}
histogramData={histogramData}
/>
)}
</>
);
}
Expand Down
4 changes: 2 additions & 2 deletions src/components/CategoryTabs/CategoryTabs.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ const categories = [
{ label: "Riverside Cabins", tag: constants.RIVERSIDE_CABINS, icon: <MdOutlineCabin size={28} /> },
];

const CategoryTabs = () => {
const CategoryTabs = ({toggleModal, setHistogramData}) => {
const [activeTab, setActiveTab] = useState(null);
const [showLeftArrow, setShowLeftArrow] = useState(false);
const [showRightArrow, setShowRightArrow] = useState(false);
Expand Down Expand Up @@ -124,7 +124,7 @@ const CategoryTabs = () => {
})}
</div>
<div className={styles.filterButtonWrapper}>
<FilterButton />
<FilterButton toggleModal={toggleModal} setHistogramData={setHistogramData} />
</div>
</div>
{showRightArrow && (
Expand Down
6 changes: 4 additions & 2 deletions src/components/CategoryTabs/CategoryTabs.module.css
Original file line number Diff line number Diff line change
Expand Up @@ -10,12 +10,13 @@
left: 0;
right: 0;
background-color: white;
z-index: 998;
z-index: 499;
padding-top: 15px;
box-shadow: 0 2px 4px rgba(0, 0, 0, 0.1);
}

.categoryMenu {
z-index: 1;
width: 95vw;
display: flex;
flex-direction: row;
Expand All @@ -29,7 +30,8 @@
display: flex;
justify-content: center;
overflow: hidden;
position: relative;
/* position: relative; */
z-index: 1;
}

.filterButtonWrapper {
Expand Down
55 changes: 42 additions & 13 deletions src/components/FilterButton/FilterButton.jsx
Original file line number Diff line number Diff line change
@@ -1,19 +1,48 @@
import React from 'react'
import styles from "./FilterButton.module.css"
import { useEffect } from "react";
import styles from "./FilterButton.module.css";
import { FontAwesomeIcon } from "@fortawesome/react-fontawesome";
import { faSliders } from "@fortawesome/free-solid-svg-icons";

const FilterButton = () => {
return (
const FilterButton = ({toggleModal, setHistogramData = () => {}}) => {
// Simulating dynamic data fetching or processing
useEffect(() => {
if (!setHistogramData) {
console.warn("setHistogramData is not provided to FilterButton");
return;
}
// Replace this logic with actual data processing from the provided file or API
const generateHistogramData = () => {
const minPrice = 9;
const maxPrice = 310;
const bins = 6; // Number of bins for histogram

<div className={styles.filterButton}>
<div className={styles.contentFilter}>
<FontAwesomeIcon icon={faSliders} className={styles.icon} />
<h6>Filters</h6>
</div>
</div>
const binSize = Math.ceil((maxPrice - minPrice) / bins);
const mockData = Array.from({ length: bins }, (_, index) => {
const from = minPrice + index * binSize;
const to = Math.min(from + binSize - 1, maxPrice);
const count = Math.floor(Math.random() * 20) + 1; // Random count for demo

)
}
return { from, to, count };
});

export default FilterButton
return mockData;
};

const data = generateHistogramData();
setHistogramData(data);
}, [setHistogramData]);

return (
<>
{/* Filter button */}
<div className={styles.filterButton} onClick={toggleModal}>
<div className={styles.contentFilter}>
<FontAwesomeIcon icon={faSliders} className={styles.icon} />
<h6>Filters</h6>
</div>
</div>
</>
);
};

export default FilterButton;
1 change: 1 addition & 0 deletions src/components/HeaderUserMenu/HeaderUserMenu.module.css
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
.headerContainer {
z-index:;
position: relative;
display: inline-block;
}
Expand Down
91 changes: 91 additions & 0 deletions src/components/PriceRangeModal/PriceRangeModal.jsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,91 @@
import React, { useState } from "react";
import styles from "./PriceRangeModal.module.css";
import PriceRangeFilter from "../priceRange/PriceRangeFilter";
import { CloseIcon } from "../../icons/CloseIcon";

const PriceRangeModal = ({ isOpen, onClose, histogramData, className }) => {
const [bedrooms, setBedrooms] = useState(0); // State for Bedrooms
const [beds, setBeds] = useState(0); // State for Beds
const [bathrooms, setBathrooms] = useState(0); // State for Bathrooms

// Increment and Decrement Handlers
const increment = (setter, value) => setter(value + 1);
const decrement = (setter, value) => {
if (value > 0) setter(value - 1);
};

if (!isOpen) return null;

return (
<div className={className}>
<div className={styles.priceModal}>
{/* Header Section */}
<div className={styles.header}>
<div className={styles.customCloseWrapper} onClick={onClose}>
<CloseIcon />
</div>
<h4>Filters</h4>
</div>

<div className={styles.range}>
<PriceRangeFilter histogramData={histogramData} />
</div>

{/* Rooms and Beds Section */}
<div className={styles.roomsSection}>
<h4 className={styles.title}>Rooms and Beds</h4>

{/* Bedrooms Section */}
<div className={styles.section}>
<div className={styles.label}>
<h4 className={styles.subtitle}>Bedrooms</h4>
</div>
<div className={styles.increment}>
<button className={styles.button} onClick={() => decrement(setBedrooms, bedrooms)}>-</button>
<h4 className={styles.sub}>{bedrooms || "Any"}</h4>
<button className={styles.button} onClick={() => increment(setBedrooms, bedrooms)}>+</button>
</div>
</div>

{/* Beds Section */}
<div className={styles.section}>
<div className={styles.label}>
<h4 className={styles.subtitle}>Beds</h4>
</div>
<div className={styles.increment}>
<button className={styles.button} onClick={() => decrement(setBeds, beds)}>-</button>
<h4 className={styles.sub}>{beds || "Any"}</h4>
<button className={styles.button} onClick={() => increment(setBeds, beds)}>+</button>
</div>
</div>

{/* Bathrooms Section */}
<div className={styles.section}>
<div className={styles.label}>
<h4 className={styles.subtitle}>Bathrooms</h4>
</div>
<div className={styles.increment}>
<button className={styles.button} onClick={() => decrement(setBathrooms, bathrooms)}>-</button>
<h4 className={styles.sub}>{bathrooms || "Any"}</h4>
<button className={styles.button} onClick={() => increment(setBathrooms, bathrooms)}>+</button>
</div>
</div>
</div>

{/* Submit Section */}
<div className={styles.submitSection}>
<button className={styles.clearAll} onClick={() => {
setBedrooms(0);
setBeds(0);
setBathrooms(0);
}}>
Clear all
</button>
<button className={styles.buttonModal}>Show 1,000+ places</button>
</div>
</div>
</div>
);
};

export default PriceRangeModal;
Loading

0 comments on commit 3415719

Please sign in to comment.