From 681a5cad74d8070db7383ccd8040b36c65a2c204 Mon Sep 17 00:00:00 2001 From: Guilherme Gazzo Date: Fri, 23 Oct 2020 22:57:35 -0300 Subject: [PATCH 1/2] Fix thread listing wrong items --- client/channel/Threads/ContextualBar/List.js | 14 ++++++++------ 1 file changed, 8 insertions(+), 6 deletions(-) diff --git a/client/channel/Threads/ContextualBar/List.js b/client/channel/Threads/ContextualBar/List.js index 29ca7318d6f88..21b675430a044 100644 --- a/client/channel/Threads/ContextualBar/List.js +++ b/client/channel/Threads/ContextualBar/List.js @@ -61,8 +61,6 @@ export function withData(WrappedComponent) { return new Promise((resolve) => { ref.current = resolve; }); }, []); - useEffect(() => () => Threads.current.remove({}, () => {}), [text, type]); - useEffect(() => { if (state !== ENDPOINT_STATES.DONE || !data || !data.threads) { return; @@ -71,10 +69,8 @@ export function withData(WrappedComponent) { data.threads.forEach(({ _id, ...message }) => { Threads.current.upsert({ _id }, filterProps(message)); }); - - ref.current && ref.current(); - setTotal(data.total); + ref.current && ref.current(); }, [data, state]); useEffect(() => { @@ -97,12 +93,18 @@ export function withData(WrappedComponent) { const cursor = Tracker.autorun(() => { const query = { ...type === 'subscribed' && { replies: { $in: [userId] } }, + ...type === 'unread' && { _id: { $in: subscription?.tunread } }, + ...text && { + $text: { + $search: text, + }, + }, }; setThreads(Threads.current.find(query, { sort: { tlm: -1 } }).fetch().map(filterProps)); }); return () => cursor.stop(); - }, [room._id, type, setThreads, userId]); + }, [room._id, type, setThreads, userId, subscription.tunread]); const handleTextChange = useCallback((e) => { setPagination({ skip: 0, count: LIST_SIZE }); From 87de2b255e51fb3e44d4f47074b6681997b27afa Mon Sep 17 00:00:00 2001 From: Guilherme Gazzo Date: Sat, 24 Oct 2020 23:42:56 -0300 Subject: [PATCH 2/2] Hook Dep --- client/channel/Threads/ContextualBar/List.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/client/channel/Threads/ContextualBar/List.js b/client/channel/Threads/ContextualBar/List.js index 21b675430a044..8d43cb32fd886 100644 --- a/client/channel/Threads/ContextualBar/List.js +++ b/client/channel/Threads/ContextualBar/List.js @@ -104,7 +104,7 @@ export function withData(WrappedComponent) { }); return () => cursor.stop(); - }, [room._id, type, setThreads, userId, subscription.tunread]); + }, [room._id, type, setThreads, userId, subscription.tunread, text]); const handleTextChange = useCallback((e) => { setPagination({ skip: 0, count: LIST_SIZE });