Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
24 changes: 19 additions & 5 deletions components/CategoryFilterWidget.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -6,12 +6,26 @@ import { UsersIcon } from '@heroicons/react/24/outline';
export const CategoryFilterWidget: React.FC = () => {
const { shortcuts, filterCategory, setFilterCategory, filterProfile, setFilterProfile } = useGTab();

const activeCategories = useMemo(() => {
return ['All', ...new Set(shortcuts.map(s => s.category))];
}, [shortcuts]);
const { activeCategories, uniqueProfiles } = useMemo(() => {
// ⚑ Bolt Optimization: Consolidate category and profile extraction into a single loop
// Replaces multiple mapping/flatMapping operations with a fast single pass
const categorySet = new Set<string>();
const profileSet = new Set<string>();

for (let i = 0; i < shortcuts.length; i++) {
const s = shortcuts[i];
categorySet.add(s.category);
if (s.profiles) {
for (let j = 0; j < s.profiles.length; j++) {
profileSet.add(s.profiles[j].name);
}
}
}

const uniqueProfiles = useMemo(() => {
return Array.from(new Set(shortcuts.flatMap(s => s.profiles?.map(p => p.name) || []))).sort();
return {
activeCategories: ['All', ...categorySet],
uniqueProfiles: Array.from(profileSet).sort()
};
}, [shortcuts]);

return (
Expand Down
1 change: 1 addition & 0 deletions src/vite-env.d.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
/// <reference types="vite/client" />