crush-level-web/src/app/(main)/character/[id]/ChatButton.tsx

23 lines
698 B
TypeScript
Raw Normal View History

2025-12-17 10:13:47 +00:00
'use client';
import { useRouter } from 'next/navigation';
import { Button } from '@/components/ui/button';
import { useAsyncFn } from '@/hooks/tools';
import { useStreamChatStore } from '@/stores/stream-chat';
export default function ChatButton({ id }: { id: string }) {
const router = useRouter();
const createChannel = useStreamChatStore((s) => s.createChannel);
const { loading, run: createChannelAndPush } = useAsyncFn(async () => {
const channelId = await createChannel(id);
if (!channelId) return;
router.push(`/chat/${channelId}`);
});
return (
<Button loading={loading} onClick={() => createChannelAndPush()} variant="primary">
Chat
</Button>
);
}