From b871f409133be28ae3a7f0a414981b2581028e99 Mon Sep 17 00:00:00 2001 From: ctc-devops <90984711+ctc-devops@users.noreply.github.com> Date: Sun, 4 Feb 2024 19:52:42 -0800 Subject: [PATCH] Filter by search input and dropdown selects for event_type, year, season, or subject (#31) * init push for catalog branch * Allowing users to search by input or with dropdown select * bt margin change and fix up --------- Co-authored-by: subinqkim --- src/pages/Catalog/Catalog.jsx | 163 +++++++++++++++++++++++++++------- 1 file changed, 129 insertions(+), 34 deletions(-) diff --git a/src/pages/Catalog/Catalog.jsx b/src/pages/Catalog/Catalog.jsx index 1f94a48..7e4fdff 100644 --- a/src/pages/Catalog/Catalog.jsx +++ b/src/pages/Catalog/Catalog.jsx @@ -1,45 +1,140 @@ -import { Table, Thead, Tbody, Tr, Th, Td, TableContainer } from '@chakra-ui/react'; +import { Table, Thead, Tbody, Tr, Th, Td, TableContainer, Badge, Input, Select, Flex, Box, Center, Button } from '@chakra-ui/react'; import { useState, useEffect } from 'react'; import { NPOBackend } from '../../utils/auth_utils'; +import { Link } from 'react-router-dom'; +const subjectsOptions = ['life skills', 'science', 'technology', 'engineering', 'math', 'college readiness']; +const eventOptions = ['guest speaker', 'study-trip', 'workshop', 'other']; +const yearOptions = ['junior', 'senior', 'both']; +const seasonOptions = ['fall', 'spring', 'summer', 'winter']; export default function Catalog() { const [tableData, setTableData] = useState([]); + const [searchTerm, setSearchTerm] = useState(''); + const [selectedFilters, setSelectedFilters] = useState({ + subject: '', + eventType: '', + season: '', + year: '', + }); useEffect(() => { const fetchCatalogData = async () => { - const response = await NPOBackend.get('/catalog'); + const params = { + title: searchTerm, + ...selectedFilters, + }; + console.log('fetching catalog data with params', params); + const response = await NPOBackend.get('/catalog', { + params: params + }); + console.log('response', response); setTableData(response.data); }; - fetchCatalogData().catch(console.error); - }, []); - - return ( - - - - - - - - - - - - - - {tableData.map(({ id, host, title, eventType, subject, description, year }) => ( - - - - - - - - - ))} - -
TitleHostCohort TypeEvent TypeSubjectDescription
{title}{host}{year}{eventType}{subject}{description}
-
- ); -} + const delay = setTimeout(() => { + fetchCatalogData().catch(console.error); + }, 750); // this is in miliseconds so 750 is .75 seconds, Vy design choice delay + + return () => clearTimeout(delay); + + }, [searchTerm, selectedFilters]); + + const handleSearch = (event) => { + console.log('searching for', event.target.value); + setSearchTerm(event.target.value); + }; + + const handleFilterChange = (event) => { + setSelectedFilters({ + ...selectedFilters, + [event.target.name]: event.target.value, + }); + }; + + return ( +
+ + + + + + + + + +
+ +

Event Catalog

+ + + + + + + + + + + + + + + + + + + + + {tableData.map(({ id, host, title, eventType, subject, year, season }) => ( + + + + + + ))} + +
EventHostTags
{title}{host} + + {eventType} + + + {subject} + + + {season} + + + {year} + +
+
+
+
+
+ ); + } + \ No newline at end of file