refactor: chatServerConnection.chat -> useChat

This commit is contained in:
Shibo Lyu 2024-09-04 03:33:32 +08:00
parent c65ff6c892
commit 48c5ed4687
3 changed files with 74 additions and 54 deletions

View file

@ -1,18 +1,11 @@
<script lang="ts">
import { page } from '$app/stores';
import BgPattern from '$lib/components/BgPattern.svelte';
import { messageFromBlah, type Chat, type Message } from '$lib/types';
import { onDestroy } from 'svelte';
import ChatHeader from './ChatHeader.svelte';
import ChatHistory from './ChatHistory.svelte';
import ChatInput from './ChatInput.svelte';
import { BlahChatServerConnection } from '$lib/blah/connection/chatServer';
import { currentKeyPair } from '$lib/keystore';
import { BlahKeyPair, type EncodedBlahKeyPair } from '$lib/blah/crypto';
import { browser } from '$app/environment';
import { chatServerConnectionPool } from '$lib/chatServers';
import ServiceMessage from '$lib/components/ServiceMessage.svelte';
import ChatPage from './ChatPage.svelte';
import { useChat } from '$lib/chat';
$: roomId = $page.params.chatId;
@ -34,7 +27,7 @@
<div class="flex h-full w-full flex-col items-center justify-center">
{#if server}
{@const { info, messages, sendMessage } = server.chat(roomId)}
{@const { info, messages, sendMessage } = useChat(server, roomId)}
<ChatPage {info} {messages} on:sendMessage={sendMessage} />
{:else}
<ServiceMessage>