From 014b64c14e1aceebee9fdc8591afe32260955f98 Mon Sep 17 00:00:00 2001 From: ZL Asica <40444637+ZL-Asica@users.noreply.github.com> Date: Fri, 6 Dec 2024 12:50:19 -0600 Subject: [PATCH] style: adjust style --- src/components/Home/DonorDashboard/index.tsx | 94 +++++++------- src/components/common/Filters.tsx | 122 ++++++++++++------- src/components/common/SearchBar.tsx | 25 ++-- 3 files changed, 137 insertions(+), 104 deletions(-) diff --git a/src/components/Home/DonorDashboard/index.tsx b/src/components/Home/DonorDashboard/index.tsx index 294b0d1..0170d2a 100644 --- a/src/components/Home/DonorDashboard/index.tsx +++ b/src/components/Home/DonorDashboard/index.tsx @@ -1,6 +1,5 @@ import { Box, Typography } from '@mui/material'; -import { filter, lowerCase, some } from 'es-toolkit/compat'; -import { useState } from 'react'; +import { useState, useMemo } from 'react'; import OrganizationCard from './OrganizationCard'; @@ -18,43 +17,58 @@ const DonorDashboard = () => { (state) => state.organizationProfiles ); - // Filtered organizations based on search query - const filteredOrganizations = filter(organizationProfiles, (org) => { - if (!org.name) return false; - const searchTerm = lowerCase(searchQuery); - return ( - lowerCase(org.name).includes(searchTerm) || - lowerCase(org.location).includes(searchTerm) || - some(org.needs, (need) => lowerCase(need).includes(searchTerm)) - ); - }); + const filteredOrganizations = useMemo(() => { + return organizationProfiles.filter((org) => { + const matchesSearch = searchQuery + ? org.name.toLowerCase().includes(searchQuery.toLowerCase()) || + org.location.toLowerCase().includes(searchQuery.toLowerCase()) || + (org.needs || []).some((need) => + need.itemName.toLowerCase().includes(searchQuery.toLowerCase()) + ) + : true; - //filtering organizations based on needs and description - const filteredByNeedsAndDescription = filter(filteredOrganizations, (org) => { - const matchesNeeds = needsQuery - ? some(org.needs, (need) => - lowerCase(need.itemName || '').includes(lowerCase(needsQuery)) - ) - : true; + const matchesNeeds = needsQuery + ? (org.needs || []).some((need) => + need.itemName.toLowerCase().includes(needsQuery.toLowerCase()) + ) + : true; - const matchesDescription = descriptionQuery - ? lowerCase(org.description || '').includes(lowerCase(descriptionQuery)) - : true; + const matchesDescription = descriptionQuery + ? org.description + ?.toLowerCase() + .includes(descriptionQuery.toLowerCase()) + : true; - const matchesLocation = locationQuery - ? lowerCase(org.location || '').includes(lowerCase(locationQuery)) - : true; + const matchesLocation = locationQuery + ? org.location.toLowerCase().includes(locationQuery.toLowerCase()) + : true; - return matchesNeeds && matchesDescription && matchesLocation; - }); + return ( + matchesSearch && matchesNeeds && matchesDescription && matchesLocation + ); + }); + }, [ + organizationProfiles, + searchQuery, + needsQuery, + descriptionQuery, + locationQuery, + ]); return organizationProfiles.length > 0 ? ( -