refactor: reorg

This commit is contained in:
2026-02-27 12:34:55 +08:00
parent 88cfe03779
commit 807ce5a406
6 changed files with 30 additions and 26 deletions
+13 -15
View File
@@ -3,21 +3,23 @@ import { generateToc, type FileNode, type TocNode } from "../data-loader";
import { useLocation } from "@solidjs/router";
import { FileTreeNode, HeadingNode } from "./FileTree";
interface SidebarProps {
export interface SidebarProps {
isOpen: boolean;
onClose: () => void;
}
interface SidebarContentProps {
fileTree: FileNode[];
pathHeadings: Record<string, TocNode[]>;
currentPath: string;
onClose: () => void;
isDesktop?: boolean;
}
/**
* 侧边栏内容组件
*/
const SidebarContent: Component<{
fileTree: FileNode[];
pathHeadings: Record<string, TocNode[]>;
currentPath: string;
onClose: () => void;
}> = (props) => {
const SidebarContent: Component<SidebarContentProps> = (props) => {
const location = useLocation();
// 响应式获取当前文件的标题列表
@@ -82,9 +84,7 @@ const SidebarContent: Component<{
export const MobileSidebar: Component<SidebarProps> = (props) => {
const location = useLocation();
const [fileTree, setFileTree] = createSignal<FileNode[]>([]);
const [pathHeadings, setPathHeadings] = createSignal<
Record<string, TocNode[]>
>({});
const [pathHeadings, setPathHeadings] = createSignal<Record<string, TocNode[]>>({});
// 加载目录数据
onMount(async () => {
@@ -122,12 +122,10 @@ export const MobileSidebar: Component<SidebarProps> = (props) => {
/**
* 桌面端固定侧边栏
*/
export const DesktopSidebar: Component = () => {
export const DesktopSidebar: Component<{}> = () => {
const location = useLocation();
const [fileTree, setFileTree] = createSignal<FileNode[]>([]);
const [pathHeadings, setPathHeadings] = createSignal<
Record<string, TocNode[]>
>({});
const [pathHeadings, setPathHeadings] = createSignal<Record<string, TocNode[]>>({});
// 加载目录数据
onMount(async () => {
@@ -143,7 +141,7 @@ export const DesktopSidebar: Component = () => {
pathHeadings={pathHeadings()}
currentPath={location.pathname}
onClose={() => {}}
isDesktop={true}
isDesktop
/>
</aside>
);