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
4 changes: 4 additions & 0 deletions .jules/bolt.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,3 +5,7 @@
## 2025-03-09 - Replace .map() with point updates for React state arrays
**Learning:** For updating single items in small React state arrays (e.g., layout configurations or task lists), using `array.map()` introduces significant performance overhead by iterating through the entire array and calling the callback for every element. This causes unnecessary processing.
**Action:** Prefer "point updates" using `findIndex` and array spreading over `array.map()`. This minimizes object allocations and improves fluidity, especially on lower-power devices.

## 2023-11-20 - Consolidating Iterations for Derived State Arrays
**Learning:** When deriving multiple unique sets of data from a single large source array (e.g., extracting distinct categories and profiles from a list of shortcuts), chaining declarative methods like `map`, `flatMap`, and `Set` in separate `useMemo` hooks is inefficient. It iterates the array multiple times and creates redundant intermediate arrays.
**Action:** Consolidate the logic into a single `useMemo` that uses a single `for...of` loop to build all required sets simultaneously. This minimizes iterations and significantly reduces memory allocation overhead.
23 changes: 18 additions & 5 deletions components/CategoryFilterWidget.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -6,12 +6,25 @@ 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(() => {
const categoriesSet = new Set<string>();
const profilesSet = new Set<string>();

for (const s of shortcuts) {
if (s.category) {
categoriesSet.add(s.category);
}
if (s.profiles) {
for (const p of s.profiles) {
profilesSet.add(p.name);
}
}
}

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

return (
Expand Down

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Large diffs are not rendered by default.

Loading