import React, { useEffect, useState } from "react"; import Workspace from "@/models/workspace"; import LoadingChat from "./LoadingChat"; import ChatContainer from "./ChatContainer"; import paths from "@/utils/paths"; import ModalWrapper from "../ModalWrapper"; import { useParams } from "react-router-dom"; import { DnDFileUploaderProvider } from "./ChatContainer/DnDWrapper"; import { WarningCircle } from "@phosphor-icons/react"; import { TTSProvider, useWatchForAutoPlayAssistantTTSResponse, } from "../contexts/TTSProvider"; import { PENDING_HOME_MESSAGE } from "@/utils/constants"; export default function WorkspaceChat({ loading, workspace }) { useWatchForAutoPlayAssistantTTSResponse(); const { threadSlug = null } = useParams(); // Stores { key, workspace, history } currently rendered. Lags the props so // the previous chat stays mounted until the next one's history is ready, // avoiding a skeleton/loader flash on workspace/thread switches. const [loaded, setLoaded] = useState(null); useEffect(() => { async function getHistory() { if (loading) return; if (!workspace?.slug) { setLoaded({ key: "none", workspace: null, history: [] }); return false; } const chatHistory = threadSlug ? await Workspace.threads.chatHistory(workspace.slug, threadSlug) : await Workspace.chatHistory(workspace.slug); setLoaded({ key: `${workspace.slug}:${threadSlug ?? "default"}`, workspace, threadSlug, history: chatHistory, }); } getHistory(); }, [workspace, loading, threadSlug]); const hasPendingMessage = !!sessionStorage.getItem(PENDING_HOME_MESSAGE); if (loaded === null) { if (hasPendingMessage) { return (
); } returnThe workspace you're looking for is not available. It may have been deleted or you may not have access to it.