mirror of
https://github.com/MODSetter/SurfSense.git
synced 2026-04-25 00:36:31 +02:00
feat: integrate chat sharing functionality in header component
This commit is contained in:
parent
459a354e0f
commit
8e5a80fc19
3 changed files with 36 additions and 8 deletions
|
|
@ -1063,8 +1063,6 @@ export default function NewChatPage() {
|
|||
header={
|
||||
<ChatHeader
|
||||
searchSpaceId={searchSpaceId}
|
||||
thread={currentThread}
|
||||
onThreadVisibilityChange={handleVisibilityChange}
|
||||
/>
|
||||
}
|
||||
/>
|
||||
|
|
|
|||
|
|
@ -1,6 +1,11 @@
|
|||
"use client";
|
||||
|
||||
import { useQuery } from "@tanstack/react-query";
|
||||
import { useParams, usePathname } from "next/navigation";
|
||||
import { NotificationButton } from "@/components/notifications/NotificationButton";
|
||||
import { ChatShareButton } from "@/components/new-chat/chat-share-button";
|
||||
import { getThreadFull } from "@/lib/chat/thread-persistence";
|
||||
import type { ChatVisibility } from "@/lib/chat/thread-persistence";
|
||||
|
||||
interface HeaderProps {
|
||||
breadcrumb?: React.ReactNode;
|
||||
|
|
@ -11,6 +16,29 @@ export function Header({
|
|||
breadcrumb,
|
||||
mobileMenuTrigger,
|
||||
}: HeaderProps) {
|
||||
const params = useParams();
|
||||
const pathname = usePathname();
|
||||
|
||||
// Check if we're on a chat page
|
||||
const isChatPage = pathname?.includes("/new-chat") ?? false;
|
||||
|
||||
// Get chat_id from URL params
|
||||
const chatId = params?.chat_id
|
||||
? Number(Array.isArray(params.chat_id) ? params.chat_id[0] : params.chat_id)
|
||||
: null;
|
||||
|
||||
// Fetch current thread if on chat page and chat_id exists
|
||||
const { data: currentThread } = useQuery({
|
||||
queryKey: ["thread", chatId],
|
||||
queryFn: () => getThreadFull(chatId!),
|
||||
enabled: isChatPage && chatId !== null && chatId > 0,
|
||||
});
|
||||
|
||||
const handleVisibilityChange = (visibility: ChatVisibility) => {
|
||||
// Visibility change is handled by ChatShareButton internally
|
||||
// This callback can be used for additional side effects if needed
|
||||
};
|
||||
|
||||
return (
|
||||
<header className="sticky top-0 z-10 flex h-14 shrink-0 items-center gap-2 border-b bg-background/95 backdrop-blur supports-backdrop-filter:bg-background/60 px-4">
|
||||
{/* Left side - Mobile menu trigger + Breadcrumb */}
|
||||
|
|
@ -23,6 +51,13 @@ export function Header({
|
|||
<div className="flex items-center gap-2">
|
||||
{/* Notifications */}
|
||||
<NotificationButton />
|
||||
{/* Share button - only show on chat pages when thread exists */}
|
||||
{isChatPage && currentThread && (
|
||||
<ChatShareButton
|
||||
thread={currentThread}
|
||||
onVisibilityChange={handleVisibilityChange}
|
||||
/>
|
||||
)}
|
||||
</div>
|
||||
</header>
|
||||
);
|
||||
|
|
|
|||
|
|
@ -5,18 +5,14 @@ import type {
|
|||
GlobalNewLLMConfig,
|
||||
NewLLMConfigPublic,
|
||||
} from "@/contracts/types/new-llm-config.types";
|
||||
import type { ChatVisibility, ThreadRecord } from "@/lib/chat/thread-persistence";
|
||||
import { ChatShareButton } from "./chat-share-button";
|
||||
import { ModelConfigSidebar } from "./model-config-sidebar";
|
||||
import { ModelSelector } from "./model-selector";
|
||||
|
||||
interface ChatHeaderProps {
|
||||
searchSpaceId: number;
|
||||
thread?: ThreadRecord | null;
|
||||
onThreadVisibilityChange?: (visibility: ChatVisibility) => void;
|
||||
}
|
||||
|
||||
export function ChatHeader({ searchSpaceId, thread, onThreadVisibilityChange }: ChatHeaderProps) {
|
||||
export function ChatHeader({ searchSpaceId }: ChatHeaderProps) {
|
||||
const [sidebarOpen, setSidebarOpen] = useState(false);
|
||||
const [selectedConfig, setSelectedConfig] = useState<
|
||||
NewLLMConfigPublic | GlobalNewLLMConfig | null
|
||||
|
|
@ -52,7 +48,6 @@ export function ChatHeader({ searchSpaceId, thread, onThreadVisibilityChange }:
|
|||
return (
|
||||
<div className="flex items-center gap-2">
|
||||
<ModelSelector onEdit={handleEditConfig} onAddNew={handleAddNew} />
|
||||
<ChatShareButton thread={thread ?? null} onVisibilityChange={onThreadVisibilityChange} />
|
||||
<ModelConfigSidebar
|
||||
open={sidebarOpen}
|
||||
onOpenChange={handleSidebarClose}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue