Skip to content

Commit 6cf3a12

Browse files
committed
use useRpcFetch for firstChatContact
1 parent 3d5dd08 commit 6cf3a12

File tree

1 file changed

+8
-15
lines changed

1 file changed

+8
-15
lines changed

packages/frontend/src/components/screens/MainScreen/MainScreen.tsx

Lines changed: 8 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -397,20 +397,10 @@ function ChatHeading({ chat }: { chat: T.FullChat }) {
397397
const openViewProfileDialog = useOpenViewProfileDialog()
398398
const accountId = selectedAccountId()
399399

400-
const [firstChatContact, setFirstChatContact] = useState<T.Contact | null>(
401-
null
402-
)
403-
useEffect(() => {
404-
BackendRemote.rpc
405-
.getContact(accountId, chat.contactIds[0])
406-
.then(setFirstChatContact)
407-
.catch(
408-
log.error.bind(
409-
null,
410-
'error fetching first contact of chat for chat subtitle'
411-
)
412-
)
413-
}, [chat.contactIds, accountId])
400+
const firstChatContact = useRpcFetch(BackendRemote.rpc.getContact, [
401+
accountId,
402+
chat.contactIds[0],
403+
])
414404

415405
const onTitleClick = () => {
416406
if (!chat) {
@@ -470,7 +460,10 @@ function ChatHeading({ chat }: { chat: T.FullChat }) {
470460
}
471461
}
472462

473-
const subtitle = chatSubtitle(chat, firstChatContact)
463+
const subtitle = chatSubtitle(
464+
chat,
465+
firstChatContact.result?.ok ? firstChatContact.result?.value : null
466+
)
474467

475468
return (
476469
<div className='navbar-heading' data-no-drag-region>

0 commit comments

Comments
 (0)