From b6308ccb4201c105b1ed465fca67f6226aa0c2da Mon Sep 17 00:00:00 2001 From: 777genius Date: Sun, 31 May 2026 03:03:55 +0300 Subject: [PATCH] perf(renderer): defer message filter option work --- .../team/messages/MessagesFilterPopover.tsx | 209 ++++++++++-------- 1 file changed, 112 insertions(+), 97 deletions(-) diff --git a/src/renderer/components/team/messages/MessagesFilterPopover.tsx b/src/renderer/components/team/messages/MessagesFilterPopover.tsx index 2ad14803..3f670635 100644 --- a/src/renderer/components/team/messages/MessagesFilterPopover.tsx +++ b/src/renderer/components/team/messages/MessagesFilterPopover.tsx @@ -6,13 +6,14 @@ import { Button } from '@renderer/components/ui/button'; import { Checkbox } from '@renderer/components/ui/checkbox'; import { Popover, PopoverContent, PopoverTrigger } from '@renderer/components/ui/popover'; import { Tooltip, TooltipContent, TooltipTrigger } from '@renderer/components/ui/tooltip'; -import { useStore } from '@renderer/store'; import { buildMemberColorMap } from '@renderer/utils/memberHelpers'; import { Filter } from 'lucide-react'; -import { useShallow } from 'zustand/react/shallow'; import type { InboxMessage, ResolvedTeamMember } from '@shared/types'; +const EMPTY_OPTIONS: string[] = []; +const EMPTY_COLOR_MAP = new Map(); + export interface MessagesFilterState { from: Set; to: Set; @@ -74,10 +75,19 @@ export const MessagesFilterPopover = ({ } }, [open, filter.from, filter.to, filter.showNoise]); - const colorMap = useMemo(() => buildMemberColorMap(members), [members]); + const colorMap = useMemo( + () => (open ? buildMemberColorMap(members) : EMPTY_COLOR_MAP), + [members, open] + ); - const fromOptions = useMemo(() => collectFromOptions(messages), [messages]); - const toOptions = useMemo(() => collectToOptions(messages), [messages]); + const fromOptions = useMemo( + () => (open ? collectFromOptions(messages) : EMPTY_OPTIONS), + [messages, open] + ); + const toOptions = useMemo( + () => (open ? collectToOptions(messages) : EMPTY_OPTIONS), + [messages, open] + ); const activeCount = (filter.from.size > 0 ? 1 : 0) + (filter.to.size > 0 ? 1 : 0); const draftCount = (draft.from.size > 0 ? 1 : 0) + (draft.to.size > 0 ? 1 : 0); @@ -133,102 +143,107 @@ export const MessagesFilterPopover = ({ {t('messages.filter.tooltip')} - - {/* Scrollable filter sections */} -
-
-

- {t('messages.filter.from')} -

-
- {fromOptions.length === 0 ? ( -

- {t('messages.filter.noData')} -

- ) : ( - fromOptions.map((name) => ( - // eslint-disable-next-line jsx-a11y/label-has-associated-control -- wraps Radix Checkbox which renders native input internally - - )) - )} + {open ? ( + + {/* Scrollable filter sections */} +
+
+

+ {t('messages.filter.from')} +

+
+ {fromOptions.length === 0 ? ( +

+ {t('messages.filter.noData')} +

+ ) : ( + fromOptions.map((name) => ( + // eslint-disable-next-line jsx-a11y/label-has-associated-control -- wraps Radix Checkbox which renders native input internally + + )) + )} +
+
+
+

+ {t('messages.filter.to')} +

+
+ {toOptions.length === 0 ? ( +

+ {t('messages.filter.noData')} +

+ ) : ( + toOptions.map((name) => ( + // eslint-disable-next-line jsx-a11y/label-has-associated-control -- wraps Radix Checkbox which renders native input internally + + )) + )} +
-
-

- {t('messages.filter.to')} -

-
- {toOptions.length === 0 ? ( -

- {t('messages.filter.noData')} -

- ) : ( - toOptions.map((name) => ( - // eslint-disable-next-line jsx-a11y/label-has-associated-control -- wraps Radix Checkbox which renders native input internally - - )) - )} -
-
-
- {/* Fixed bottom section */} -
-
- {/* eslint-disable-next-line jsx-a11y/label-has-associated-control -- wraps Radix Checkbox */} - + {/* Fixed bottom section */} +
+
+ {/* eslint-disable-next-line jsx-a11y/label-has-associated-control -- wraps Radix Checkbox */} + +
+
+ + +
-
- - -
-
- + + ) : null} ); };