mirror of
https://gitee.com/wanwujie/deer-flow
synced 2026-04-30 01:04:48 +08:00
fix(frontend): add stable ids for chat resizable panels (#1341)
Signed-off-by: sysusugan <sugan@foxmail.com>
This commit is contained in:
@@ -1,4 +1,5 @@
|
|||||||
import { FilesIcon, XIcon } from "lucide-react";
|
import { FilesIcon, XIcon } from "lucide-react";
|
||||||
|
import { usePathname } from "next/navigation";
|
||||||
import { useEffect, useMemo, useRef, useState } from "react";
|
import { useEffect, useMemo, useRef, useState } from "react";
|
||||||
import type { GroupImperativeHandle } from "react-resizable-panels";
|
import type { GroupImperativeHandle } from "react-resizable-panels";
|
||||||
|
|
||||||
@@ -27,6 +28,7 @@ const ChatBox: React.FC<{ children: React.ReactNode; threadId: string }> = ({
|
|||||||
threadId,
|
threadId,
|
||||||
}) => {
|
}) => {
|
||||||
const { thread } = useThread();
|
const { thread } = useThread();
|
||||||
|
const pathname = usePathname();
|
||||||
const threadIdRef = useRef(threadId);
|
const threadIdRef = useRef(threadId);
|
||||||
const layoutRef = useRef<GroupImperativeHandle>(null);
|
const layoutRef = useRef<GroupImperativeHandle>(null);
|
||||||
|
|
||||||
@@ -84,6 +86,10 @@ const ChatBox: React.FC<{ children: React.ReactNode; threadId: string }> = ({
|
|||||||
return artifactsOpen;
|
return artifactsOpen;
|
||||||
}, [artifactsOpen, artifacts]);
|
}, [artifactsOpen, artifacts]);
|
||||||
|
|
||||||
|
const resizableIdBase = useMemo(() => {
|
||||||
|
return pathname.replace(/[^a-zA-Z0-9_-]+/g, "-").replace(/^-+|-+$/g, "");
|
||||||
|
}, [pathname]);
|
||||||
|
|
||||||
useEffect(() => {
|
useEffect(() => {
|
||||||
if (layoutRef.current) {
|
if (layoutRef.current) {
|
||||||
if (artifactPanelOpen) {
|
if (artifactPanelOpen) {
|
||||||
@@ -96,6 +102,7 @@ const ChatBox: React.FC<{ children: React.ReactNode; threadId: string }> = ({
|
|||||||
|
|
||||||
return (
|
return (
|
||||||
<ResizablePanelGroup
|
<ResizablePanelGroup
|
||||||
|
id={`${resizableIdBase}-panels`}
|
||||||
orientation="horizontal"
|
orientation="horizontal"
|
||||||
defaultLayout={{ chat: 100, artifacts: 0 }}
|
defaultLayout={{ chat: 100, artifacts: 0 }}
|
||||||
groupRef={layoutRef}
|
groupRef={layoutRef}
|
||||||
@@ -104,6 +111,7 @@ const ChatBox: React.FC<{ children: React.ReactNode; threadId: string }> = ({
|
|||||||
{children}
|
{children}
|
||||||
</ResizablePanel>
|
</ResizablePanel>
|
||||||
<ResizableHandle
|
<ResizableHandle
|
||||||
|
id={`${resizableIdBase}-separator`}
|
||||||
className={cn(
|
className={cn(
|
||||||
"opacity-33 hover:opacity-100",
|
"opacity-33 hover:opacity-100",
|
||||||
!artifactPanelOpen && "pointer-events-none opacity-0",
|
!artifactPanelOpen && "pointer-events-none opacity-0",
|
||||||
|
|||||||
Reference in New Issue
Block a user