diff --git a/frontend/src/components/format/FormatPage.jsx b/frontend/src/components/format/FormatPage.jsx index 56f11dd..044ba51 100644 --- a/frontend/src/components/format/FormatPage.jsx +++ b/frontend/src/components/format/FormatPage.jsx @@ -9,6 +9,7 @@ import FilterMenu from '../ui/FilterMenu'; import SortMenu from '../ui/SortMenu'; import {Loader} from 'lucide-react'; import Alert from '@ui/Alert'; +import SearchBar from '@ui/SearchBar'; import {useFormatModal} from '@hooks/useFormatModal'; function FormatPage() { @@ -23,6 +24,7 @@ function FormatPage() { const [isCloning, setIsCloning] = useState(false); const [isLoading, setIsLoading] = useState(true); const [mergeConflicts, setMergeConflicts] = useState([]); + const [searchQuery, setSearchQuery] = useState(''); const navigate = useNavigate(); @@ -144,20 +146,27 @@ function FormatPage() { const getFilteredAndSortedFormats = () => { let filtered = [...formats]; - // Apply filters + // Apply search filter + if (searchQuery) { + filtered = filtered.filter( + format => + format.content.name + .toLowerCase() + .includes(searchQuery.toLowerCase()) || + format.content.tags?.some(tag => + tag.toLowerCase().includes(searchQuery.toLowerCase()) + ) + ); + } + + // Apply existing filters if (filterType === 'tag' && filterValue) { filtered = filtered.filter(format => format.content.tags?.includes(filterValue) ); - } else if (filterType === 'name' && filterValue) { - filtered = filtered.filter(format => - format.content.name - .toLowerCase() - .includes(filterValue.toLowerCase()) - ); } - // Apply sorting + // Rest of the sorting logic remains the same... return filtered.sort((a, b) => { switch (sortBy) { case 'dateModified': @@ -172,7 +181,6 @@ function FormatPage() { } }); }; - if (isLoading) { return (
@@ -218,23 +226,23 @@ function FormatPage() { return (
-
- - + +
+ +
+
+ +
diff --git a/frontend/src/components/profile/ProfilePage.jsx b/frontend/src/components/profile/ProfilePage.jsx index 6994e4a..573be70 100644 --- a/frontend/src/components/profile/ProfilePage.jsx +++ b/frontend/src/components/profile/ProfilePage.jsx @@ -8,6 +8,7 @@ import {Profiles, CustomFormats} from '@api/data'; import FilterMenu from '../ui/FilterMenu'; import SortMenu from '../ui/SortMenu'; import {Loader} from 'lucide-react'; +import SearchBar from '@ui/SearchBar'; function ProfilePage() { const [profiles, setProfiles] = useState([]); @@ -21,6 +22,7 @@ function ProfilePage() { const [isCloning, setIsCloning] = useState(false); const [isLoading, setIsLoading] = useState(true); const [mergeConflicts, setMergeConflicts] = useState([]); + const [searchQuery, setSearchQuery] = useState(''); const navigate = useNavigate(); @@ -136,22 +138,44 @@ function ProfilePage() { const sortedAndFilteredProfiles = profiles .filter(profile => { + // Apply search filter + if (searchQuery) { + return ( + profile.content.name + .toLowerCase() + .includes(searchQuery.toLowerCase()) || + profile.content.tags?.some( + ( + tag // Changed from profile.tags + ) => + tag + .toLowerCase() + .includes(searchQuery.toLowerCase()) + ) + ); + } + + // Apply existing filters if (filterType === 'tag') { - return profile.tags && profile.tags.includes(filterValue); + return ( + profile.content.tags && + profile.content.tags.includes(filterValue) + ); // Changed from profile.tags } if (filterType === 'date') { - const profileDate = new Date(profile.date_modified); + const profileDate = new Date(profile.modified_date); // This looks correct already const filterDate = new Date(filterValue); return profileDate.toDateString() === filterDate.toDateString(); } return true; }) .sort((a, b) => { - if (sortBy === 'name') return a.name.localeCompare(b.name); + if (sortBy === 'name') + return a.content.name.localeCompare(b.content.name); // Changed from a.name if (sortBy === 'dateCreated') - return new Date(b.date_created) - new Date(a.date_created); + return new Date(b.created_date) - new Date(a.created_date); if (sortBy === 'dateModified') - return new Date(b.date_modified) - new Date(a.date_modified); + return new Date(b.modified_date) - new Date(a.modified_date); return 0; }); @@ -200,15 +224,23 @@ function ProfilePage() { return (
-
- - + +
+ +
+
+ +
{sortedAndFilteredProfiles.map(profile => ( diff --git a/frontend/src/components/regex/RegexPage.jsx b/frontend/src/components/regex/RegexPage.jsx index 1956bca..80a9b93 100644 --- a/frontend/src/components/regex/RegexPage.jsx +++ b/frontend/src/components/regex/RegexPage.jsx @@ -7,6 +7,7 @@ import FilterMenu from '../ui/FilterMenu'; import SortMenu from '../ui/SortMenu'; import {Loader} from 'lucide-react'; import Alert from '@ui/Alert'; +import SearchBar from '@ui/SearchBar'; function RegexPage() { const [patterns, setPatterns] = useState([]); @@ -18,6 +19,7 @@ function RegexPage() { const [allTags, setAllTags] = useState([]); const [isCloning, setIsCloning] = useState(false); const [isLoading, setIsLoading] = useState(true); + const [searchQuery, setSearchQuery] = useState(''); // Load initial data useEffect(() => { @@ -84,18 +86,27 @@ function RegexPage() { const getFilteredAndSortedPatterns = () => { let filtered = [...patterns]; - // Apply filters + // Apply search filter + if (searchQuery) { + filtered = filtered.filter( + pattern => + pattern.name + .toLowerCase() + .includes(searchQuery.toLowerCase()) || + pattern.tags?.some(tag => + tag.toLowerCase().includes(searchQuery.toLowerCase()) + ) + ); + } + + // Apply existing filters if (filterType === 'tag' && filterValue) { filtered = filtered.filter(pattern => pattern.tags?.includes(filterValue) ); - } else if (filterType === 'name' && filterValue) { - filtered = filtered.filter(pattern => - pattern.name.toLowerCase().includes(filterValue.toLowerCase()) - ); } - // Apply sorting + // Rest of the sorting logic remains the same... return filtered.sort((a, b) => { switch (sortBy) { case 'dateModified': @@ -125,15 +136,23 @@ function RegexPage() { return (
-
- - + +
+ +
+
+ +
{getFilteredAndSortedPatterns().map(pattern => ( diff --git a/frontend/src/components/ui/SearchBar.jsx b/frontend/src/components/ui/SearchBar.jsx new file mode 100644 index 0000000..5275e26 --- /dev/null +++ b/frontend/src/components/ui/SearchBar.jsx @@ -0,0 +1,53 @@ +import React, {useState, useEffect} from 'react'; +import {Search, X} from 'lucide-react'; + +const SearchBar = ({ + onSearch, + placeholder = 'Search...', + value = '', + className = '' +}) => { + const [searchTerm, setSearchTerm] = useState(value); + + useEffect(() => { + setSearchTerm(value); + }, [value]); + + const handleChange = e => { + const newValue = e.target.value; + setSearchTerm(newValue); + onSearch(newValue); + }; + + const clearSearch = () => { + setSearchTerm(''); + onSearch(''); + }; + + return ( +
+ + + {searchTerm && ( + + )} +
+ ); +}; + +export default SearchBar;