@@ -6,44 +6,47 @@ import { Heading, StyledMarkdown } from "./markdown";
66import { useChatHistoryContext } from "./chatHistory" ;
77import { useSidebarMdContext } from "@/sidebar" ;
88import clsx from "clsx" ;
9- import { MarkdownSection , PageEntry } from "@/lib/docs" ;
9+ import {
10+ LanguageEntry ,
11+ MarkdownSection ,
12+ PageEntry ,
13+ PagePath ,
14+ } from "@/lib/docs" ;
1015
1116// MarkdownSectionに追加で、ユーザーが今そのセクションを読んでいるかどうか、などの動的な情報を持たせる
1217export type DynamicMarkdownSection = MarkdownSection & {
1318 inView : boolean ;
1419} ;
1520
1621interface PageContentProps {
17- documentContent : string ;
1822 splitMdContent : MarkdownSection [ ] ;
23+ langEntry : LanguageEntry ;
1924 pageEntry : PageEntry ;
20- lang : string ;
21- pageId : string ;
22- // TODO: チャット周りのid管理をsectionIdに移行し、docs_idパラメータを削除
23- docs_id : string ;
25+ path : PagePath ;
2426}
2527export function PageContent ( props : PageContentProps ) {
2628 const { setSidebarMdContent } = useSidebarMdContext ( ) ;
29+ const { splitMdContent, pageEntry, path } = props ;
2730
2831 // SSR用のローカルstate
2932 const [ dynamicMdContent , setDynamicMdContent ] = useState <
3033 DynamicMarkdownSection [ ]
3134 > (
32- props . splitMdContent . map ( ( section ) => ( {
35+ splitMdContent . map ( ( section ) => ( {
3336 ...section ,
3437 inView : false ,
3538 } ) )
3639 ) ;
3740
3841 useEffect ( ( ) => {
3942 // props.splitMdContentが変わったときにローカルstateとcontextの両方を更新
40- const newContent = props . splitMdContent . map ( ( section ) => ( {
43+ const newContent = splitMdContent . map ( ( section ) => ( {
4144 ...section ,
4245 inView : false ,
4346 } ) ) ;
4447 setDynamicMdContent ( newContent ) ;
45- setSidebarMdContent ( props . lang , props . pageId , newContent ) ;
46- } , [ props . splitMdContent , props . lang , props . pageId , setSidebarMdContent ] ) ;
48+ setSidebarMdContent ( path , newContent ) ;
49+ } , [ splitMdContent , path , setSidebarMdContent ] ) ;
4750
4851 const sectionRefs = useRef < Array < HTMLDivElement | null > > ( [ ] ) ;
4952 // sectionRefsの長さをsplitMdContentに合わせる
@@ -70,14 +73,14 @@ export function PageContent(props: PageContentProps) {
7073
7174 // ローカルstateとcontextの両方を更新
7275 setDynamicMdContent ( updateContent ) ;
73- setSidebarMdContent ( props . lang , props . pageId , updateContent ) ;
76+ setSidebarMdContent ( path , updateContent ) ;
7477 } ;
7578 window . addEventListener ( "scroll" , handleScroll ) ;
7679 handleScroll ( ) ;
7780 return ( ) => {
7881 window . removeEventListener ( "scroll" , handleScroll ) ;
7982 } ;
80- } , [ setSidebarMdContent , props . lang , props . pageId ] ) ;
83+ } , [ setSidebarMdContent , path ] ) ;
8184
8285 const [ isFormVisible , setIsFormVisible ] = useState ( false ) ;
8386
@@ -91,7 +94,7 @@ export function PageContent(props: PageContentProps) {
9194 } }
9295 >
9396 < Heading level = { 1 } >
94- 第{ props . pageEntry . index } 章: { props . pageEntry . title }
97+ 第{ pageEntry . index } 章: { pageEntry . title }
9598 </ Heading >
9699 < div />
97100 { dynamicMdContent . map ( ( section , index ) => (
@@ -104,17 +107,18 @@ export function PageContent(props: PageContentProps) {
104107 } }
105108 >
106109 { /* ドキュメントのコンテンツ */ }
107- < StyledMarkdown
108- content = { section . rawContent . replace (
109- / - r e p l \s * \n / ,
110- `-repl:${ section . id } \n`
111- ) }
112- />
110+ < StyledMarkdown content = { section . rawContent } />
113111 </ div >
114112 < div >
115113 { /* 右側に表示するチャット履歴欄 */ }
116114 { chatHistories
117- . filter ( ( c ) => c . sectionId === section . id )
115+ . filter (
116+ ( c ) =>
117+ c . sectionId === section . id ||
118+ // 対象のセクションが存在しないものは、introセクション(index=0)にフォールバックする
119+ ( index === 0 &&
120+ dynamicMdContent . every ( ( sec ) => c . sectionId !== sec . id ) )
121+ )
118122 . map ( ( { chatId, messages } ) => (
119123 < div
120124 key = { chatId }
@@ -150,9 +154,8 @@ export function PageContent(props: PageContentProps) {
150154 // replがz-10を使用することからそれの上にするためz-20
151155 < div className = "fixed bottom-4 right-4 left-4 lg:left-84 z-20" >
152156 < ChatForm
153- documentContent = { props . documentContent }
157+ path = { path }
154158 sectionContent = { dynamicMdContent }
155- docs_id = { props . docs_id }
156159 close = { ( ) => setIsFormVisible ( false ) }
157160 />
158161 </ div >
0 commit comments