From 7adc58419902875fcb4e38876d50c7b9fcaedd80 Mon Sep 17 00:00:00 2001 From: Giovanni-Josserand Date: Sun, 7 Dec 2025 14:35:17 +0100 Subject: [PATCH] add scroll-y lock on search --- src/components/Event/Event.module.css | 1 + src/components/SearchBar/SearchBar.jsx | 55 ++++++++++++++++++- src/components/SearchBar/SearchBar.module.css | 52 ++++++++++++++++++ src/index.css | 8 ++- src/pages/Events/EventsPage.jsx | 44 ++++----------- src/pages/Events/EventsPage.module.css | 5 +- 6 files changed, 127 insertions(+), 38 deletions(-) diff --git a/src/components/Event/Event.module.css b/src/components/Event/Event.module.css index 142d004..04a40f6 100644 --- a/src/components/Event/Event.module.css +++ b/src/components/Event/Event.module.css @@ -7,6 +7,7 @@ .eventContainerTop { display: flex; + justify-content: space-between; } .eventContainerBottom{ diff --git a/src/components/SearchBar/SearchBar.jsx b/src/components/SearchBar/SearchBar.jsx index 8df2beb..3241c0c 100644 --- a/src/components/SearchBar/SearchBar.jsx +++ b/src/components/SearchBar/SearchBar.jsx @@ -1,6 +1,37 @@ import styles from "./SearchBar.module.css" +import {Link} from "react-router"; +import {useEffect, useState} from "react"; +import searchEvents from "../../utils/searchEvents.js"; + +function SearchBar() { + const [searchQuery, setSearchQuery] = useState(''); + const [searchResults, setSearchResults] = useState([]); + + useEffect(() => { + const performSearch = async (query) => { + if (query.trim() === '') { + setSearchResults([]); + return; + } + + const data = await searchEvents(query); + if (data) { + setSearchResults(data); + } else { + setSearchResults([]); + } + }; + + + const handler = setTimeout(() => { + performSearch(searchQuery); + }, 300); + + return () => { + clearTimeout(handler); + }; + }, [searchQuery]); -function SearchBar({ searchQuery, setSearchQuery}) { return (
event.preventDefault()}> @@ -15,6 +46,28 @@ function SearchBar({ searchQuery, setSearchQuery}) { onChange={(event) => setSearchQuery(event.target.value)} />
+ +
+ {searchResults.length > 0 ? ( +
+ ) : null} +
+ + + {searchResults.map((result, i) => ( + +
+
+ {result.image == null ? ( + Pas de photo de l'événement + ) : ( + Photo de l'événement + )} +
+

{result.name}

+
+ + ))}
); } diff --git a/src/components/SearchBar/SearchBar.module.css b/src/components/SearchBar/SearchBar.module.css index 5779207..ff2830e 100644 --- a/src/components/SearchBar/SearchBar.module.css +++ b/src/components/SearchBar/SearchBar.module.css @@ -10,6 +10,58 @@ display: flex; } + + +.eventImageDiv { + display: flex; + align-items: center; + justify-content: center; + margin-right: 1rem; + width: auto; + height: 2rem; + flex-shrink: 0; +} + +.searchedEvent{ + display: flex; + padding: 0.5rem; + border-radius: 15px; + align-items: center; +} + +.searchedEvent:hover { + background: #afafaf; + cursor: pointer; +} + +.searchedEvent p { + display: flex; + align-items: center; + text-decoration: none; + color: black; +} + + +.lineContainer{ + display: flex; + justify-content: center; + align-items: center; +} + +.line{ + height: 0; + width: 96%; + border: #606060 solid 1px; + margin: 0.5rem 0; +} + +.eventImage { + max-width: 100%; + max-height: 100%; + object-fit: contain; + border-radius: 20px; +} + .searchBarForm input{ background: none; box-shadow: none; diff --git a/src/index.css b/src/index.css index f7d7591..87c36d8 100644 --- a/src/index.css +++ b/src/index.css @@ -1,8 +1,10 @@ * { margin: 0; padding: 0; - width: 100%; box-sizing: border-box; +} + +html { overflow-x: hidden; } @@ -20,12 +22,14 @@ @media screen and (max-width: 768px) { .content{ padding: 0.7rem; - z-index:1; } } + + .content { padding: 1.5rem; z-index: 1; + width: 100%; } a { diff --git a/src/pages/Events/EventsPage.jsx b/src/pages/Events/EventsPage.jsx index fba2bdf..3728572 100644 --- a/src/pages/Events/EventsPage.jsx +++ b/src/pages/Events/EventsPage.jsx @@ -4,14 +4,12 @@ import {Link} from "react-router"; import styles from "./EventsPage.module.css"; import Filter from "../../components/Filter/Filter.jsx"; import SearchBar from "../../components/SearchBar/SearchBar.jsx"; -import searchEvents from "../../utils/searchEvents.js" function EventsPage(){ const [isFilterVisible, setIsFilterVisible] = useState(false); const [isSearchVisible, setIsSearchVisible] = useState(false); - const [searchQuery, setSearchQuery] = useState(''); - const [searchResults, setSearchResults] = useState([]); + const toggleFilters = () => { setIsFilterVisible(prev => !prev); }; @@ -21,33 +19,19 @@ function EventsPage(){ yearOrder: "asc", }); - - - useEffect(() => { - const performSearch = async (query) => { - if (query.trim() === '') { - setSearchResults([]); - return; - } - - const data = await searchEvents(query); - if (data) { - setSearchResults(data); - } else { - setSearchResults([]); - } - }; - - - const handler = setTimeout(() => { - performSearch(searchQuery); - }, 300); + if (isSearchVisible) { + document.documentElement.style.overflow = 'hidden'; + } else { + document.documentElement.style.overflow = ''; + } return () => { - clearTimeout(handler); + document.documentElement.style.overflow = ''; }; - }, [searchQuery]); + }, [isSearchVisible]); + + const [events] = useState([ @@ -259,13 +243,7 @@ function EventsPage(){ {isSearchVisible ? (
setIsSearchVisible(false)}>
- - {searchResults.map((event, index) => ( - - ))} +
) : null} diff --git a/src/pages/Events/EventsPage.module.css b/src/pages/Events/EventsPage.module.css index 6c7a2a5..321145b 100644 --- a/src/pages/Events/EventsPage.module.css +++ b/src/pages/Events/EventsPage.module.css @@ -34,6 +34,7 @@ padding: 5px 5px 5px 5px; } + .searchBarOverlay { position: fixed; top: 0; @@ -41,9 +42,9 @@ width: 100%; height: 100%; z-index: 100; + background-color: rgba(0, 0, 0, 0.3); + backdrop-filter: blur(4px); } - - .searchBarContainer{ display: flex; justify-content: center;