From 008dda735e133c31cca23314058d7a585cdd901d Mon Sep 17 00:00:00 2001 From: balzack Date: Mon, 16 Dec 2024 22:38:06 -0800 Subject: [PATCH] fix open thread error on resize --- app/client/web/src/content/Content.tsx | 3 +- app/client/web/src/content/useContent.hook.ts | 28 +++++++++---------- 2 files changed, 15 insertions(+), 16 deletions(-) diff --git a/app/client/web/src/content/Content.tsx b/app/client/web/src/content/Content.tsx index fda3361f..450fc94c 100644 --- a/app/client/web/src/content/Content.tsx +++ b/app/client/web/src/content/Content.tsx @@ -19,8 +19,7 @@ export function Content({ textCard }: { textCard: { cardId: null|string }}) { const openTopic = async (cardId: string) => { setAdding(true); try { - const id = await actions.openTopic(cardId); - actions.setFocus(null, id); + await actions.openTopic(cardId); } catch (err) { console.log(err); showError(); diff --git a/app/client/web/src/content/useContent.hook.ts b/app/client/web/src/content/useContent.hook.ts index e5c4acdb..31d8f0fb 100644 --- a/app/client/web/src/content/useContent.hook.ts +++ b/app/client/web/src/content/useContent.hook.ts @@ -245,22 +245,22 @@ export function useContent() { openTopic: async (cardId: string) => { const content = app.state.session.getContent() const card = state.cards.find(card => card.cardId === cardId) - if (!card) { - throw new Error('contact not found'); - } - const sealable = card.sealable && state.sealSet; - const thread = state.sorted.find(channel => { - const { sealed, cardId, members} = channel; - if (sealed === sealable && cardId == null && members.length === 1 && members[0].guid === card.guid) { - return true; + if (card) { + const sealable = card.sealable && state.sealSet; + const thread = state.sorted.find(channel => { + const { sealed, cardId, members} = channel; + if (sealed === sealable && cardId == null && members.length === 1 && members[0].guid === card.guid) { + return true; + } + return false; + }); + if (thread) { + app.actions.setFocus(null, thread.channelId) + } else { + const topic = await content.addChannel(sealable, sealable ? 'sealed' : 'superbasic', {}, [cardId]); + app.actions.setFocus(null, topic.id) } - return false; - }); - if (thread) { - return thread.channelId; } - const topic = await content.addChannel(sealable, sealable ? 'sealed' : 'superbasic', {}, [cardId]); - return topic.id; }, addTopic: async (sealed: boolean, subject: string, contacts: string[]) => { const content = app.state.session.getContent()