项目文件夹

文件
2026-07-13 12:58:18 +08:00

61 行
1.6 KiB
TypeScript

此文件含有模棱两可的 Unicode 字符
此文件含有可能会与其他字符混淆的 Unicode 字符。 如果您是想特意这样的,可以安全地忽略该警告。 使用 Escape 按钮显示他们。
"use client";
import { usePathname } from "next/navigation";
import React, { createContext, useContext, useState, ReactNode } from "react";
interface LayoutState {
title: string;
description: string;
showHeader: boolean;
headerContent?: ReactNode;
sidebarContent?: ReactNode;
theme: "light" | "dark" | "auto";
agent: string;
}
interface LayoutContextType {
layoutState: LayoutState;
updateLayout: (updates: Partial<LayoutState>) => void;
}
const defaultLayoutState: LayoutState = {
title: "DeepMind × Gemini",
description:
"Powered by Google's most advanced AI models for generating LinkedIn and X posts",
showHeader: true,
theme: "light",
agent: "post_generation_agent",
};
const LayoutContext = createContext<LayoutContextType | undefined>(undefined);
export function LayoutProvider({ children }: { children: ReactNode }) {
const pathname = usePathname();
console.log(pathname);
const [layoutState, setLayoutState] = useState<LayoutState>({
...defaultLayoutState,
agent:
pathname == "/post-generator"
? "post_generation_agent"
: "stack_analysis_agent",
});
console.log(layoutState);
const updateLayout = (updates: Partial<LayoutState>) => {
setLayoutState((prev) => ({ ...prev, ...updates }));
};
return (
<LayoutContext.Provider value={{ layoutState, updateLayout }}>
{children}
</LayoutContext.Provider>
);
}
export function useLayout() {
const context = useContext(LayoutContext);
if (context === undefined) {
throw new Error("useLayout must be used within a LayoutProvider");
}
return context;
}