diff --git a/frontend/leeds-beer-quest/src/components/dropdown-filter.tsx b/frontend/leeds-beer-quest/src/components/dropdown-filter.tsx index 5bf0ba1..22ed01f 100644 --- a/frontend/leeds-beer-quest/src/components/dropdown-filter.tsx +++ b/frontend/leeds-beer-quest/src/components/dropdown-filter.tsx @@ -1,4 +1,4 @@ -import { ListItemText, MenuItem, Select, SelectChangeEvent } from "@mui/material"; +import { InputLabel, ListItemText, MenuItem, Select, SelectChangeEvent } from "@mui/material"; import { useState } from "react"; export type TFilter = { @@ -7,28 +7,53 @@ export type TFilter = { } export type TDropdownFilterProps = { + prefillText: string; filters: TFilter[]; + setSelectedFilters: (filters: TFilter[]) => void; } export function DropdownFilter(props: TDropdownFilterProps) { - const [selectedTags, setSelectedTags] = useState([]); + const [selectedFilterStrings, setSelectedFilterStrings] = useState([]); - const handleChange = (event: SelectChangeEvent) => { + const handleChange = (event: SelectChangeEvent) => { const { value } = event.target; - setSelectedTags(typeof value == "string" ? value.split(",") : value); + + const filterStrings = typeof value === "string" ? value.split(",") : value; + setSelectedFilterStrings(filterStrings); + + updateSelectedFilters(filterStrings); }; + const updateSelectedFilters = (stringFilters: string[]): void => { + const currentFilters: TFilter[] = []; + + stringFilters.forEach((filterString) => { + filterString = filterString.trim(); + const foundFilter = props.filters.find((filter) => filter.name === filterString); + + if (foundFilter) { + currentFilters.push(foundFilter); + } + }); + + props.setSelectedFilters(currentFilters); + } + return( - selected.join(', ')}> + {props.filters.map((filter) => ( + + + + ))} + ); } \ No newline at end of file diff --git a/frontend/leeds-beer-quest/src/components/tag-selector.tsx b/frontend/leeds-beer-quest/src/components/tag-selector.tsx deleted file mode 100644 index c427c8b..0000000 --- a/frontend/leeds-beer-quest/src/components/tag-selector.tsx +++ /dev/null @@ -1,30 +0,0 @@ -import { ListItemText, MenuItem, Select, SelectChangeEvent } from "@mui/material"; -import { useState } from "react"; -import { TTag } from "../lib/types"; - -export type TTagSelectorProps = { - tags: TTag[]; -} - -export function TagSelector(props: TTagSelectorProps) { - const [selectedTags, setSelectedTags] = useState([]); - - const handleChange = (event: SelectChangeEvent) => { - const { value } = event.target; - setSelectedTags(typeof value == "string" ? value.split(",") : value); - }; - - return( - - ); -} \ No newline at end of file diff --git a/frontend/leeds-beer-quest/src/pages/index.tsx b/frontend/leeds-beer-quest/src/pages/index.tsx index ccdd821..8494b45 100644 --- a/frontend/leeds-beer-quest/src/pages/index.tsx +++ b/frontend/leeds-beer-quest/src/pages/index.tsx @@ -1,21 +1,30 @@ import { useQuery, useQueryClient } from "@tanstack/react-query"; -import { TagSelector } from "../components/tag-selector"; +import { useState } from "react"; +import { DropdownFilter } from "../components/dropdown-filter"; import { VenueGrid } from "../components/venue-grid"; import { API } from "../lib/api"; import { Environment } from "../lib/environment"; -import { TTag, TVenue } from "../lib/types"; +import { TCategory, TTag, TVenue } from "../lib/types"; export function Index() { const api = new API(Environment.BaseAPIUrl); const { data: venueData } = useQuery(["venues"], api.getVenues); + const { data: categoryData } = useQuery(["categories"], api.getCategories); + const { data: tagData } = useQuery(["tags"], api.getTags); - // return(
{data?.map(d => `${d} |`)}
); + const [filteredTags, setFilteredTags] = useState([]); + const [filteredCategories, setFilteredCategories] = useState([]); + return( <> - +

Leeds Beer Quest

+
+ + +
);