From ec9cdfa9cbda71b5bfb51c9857e93b2ae8f78425 Mon Sep 17 00:00:00 2001 From: Aleksandar Toplek Date: Sun, 8 Oct 2023 21:55:12 +0200 Subject: [PATCH] chore(app): Minor fixes and simplification --- web/apps/app/app/entities/page.tsx | 2 +- web/apps/app/app/settings/page.tsx | 19 +++++++++++++------ web/apps/app/src/hooks/useSearch.ts | 14 ++++++-------- 3 files changed, 20 insertions(+), 15 deletions(-) diff --git a/web/apps/app/app/entities/page.tsx b/web/apps/app/app/entities/page.tsx index 15eb263d82..87ed75da6a 100644 --- a/web/apps/app/app/entities/page.tsx +++ b/web/apps/app/app/entities/page.tsx @@ -98,7 +98,7 @@ export default function Entities() { }), [filteredItems, selectedType]); const results = useMemo(() => ( -
+
-
+
React.JSX.Element; +} + function SettingsPane() { const generalForm = useGeneralForm(); const profileForm = useProfileForm(); @@ -245,7 +252,7 @@ function SettingsPane() { const timeLocationForm = useTimeLocationForm(); const developerForm = useDeveloperForm(); - const categories = [ + const categories: SettingsCategory[] = [ { id: 'general', label: 'General', form: generalForm }, { id: 'lookAndFeel', label: 'Look and feel', form: lookAndFeelForm }, { id: 'profile', label: 'Profile', form: profileForm }, @@ -254,7 +261,7 @@ function SettingsPane() { { id: 'developer', label: 'Developer', form: developerForm }, ]; - const [filteredItems, setFilteredItems] = useState(categories); + const [filteredItems, setFilteredItems] = useState(categories); const [selectedCategory, setSelectedCategory] = useState(categories[0]); const handleFilteredItems = (updated: typeof categories) => { @@ -263,11 +270,11 @@ function SettingsPane() { }; return ( - - + +   - + {filteredItems.map(category => ( = [TItem[], string, (text: string) => void]; function useSearch(items?: TItem[], filterFunc?: (item: TItem, keyword: string) => boolean): UseSearchReturn { const [searchText, setSearchText] = useState(''); - - const handleSearchTextChange = (text: string) => { - setSearchText(text); - }; - const filteredItems = useMemo(() => searchText - ? (items || []).filter(i => filterFunc ? filterFunc(i, searchText.toLowerCase()) : defaultSearchFunc(i, searchText.toLocaleLowerCase())) - : items || [], [filterFunc, items, searchText]); + ? (items || []).filter(i => filterFunc + ? filterFunc(i, searchText.toLowerCase()) + : defaultSearchFunc(i, searchText.toLocaleLowerCase())) + : items || [], + [filterFunc, items, searchText]); - return [filteredItems, searchText, handleSearchTextChange]; + return [filteredItems, searchText, setSearchText]; } export default useSearch;