增加分栏后可以全屏和还原的功能

This commit is contained in:
allen2fuc
2026-05-13 17:46:05 +08:00
parent b3d3f0edcb
commit db4d8e5090
6 changed files with 67 additions and 11 deletions
+36 -7
View File
@@ -9,6 +9,12 @@
import BottomNav from "@/components/BottomNav";
import ConnectScreen from "@/components/ConnectScreen";
import { useDevice } from "@/contexts/DeviceContext";
import {
AI_SPLIT_RESTORE_PATH_KEY,
readAndClearAiSplitRestorePath,
useAIDrawer,
} from "@/contexts/AIDrawerContext";
import { useIsLgUp } from "@/hooks/useIsLgUp";
import {
ChatRead,
MessageRead,
@@ -45,6 +51,7 @@ import {
Trash2,
Maximize2,
ChevronsRight,
ChevronsLeft,
} from "lucide-react";
import { useLocation } from "wouter";
import { useCallback, useEffect, useMemo, useRef, useState } from "react";
@@ -165,12 +172,10 @@ function moveLastOptimizeAfterAssistantReply(items: UIMessage[]): UIMessage[] {
}
let endAsst = firstAsst;
while (
endAsst + 1 < items.length &&
items[endAsst + 1].kind === "chat" &&
items[endAsst + 1].role === "assistant"
) {
endAsst++;
while (endAsst + 1 < items.length) {
const m = items[endAsst + 1];
if (m.kind === "chat" && m.role === "assistant") endAsst++;
else break;
}
if (lastOptIdx === endAsst + 1) return items;
@@ -199,7 +204,9 @@ export interface AIPageProps {
export default function AIPage({ variant = "page", onClose }: AIPageProps = {}) {
const isEmbedded = variant === "split";
const [, setLocation] = useLocation();
const [routePath, setLocation] = useLocation();
const isLgUp = useIsLgUp();
const { setOpen: setAiPanelOpen } = useAIDrawer();
const { isConnected, deviceState, api } = useDevice();
const mac = deviceState?.mac ?? "";
const language = deviceState?.language ?? 2;
@@ -207,6 +214,12 @@ export default function AIPage({ variant = "page", onClose }: AIPageProps = {})
const aiText = useMemo(() => resolveAILocale(language), [language]);
const restoreDesktopSplit = useCallback(() => {
const path = readAndClearAiSplitRestorePath();
setLocation(path);
setAiPanelOpen(true);
}, [setLocation, setAiPanelOpen]);
const [chatId, setChatId] = useState<string | null>(null);
const [messages, setMessages] = useState<UIMessage[]>([]);
const [input, setInput] = useState("");
@@ -692,6 +705,17 @@ export default function AIPage({ variant = "page", onClose }: AIPageProps = {})
{/* ── Header ── */}
<div className="page-header flex-shrink-0">
<div className="flex items-center gap-2 mr-auto">
{!isEmbedded && isLgUp && (
<button
type="button"
onClick={restoreDesktopSplit}
className="mr-0.5 flex h-9 w-9 flex-shrink-0 items-center justify-center rounded-full text-white/70 transition-colors active:text-white"
style={{ background: "rgba(44,44,46,0.6)" }}
aria-label={aiText.ariaRestoreSplit}
>
<ChevronsLeft size={18} />
</button>
)}
{isEmbedded && onClose && (
<>
<button
@@ -706,6 +730,11 @@ export default function AIPage({ variant = "page", onClose }: AIPageProps = {})
<button
type="button"
onClick={() => {
try {
sessionStorage.setItem(AI_SPLIT_RESTORE_PATH_KEY, routePath);
} catch {
/* ignore */
}
setLocation("/ai");
onClose();
}}