From 1c3da972e088b90b5660a576b3cafc4aa209da83 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?B=C3=A1rbara=20Chaves?= Date: Wed, 27 Nov 2024 12:59:04 +0100 Subject: [PATCH 1/2] Add no results component --- client/src/components/ui/search-location.tsx | 14 +++- client/src/containers/map/controls/index.tsx | 6 +- client/src/containers/map/legends/index.tsx | 16 ++-- .../containers/map/search-location/index.tsx | 74 ++++++++++++------- 4 files changed, 74 insertions(+), 36 deletions(-) diff --git a/client/src/components/ui/search-location.tsx b/client/src/components/ui/search-location.tsx index da048d1..6d0ff9a 100644 --- a/client/src/components/ui/search-location.tsx +++ b/client/src/components/ui/search-location.tsx @@ -43,4 +43,16 @@ const SearchResultItem = ({ option, onOptionClick, children }: SearchResultI ); }; -export { SearchResultList, SearchResultItem }; +const SearchResultItemNotFound = ({ children }: PropsWithChildren) => ( +
  • + {children} + No results +
  • +); + +export { SearchResultList, SearchResultItem, SearchResultItemNotFound }; diff --git a/client/src/containers/map/controls/index.tsx b/client/src/containers/map/controls/index.tsx index 6962a61..4b45862 100644 --- a/client/src/containers/map/controls/index.tsx +++ b/client/src/containers/map/controls/index.tsx @@ -1,13 +1,15 @@ import MapZoomControl from "@/components/map/controls/zoom"; import Legends from "../legends"; import SearchLocation from "../search-location"; +import { useState } from "react"; const MapControlsContainer = () => { + const [legendOpen, setLegendOpen] = useState(true); return (
    - + o && setLegendOpen(false)} /> - +
    ); }; diff --git a/client/src/containers/map/legends/index.tsx b/client/src/containers/map/legends/index.tsx index edd5f08..7769d8c 100644 --- a/client/src/containers/map/legends/index.tsx +++ b/client/src/containers/map/legends/index.tsx @@ -4,7 +4,6 @@ import { useSyncDatasets } from "@/store/map"; import { Layers3Icon } from "lucide-react"; import LegendItem from "./item"; import { Button } from "@/components/ui/button"; -import { useState } from "react"; import { ScrollArea, ScrollAreaCorner, @@ -13,10 +12,12 @@ import { Scrollbar, } from "@radix-ui/react-scroll-area"; -const Legends = () => { +type LegendsProps = { + open: boolean; + onOpenChange: (o: boolean) => void; +}; +const Legends = ({ open, onOpenChange }: LegendsProps) => { const [datasets] = useSyncDatasets(); - const [open, setOpen] = useState(true); - const legendItems = Array.from(datasets).reverse(); return ( @@ -24,7 +25,7 @@ const Legends = () => { diff --git a/client/src/containers/map/search-location/index.tsx b/client/src/containers/map/search-location/index.tsx index 185e7ef..225596c 100644 --- a/client/src/containers/map/search-location/index.tsx +++ b/client/src/containers/map/search-location/index.tsx @@ -2,8 +2,13 @@ import { Button } from "@/components/ui/button"; import { Popover, PopoverTrigger, PopoverContent } from "@/components/ui/popover"; -import { SearchResultItem, SearchResultList } from "@/components/ui/search-location"; +import { + SearchResultItem, + SearchResultItemNotFound, + SearchResultList, +} from "@/components/ui/search-location"; import { useOpenStreetMapsLocations } from "@/hooks/openstreetmaps"; +import { cn } from "@/lib/utils"; import { PopoverClose } from "@radix-ui/react-popover"; import { ChevronRightIcon, MapIcon, MapPinIcon, SearchIcon, XIcon } from "lucide-react"; import { useCallback, useMemo, useState } from "react"; @@ -18,7 +23,10 @@ type LocationOption = { type StoryOption = Omit; -const SearchLocation = () => { +type SearchLocationProps = { + onOpenChange: (open: boolean) => void; +}; +const SearchLocation = ({ onOpenChange }: SearchLocationProps) => { const [open, setOpen] = useState(true); const [locationSearch, setLocationSearch] = useState(""); @@ -78,9 +86,9 @@ const SearchLocation = () => { duration: 1000, padding: { top: 50, bottom: 50, left: 350, right: 50 }, }); - setLocationSearch(""); setOpen(false); + onOpenChange(false); } }, [map], @@ -93,6 +101,7 @@ const SearchLocation = () => { const handleOpenChange = useCallback((open: boolean) => { setLocationSearch(""); setOpen(open); + onOpenChange(open); }, []); return ( @@ -108,11 +117,14 @@ const SearchLocation = () => {
    @@ -122,7 +134,7 @@ const SearchLocation = () => { type="text" value={locationSearch} placeholder="Search" - className="placeholder:text-popover-foreground/50 w-full border-2 border-background bg-background p-2 px-9 text-sm leading-none text-foreground placeholder:text-sm placeholder:font-light focus-visible:outline-global" + className="w-full border-2 border-background bg-background p-2 px-9 text-sm leading-none text-foreground placeholder:text-sm placeholder:font-light placeholder:text-popover-foreground/50 focus-visible:outline-global" /> {locationSearch.length >= 1 && (
    - {!!locationOptions.length && ( + {!!debouncedSearch.length && ( - {locationOptions.map((option) => ( - + {!!locationOptions?.length ? ( + locationOptions.map((option) => ( + + + + )) + ) : ( + - - ))} + + )} )} - {!!storiesOptions?.length && ( + {!!debouncedSearch?.length && ( - {storiesOptions.map((option) => ( - + {storiesOptions?.length ? ( + storiesOptions.map((option) => ( + + + + )) + ) : ( + - - ))} + + )} )}
    From 2c67140ea1dda266d2edaa7c540f9b60e9a34ca1 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?B=C3=A1rbara=20Chaves?= Date: Wed, 27 Nov 2024 16:56:43 +0100 Subject: [PATCH 2/2] Add translations to search locations box --- client/src/components/ui/search-location.tsx | 26 +++++++++++-------- .../containers/map/search-location/index.tsx | 10 ++++--- 2 files changed, 21 insertions(+), 15 deletions(-) diff --git a/client/src/components/ui/search-location.tsx b/client/src/components/ui/search-location.tsx index 6d0ff9a..fc4ca70 100644 --- a/client/src/components/ui/search-location.tsx +++ b/client/src/components/ui/search-location.tsx @@ -1,3 +1,4 @@ +import { useTranslations } from "@/i18n"; import { PropsWithChildren } from "react"; type SearchResultListProps = PropsWithChildren & { @@ -43,16 +44,19 @@ const SearchResultItem = ({ option, onOptionClick, children }: SearchResultI ); }; -const SearchResultItemNotFound = ({ children }: PropsWithChildren) => ( -
  • - {children} - No results -
  • -); +const SearchResultItemNotFound = ({ children }: PropsWithChildren) => { + const t = useTranslations(); + return ( +
  • + {children} + {t("No results")} +
  • + ); +}; export { SearchResultList, SearchResultItem, SearchResultItemNotFound }; diff --git a/client/src/containers/map/search-location/index.tsx b/client/src/containers/map/search-location/index.tsx index 225596c..b3965bd 100644 --- a/client/src/containers/map/search-location/index.tsx +++ b/client/src/containers/map/search-location/index.tsx @@ -8,6 +8,7 @@ import { SearchResultList, } from "@/components/ui/search-location"; import { useOpenStreetMapsLocations } from "@/hooks/openstreetmaps"; +import { useTranslations } from "@/i18n"; import { cn } from "@/lib/utils"; import { PopoverClose } from "@radix-ui/react-popover"; import { ChevronRightIcon, MapIcon, MapPinIcon, SearchIcon, XIcon } from "lucide-react"; @@ -27,6 +28,8 @@ type SearchLocationProps = { onOpenChange: (open: boolean) => void; }; const SearchLocation = ({ onOpenChange }: SearchLocationProps) => { + const t = useTranslations(); + const [open, setOpen] = useState(true); const [locationSearch, setLocationSearch] = useState(""); @@ -118,7 +121,6 @@ const SearchLocation = ({ onOpenChange }: SearchLocationProps) => { { onChange={handleSearchChange} type="text" value={locationSearch} - placeholder="Search" + placeholder={t("Search")} className="w-full border-2 border-background bg-background p-2 px-9 text-sm leading-none text-foreground placeholder:text-sm placeholder:font-light placeholder:text-popover-foreground/50 focus-visible:outline-global" /> {locationSearch.length >= 1 && ( @@ -152,7 +154,7 @@ const SearchLocation = ({ onOpenChange }: SearchLocationProps) => { {!!debouncedSearch.length && ( - + {!!locationOptions?.length ? ( locationOptions.map((option) => ( { )} {!!debouncedSearch?.length && ( - + {storiesOptions?.length ? ( storiesOptions.map((option) => (