From 1cae1c9fda764011df057aaaae3ce9812e0d9bce Mon Sep 17 00:00:00 2001 From: AshAnand34 Date: Mon, 21 Jul 2025 21:22:05 -0700 Subject: [PATCH] Refactor UserTypeFilter component to use Chips for selection and update user type filtering logic --- src/components/UserTypeFilter.tsx | 80 ++++++++----------------------- src/pages/home/index.tsx | 13 +++++ src/tools/defineTool.tsx | 1 - src/tools/index.ts | 4 ++ 4 files changed, 38 insertions(+), 60 deletions(-) diff --git a/src/components/UserTypeFilter.tsx b/src/components/UserTypeFilter.tsx index e7fe782..0eea9b8 100644 --- a/src/components/UserTypeFilter.tsx +++ b/src/components/UserTypeFilter.tsx @@ -1,23 +1,11 @@ import React, { useState, useEffect } from 'react'; -import { - Box, - Chip, - FormControl, - InputLabel, - MenuItem, - OutlinedInput, - Select, - SelectChangeEvent, - Typography, - useTheme -} from '@mui/material'; +import { Box, Chip, Typography } from '@mui/material'; import { UserType } from '@tools/defineTool'; const userTypes: UserType[] = [ 'General Users', 'Developers', 'Designers', - 'Students', 'CyberSec' ]; @@ -32,54 +20,28 @@ export default function UserTypeFilter({ onUserTypesChange, label = 'Filter by User Type' }: UserTypeFilterProps) { - const theme = useTheme(); - - const handleChange = (event: SelectChangeEvent) => { - const { - target: { value } - } = event; - const newUserTypes = - typeof value === 'string' ? (value.split(',') as UserType[]) : value; - onUserTypesChange(newUserTypes); - }; - return ( - - {label} - - + + {label} + + + {userTypes.map((userType) => ( + { + const isSelected = selectedUserTypes.includes(userType); + const newUserTypes = isSelected + ? selectedUserTypes.filter((ut) => ut !== userType) + : [...selectedUserTypes, userType]; + onUserTypesChange(newUserTypes); + }} + sx={{ cursor: 'pointer' }} + /> + ))} + ); } diff --git a/src/pages/home/index.tsx b/src/pages/home/index.tsx index bf891d8..0d2fd92 100644 --- a/src/pages/home/index.tsx +++ b/src/pages/home/index.tsx @@ -2,9 +2,17 @@ import { Box, useTheme } from '@mui/material'; import Hero from 'components/Hero'; import Categories from './Categories'; import { Helmet } from 'react-helmet'; +import UserTypeFilter, { useUserTypeFilter } from 'components/UserTypeFilter'; +import { UserType } from '@tools/defineTool'; export default function Home() { const theme = useTheme(); + const { selectedUserTypes, setSelectedUserTypes } = useUserTypeFilter(); + + const handleUserTypesChange = (userTypes: UserType[]) => { + setSelectedUserTypes(userTypes); + }; + return ( + ); diff --git a/src/tools/defineTool.tsx b/src/tools/defineTool.tsx index 950c28f..32f64fb 100644 --- a/src/tools/defineTool.tsx +++ b/src/tools/defineTool.tsx @@ -8,7 +8,6 @@ export type UserType = | 'General Users' | 'Developers' | 'Designers' - | 'Students' | 'CyberSec'; export interface ToolMeta { diff --git a/src/tools/index.ts b/src/tools/index.ts index de81720..98219c6 100644 --- a/src/tools/index.ts +++ b/src/tools/index.ts @@ -145,6 +145,10 @@ export const filterToolsByUserTypes = ( if (userTypes.length === 0) return tools; return tools.filter((tool) => { + // Always treat xml tools as dev-only + if (tool.type === 'xml') { + return userTypes.includes('Developers'); + } // If tool has no userTypes defined, show it to all users if (!tool.userTypes || tool.userTypes.length === 0) return true;