diff --git a/src/app/content/App.tsx b/src/app/content/App.tsx index 79f9b67..b484e34 100644 --- a/src/app/content/App.tsx +++ b/src/app/content/App.tsx @@ -9,6 +9,8 @@ import { stringToHex } from '@/utils' import { Toaster } from '@/components/ui/Sonner' import UserInfoDomain from '@/domain/UserInfo' import Setup from '@/app/content/views/Setup' +import MessageListDomain from '@/domain/MessageList' +import { useEffect } from 'react' const hostRoomId = stringToHex(document.location.host) @@ -16,15 +18,31 @@ export default function App() { const send = useRemeshSend() const roomDomain = useRemeshDomain(RoomDomain()) const userInfoDomain = useRemeshDomain(UserInfoDomain()) - send(roomDomain.command.JoinRoomCommand(hostRoomId)) - const isLogin = useRemeshQuery(userInfoDomain.query.IsLoginQuery()) + const messageListDomain = useRemeshDomain(MessageListDomain()) + const joinRoomFinished = useRemeshQuery(roomDomain.query.IsFinishedQuery()) + const userInfoFinished = useRemeshQuery(userInfoDomain.query.IsFinishedQuery()) + + const userInfo = useRemeshQuery(userInfoDomain.query.UserInfoQuery()) + + const notUserInfo = userInfoFinished && !userInfo + + useEffect(() => { + if (userInfoFinished) { + if (userInfo) { + !joinRoomFinished && send(roomDomain.command.JoinRoomCommand(hostRoomId)) + } else { + send(messageListDomain.command.ClearListCommand()) + } + } + }, [userInfoFinished, userInfo, joinRoomFinished]) + return ( <>