feat: auto expand in demo mode

This commit is contained in:
Henry Li
2026-01-24 23:51:11 +08:00
parent 2eb9bb2167
commit 099fb727cc
6 changed files with 34 additions and 5 deletions

View File

@@ -43,6 +43,7 @@ export default function ChatPage() {
open: artifactsOpen,
setOpen: setArtifactsOpen,
setArtifacts,
select: selectArtifact,
selectedArtifact,
} = useArtifacts();
const { thread_id: threadIdFromPath } = useParams<{ thread_id: string }>();
@@ -75,9 +76,16 @@ export default function ChatPage() {
useEffect(() => {
setArtifacts(thread.values.artifacts);
}, [setArtifacts, thread.values.artifacts]);
if (env.NEXT_PUBLIC_STATIC_WEBSITE_ONLY === "true") {
if (thread?.values?.artifacts?.length > 0) {
selectArtifact(thread.values.artifacts[0]!);
}
}
}, [selectArtifact, setArtifacts, thread.values.artifacts]);
const [todoListCollapsed, setTodoListCollapsed] = useState(true);
const [todoListCollapsed, setTodoListCollapsed] = useState(
env.NEXT_PUBLIC_STATIC_WEBSITE_ONLY !== "true",
);
const handleSubmit = useSubmitThread({
isNewThread,

View File

@@ -1,6 +1,8 @@
import {
Code2Icon,
CopyIcon,
DownloadIcon,
EyeIcon,
SquareArrowOutUpRightIcon,
XIcon,
} from "lucide-react";
@@ -31,6 +33,8 @@ import { useI18n } from "@/core/i18n/hooks";
import { checkCodeFile, getFileName } from "@/core/utils/files";
import { cn } from "@/lib/utils";
import { Tooltip } from "../tooltip";
import { useArtifacts } from "./context";
export function ArtifactFileDetail({
@@ -115,8 +119,16 @@ export function ArtifactFileDetail({
setViewMode(value as "code" | "preview")
}
>
<ToggleGroupItem value="code">Code</ToggleGroupItem>
<ToggleGroupItem value="preview">Preview</ToggleGroupItem>
<Tooltip content={t.common.code}>
<ToggleGroupItem value="code">
<Code2Icon />
</ToggleGroupItem>
</Tooltip>
<Tooltip content={t.common.preview}>
<ToggleGroupItem value="preview">
<EyeIcon />
</ToggleGroupItem>
</Tooltip>
</ToggleGroup>
)}
</div>

View File

@@ -1,6 +1,7 @@
import { createContext, useContext, useState, type ReactNode } from "react";
import { useSidebar } from "@/components/ui/sidebar";
import { env } from "@/env";
export interface ArtifactsContextType {
artifacts: string[];
@@ -28,7 +29,9 @@ export function ArtifactsProvider({ children }: ArtifactsProviderProps) {
const [artifacts, setArtifacts] = useState<string[]>([]);
const [selectedArtifact, setSelectedArtifact] = useState<string | null>(null);
const [autoSelect, setAutoSelect] = useState(true);
const [open, setOpen] = useState(false);
const [open, setOpen] = useState(
env.NEXT_PUBLIC_STATIC_WEBSITE_ONLY === "true",
);
const [autoOpen, setAutoOpen] = useState(true);
const { setOpen: setSidebarOpen } = useSidebar();

View File

@@ -22,6 +22,8 @@ export const enUS: Translations = {
custom: "Custom",
notAvailableInDemoMode: "Not available in demo mode",
loading: "Loading...",
code: "Code",
preview: "Preview",
},
// Welcome

View File

@@ -20,6 +20,8 @@ export interface Translations {
custom: string;
notAvailableInDemoMode: string;
loading: string;
code: string;
preview: string;
};
// Welcome

View File

@@ -22,6 +22,8 @@ export const zhCN: Translations = {
custom: "自定义",
notAvailableInDemoMode: "在演示模式下不可用",
loading: "加载中...",
code: "代码",
preview: "预览",
},
// Welcome