import { Hash, HashedObject, Identity, Resources } from '@hyper-hyper-space/core'; import { ChatSpace, Conversation } from '@hyper-hyper-space/home'; import { useObjectDiscoveryIfNecessary } from '@hyper-hyper-space/react'; import { Stack } from '@mui/material'; import { Box } from '@mui/system'; import { useEffect, useState } from 'react'; import AllChatsSummary from './AllChatsSummary'; import Chat from './Chat'; type AllChatsNav = { editProfile: () => void, viewProfile: (id: Hash) => void, viewConversation: (id: Hash) => void, viewChatSummary: () => void, viewContacts: () => void }; function AllChats(props: { onClose: () => void, noSummary?: boolean, narrowChat?: boolean, remoteIdHash?: Hash, chats: ChatSpace, localId: Identity, resources: Resources, resourcesForDiscovery: Resources, nav: AllChatsNav }) { const noSummary = props.noSummary || false; const narrowChat = props.narrowChat || false; const summaryWidth = noSummary? '100%' : (narrowChat? '40%' : '32%'); const chatWidth = noSummary? '100%' : (narrowChat? '60%' : '68%'); const [locallyFoundRemoteId, setLocallyFoundRemoteId] = useState(); const remoteId = useObjectDiscoveryIfNecessary(props.resourcesForDiscovery, props.remoteIdHash, locallyFoundRemoteId); const [conv, setConv] = useState(); useEffect(() => { if (props.remoteIdHash !== undefined) { props.resources.store.load(props.remoteIdHash).then((id?: HashedObject) => { if (id instanceof Identity) { setLocallyFoundRemoteId(id); } }); } }, [props.remoteIdHash]) useEffect(() => { if (props.localId !== undefined && remoteId !== undefined) { setConv(props.chats.getConversationFor(remoteId)); } }, [props.localId, remoteId]) return {(!noSummary || props.remoteIdHash === undefined) && } {(!noSummary || props.remoteIdHash !== undefined) && } ; } export default AllChats; export type { AllChatsNav };