Skip to content

Commit 4850b07

Browse files
Copilotna-trium-144
andcommitted
Rename variables: dynamicMdContent→sidebarMdContent, localDynamicMdContent→dynamicMdContent
Co-authored-by: na-trium-144 <[email protected]>
1 parent f090192 commit 4850b07

File tree

4 files changed

+31
-31
lines changed

4 files changed

+31
-31
lines changed

app/[docs_id]/dynamicMdContext.tsx

Lines changed: 13 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -3,38 +3,38 @@
33
import { createContext, ReactNode, useContext, useState } from "react";
44
import { DynamicMarkdownSection } from "./pageContent";
55

6-
export interface IDynamicMdContext {
7-
dynamicMdContent: DynamicMarkdownSection[];
8-
setDynamicMdContent: React.Dispatch<React.SetStateAction<DynamicMarkdownSection[]>>;
6+
export interface ISidebarMdContext {
7+
sidebarMdContent: DynamicMarkdownSection[];
8+
setSidebarMdContent: React.Dispatch<React.SetStateAction<DynamicMarkdownSection[]>>;
99
}
1010

11-
const DynamicMdContext = createContext<IDynamicMdContext | null>(null);
11+
const SidebarMdContext = createContext<ISidebarMdContext | null>(null);
1212

13-
export function useDynamicMdContext() {
14-
const context = useContext(DynamicMdContext);
13+
export function useSidebarMdContext() {
14+
const context = useContext(SidebarMdContext);
1515
if (!context) {
1616
throw new Error(
17-
"useDynamicMdContext must be used within a DynamicMdProvider"
17+
"useSidebarMdContext must be used within a SidebarMdProvider"
1818
);
1919
}
2020
return context;
2121
}
2222

23-
export function useDynamicMdContextOptional() {
24-
return useContext(DynamicMdContext);
23+
export function useSidebarMdContextOptional() {
24+
return useContext(SidebarMdContext);
2525
}
2626

27-
export function DynamicMdProvider({
27+
export function SidebarMdProvider({
2828
children,
2929
}: {
3030
children: ReactNode;
3131
}) {
32-
const [dynamicMdContent, setDynamicMdContent] =
32+
const [sidebarMdContent, setSidebarMdContent] =
3333
useState<DynamicMarkdownSection[]>([]);
3434

3535
return (
36-
<DynamicMdContext.Provider value={{ dynamicMdContent, setDynamicMdContent }}>
36+
<SidebarMdContext.Provider value={{ sidebarMdContent, setSidebarMdContent }}>
3737
{children}
38-
</DynamicMdContext.Provider>
38+
</SidebarMdContext.Provider>
3939
);
4040
}

app/[docs_id]/pageContent.tsx

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ import { MarkdownSection } from "./splitMarkdown";
55
import { ChatForm } from "./chatForm";
66
import { Heading, StyledMarkdown } from "./markdown";
77
import { useChatHistoryContext } from "./chatHistory";
8-
import { useDynamicMdContext } from "./dynamicMdContext";
8+
import { useSidebarMdContext } from "./dynamicMdContext";
99
import clsx from "clsx";
1010

1111
// MarkdownSectionに追加で、ユーザーが今そのセクションを読んでいるかどうか、などの動的な情報を持たせる
@@ -20,10 +20,10 @@ interface PageContentProps {
2020
docs_id: string;
2121
}
2222
export function PageContent(props: PageContentProps) {
23-
const { setDynamicMdContent } = useDynamicMdContext();
23+
const { setSidebarMdContent } = useSidebarMdContext();
2424

2525
// SSR用のローカルstate
26-
const [localDynamicMdContent, setLocalDynamicMdContent] = useState<
26+
const [dynamicMdContent, setDynamicMdContent] = useState<
2727
DynamicMarkdownSection[]
2828
>(
2929
props.splitMdContent.map((section, i) => ({
@@ -40,14 +40,14 @@ export function PageContent(props: PageContentProps) {
4040
inView: false,
4141
sectionId: `${props.docs_id}-${i}`,
4242
}));
43-
setLocalDynamicMdContent(newContent);
4443
setDynamicMdContent(newContent);
44+
setSidebarMdContent(newContent);
4545

4646
// クリーンアップ:コンポーネントがアンマウントされたらcontextをクリア
4747
return () => {
48-
setDynamicMdContent([]);
48+
setSidebarMdContent([]);
4949
};
50-
}, [props.splitMdContent, props.docs_id, setDynamicMdContent]);
50+
}, [props.splitMdContent, props.docs_id, setSidebarMdContent]);
5151

5252
const sectionRefs = useRef<Array<HTMLDivElement | null>>([]);
5353
// sectionRefsの長さをsplitMdContentに合わせる
@@ -70,15 +70,15 @@ export function PageContent(props: PageContentProps) {
7070
};
7171

7272
// ローカルstateとcontextの両方を更新
73-
setLocalDynamicMdContent(updateContent);
7473
setDynamicMdContent(updateContent);
74+
setSidebarMdContent(updateContent);
7575
};
7676
window.addEventListener("scroll", handleScroll);
7777
handleScroll();
7878
return () => {
7979
window.removeEventListener("scroll", handleScroll);
8080
};
81-
}, [setDynamicMdContent]);
81+
}, [setSidebarMdContent]);
8282

8383
const [isFormVisible, setIsFormVisible] = useState(false);
8484

@@ -91,7 +91,7 @@ export function PageContent(props: PageContentProps) {
9191
gridTemplateColumns: `1fr auto`,
9292
}}
9393
>
94-
{localDynamicMdContent.map((section, index) => (
94+
{dynamicMdContent.map((section, index) => (
9595
<>
9696
<div
9797
className="max-w-200"
@@ -147,7 +147,7 @@ export function PageContent(props: PageContentProps) {
147147
<div className="fixed bottom-4 right-4 left-4 lg:left-84 z-20">
148148
<ChatForm
149149
documentContent={props.documentContent}
150-
sectionContent={localDynamicMdContent}
150+
sectionContent={dynamicMdContent}
151151
docs_id={props.docs_id}
152152
close={() => setIsFormVisible(false)}
153153
/>

app/layout.tsx

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ import { PyodideProvider } from "./terminal/python/pyodide";
99
import { WandboxProvider } from "./terminal/wandbox/wandbox";
1010
import { EmbedContextProvider } from "./terminal/embedContext";
1111
import { AutoAnonymousLogin } from "./accountMenu";
12-
import { DynamicMdProvider } from "./[docs_id]/dynamicMdContext";
12+
import { SidebarMdProvider } from "./[docs_id]/dynamicMdContext";
1313

1414
export const metadata: Metadata = {
1515
title: "Create Next App",
@@ -23,7 +23,7 @@ export default function RootLayout({
2323
<html lang="ja">
2424
<body className="w-screen h-screen">
2525
<AutoAnonymousLogin />
26-
<DynamicMdProvider>
26+
<SidebarMdProvider>
2727
<div className="drawer lg:drawer-open">
2828
<input id="drawer-toggle" type="checkbox" className="drawer-toggle" />
2929
<div className="drawer-content flex flex-col">
@@ -43,7 +43,7 @@ export default function RootLayout({
4343
<Sidebar />
4444
</div>
4545
</div>
46-
</DynamicMdProvider>
46+
</SidebarMdProvider>
4747
</body>
4848
</html>
4949
);

app/sidebar.tsx

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -4,15 +4,15 @@ import { usePathname } from "next/navigation";
44
import { pagesList } from "./pagesList";
55
import { AccountMenu } from "./accountMenu";
66
import { ThemeToggle } from "./[docs_id]/themeToggle";
7-
import { useDynamicMdContext } from "./[docs_id]/dynamicMdContext";
7+
import { useSidebarMdContext } from "./[docs_id]/dynamicMdContext";
88

99
export function Sidebar() {
1010
const pathname = usePathname();
1111
const docs_id = pathname.replace(/^\//, "");
12-
const { dynamicMdContent } = useDynamicMdContext();
12+
const { sidebarMdContent } = useSidebarMdContext();
1313

1414
// 現在表示中のセクション(最初にinViewがtrueのもの)を見つける
15-
const currentSectionIndex = dynamicMdContent.findIndex(
15+
const currentSectionIndex = sidebarMdContent.findIndex(
1616
(section) => section.inView
1717
);
1818
return (
@@ -62,9 +62,9 @@ export function Sidebar() {
6262
<span className="mr-0">{page.id}.</span>
6363
{page.title}
6464
</Link>
65-
{`${group.id}-${page.id}` === docs_id && dynamicMdContent.length > 0 && (
65+
{`${group.id}-${page.id}` === docs_id && sidebarMdContent.length > 0 && (
6666
<ul className="ml-4 text-sm">
67-
{dynamicMdContent.slice(1).map((section, idx) => {
67+
{sidebarMdContent.slice(1).map((section, idx) => {
6868
// idx + 1 は実際のsectionIndexに対応(slice(1)で最初を除外しているため)
6969
const isCurrentSection = idx + 1 === currentSectionIndex;
7070
return (

0 commit comments

Comments
 (0)