From fbabcb91961af67be010d1f3ea769abb286543a9 Mon Sep 17 00:00:00 2001 From: Tomasz Misiukiewicz Date: Wed, 17 Apr 2024 14:34:17 +0200 Subject: [PATCH 1/3] implement filtering in new chat page --- src/pages/NewChatPage.tsx | 56 ++++++++++++++++++++++++++++----------- 1 file changed, 40 insertions(+), 16 deletions(-) diff --git a/src/pages/NewChatPage.tsx b/src/pages/NewChatPage.tsx index 8137bb0e8515..b93f24b490b9 100755 --- a/src/pages/NewChatPage.tsx +++ b/src/pages/NewChatPage.tsx @@ -50,13 +50,14 @@ function useOptions({isGroupChat}: NewChatPageProps) { const {options: listOptions, areOptionsInitialized} = useOptionsList({ shouldInitialize: didScreenTransitionEnd, }); + const maxParticipantsReached = useMemo(() => selectedOptions.length === CONST.REPORT.MAXIMUM_PARTICIPANTS, [selectedOptions.length]); - const options = useMemo(() => { + const defaultOptions = useMemo(() => { const filteredOptions = OptionsListUtils.getFilteredOptions( listOptions.reports ?? [], listOptions.personalDetails ?? [], betas ?? [], - debouncedSearchTerm, + '', selectedOptions, isGroupChat ? excludedGroupEmails : [], false, @@ -69,25 +70,38 @@ function useOptions({isGroupChat}: NewChatPageProps) { [], true, ); - const maxParticipantsReached = selectedOptions.length === CONST.REPORT.MAXIMUM_PARTICIPANTS; - - const headerMessage = OptionsListUtils.getHeaderMessage( - filteredOptions.personalDetails.length + filteredOptions.recentReports.length !== 0, - Boolean(filteredOptions.userToInvite), - debouncedSearchTerm.trim(), - maxParticipantsReached, - selectedOptions.some((participant) => participant?.searchText?.toLowerCase?.().includes(debouncedSearchTerm.trim().toLowerCase())), - ); - return {...filteredOptions, headerMessage, maxParticipantsReached}; - }, [betas, debouncedSearchTerm, isGroupChat, listOptions.personalDetails, listOptions.reports, selectedOptions]); + + return filteredOptions; + }, [betas, isGroupChat, listOptions.personalDetails, listOptions.reports, selectedOptions]); + + const options = useMemo(() => { + if (debouncedSearchTerm.trim() === '') { + return defaultOptions; + } + const filteredOptions = OptionsListUtils.filterOptions(defaultOptions, debouncedSearchTerm, {selectedOptions, excludeLogins: isGroupChat ? excludedGroupEmails : []}); + + return filteredOptions; + }, [debouncedSearchTerm, defaultOptions, isGroupChat, selectedOptions]); + + const headerMessage = useMemo( + () => + OptionsListUtils.getHeaderMessage( + options.personalDetails.length + options.recentReports.length !== 0, + Boolean(options.userToInvite), + debouncedSearchTerm.trim(), + maxParticipantsReached, + selectedOptions.some((participant) => participant?.searchText?.toLowerCase?.().includes(debouncedSearchTerm.trim().toLowerCase())), + ), + [debouncedSearchTerm, maxParticipantsReached, options.personalDetails.length, options.recentReports.length, options.userToInvite, selectedOptions], + ); useEffect(() => { - if (!debouncedSearchTerm.length || options.maxParticipantsReached) { + if (!debouncedSearchTerm.length || maxParticipantsReached) { return; } Report.searchInServer(debouncedSearchTerm); - }, [debouncedSearchTerm, options.maxParticipantsReached]); + }, [debouncedSearchTerm, maxParticipantsReached]); useEffect(() => { if (!newGroupDraft?.participants) { @@ -101,7 +115,17 @@ function useOptions({isGroupChat}: NewChatPageProps) { setSelectedOptions(newSelectedOptions); }, [newGroupDraft, personalData, personalDetails]); - return {...options, searchTerm, debouncedSearchTerm, setSearchTerm, areOptionsInitialized: areOptionsInitialized && didScreenTransitionEnd, selectedOptions, setSelectedOptions}; + return { + ...options, + searchTerm, + debouncedSearchTerm, + setSearchTerm, + areOptionsInitialized: areOptionsInitialized && didScreenTransitionEnd, + selectedOptions, + setSelectedOptions, + headerMessage, + maxParticipantsReached, + }; } function NewChatPage({isGroupChat}: NewChatPageProps) { From 59e70fe9ae8cf5eb1cd605542381d43aa1819319 Mon Sep 17 00:00:00 2001 From: Tomasz Misiukiewicz Date: Tue, 25 Jun 2024 11:40:07 +0200 Subject: [PATCH 2/3] remove max participants --- src/pages/NewChatPage.tsx | 6 ++---- 1 file changed, 2 insertions(+), 4 deletions(-) diff --git a/src/pages/NewChatPage.tsx b/src/pages/NewChatPage.tsx index 7aa51c72e50b..1c9d69c41d28 100755 --- a/src/pages/NewChatPage.tsx +++ b/src/pages/NewChatPage.tsx @@ -49,7 +49,6 @@ function useOptions({isGroupChat}: NewChatPageProps) { const {options: listOptions, areOptionsInitialized} = useOptionsList({ shouldInitialize: didScreenTransitionEnd, }); - const maxParticipantsReached = useMemo(() => selectedOptions.length === CONST.REPORT.MAXIMUM_PARTICIPANTS, [selectedOptions.length]); const defaultOptions = useMemo(() => { const filteredOptions = OptionsListUtils.getFilteredOptions( @@ -99,12 +98,12 @@ function useOptions({isGroupChat}: NewChatPageProps) { ); useEffect(() => { - if (!debouncedSearchTerm.length || maxParticipantsReached) { + if (!debouncedSearchTerm.length) { return; } Report.searchInServer(debouncedSearchTerm); - }, [debouncedSearchTerm, maxParticipantsReached]); + }, [debouncedSearchTerm]); useEffect(() => { if (!newGroupDraft?.participants) { @@ -142,7 +141,6 @@ function useOptions({isGroupChat}: NewChatPageProps) { selectedOptions, setSelectedOptions, headerMessage, - maxParticipantsReached, }; } From fc30cb232ccd374210b8e026b8a0c82bcf856b05 Mon Sep 17 00:00:00 2001 From: Tomasz Misiukiewicz Date: Tue, 25 Jun 2024 13:48:47 +0200 Subject: [PATCH 3/3] display selfDM in new chat --- src/pages/NewChatPage.tsx | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/src/pages/NewChatPage.tsx b/src/pages/NewChatPage.tsx index 1c9d69c41d28..17baddd39251 100755 --- a/src/pages/NewChatPage.tsx +++ b/src/pages/NewChatPage.tsx @@ -69,19 +69,19 @@ function useOptions({isGroupChat}: NewChatPageProps) { true, undefined, undefined, - CONST.IOU.MAX_RECENT_REPORTS_TO_SHOW, + 0, undefined, true, ); - return filteredOptions; }, [betas, isGroupChat, listOptions.personalDetails, listOptions.reports, selectedOptions]); const options = useMemo(() => { - if (debouncedSearchTerm.trim() === '') { - return defaultOptions; - } - const filteredOptions = OptionsListUtils.filterOptions(defaultOptions, debouncedSearchTerm, {selectedOptions, excludeLogins: isGroupChat ? excludedGroupEmails : []}); + const filteredOptions = OptionsListUtils.filterOptions(defaultOptions, debouncedSearchTerm, { + selectedOptions, + excludeLogins: isGroupChat ? excludedGroupEmails : [], + maxRecentReportsToShow: CONST.IOU.MAX_RECENT_REPORTS_TO_SHOW, + }); return filteredOptions; }, [debouncedSearchTerm, defaultOptions, isGroupChat, selectedOptions]);