11import { ChatAreaStateUpdater } from "@/(docs)/chatAreaState" ;
22import { getChatOne , initContext } from "@/lib/chatHistory" ;
3+ import { getMarkdownSections , getPagesList } from "@/lib/docs" ;
34import { StyledMarkdown } from "@/markdown/markdown" ;
45import clsx from "clsx" ;
56import Link from "next/link" ;
@@ -14,38 +15,72 @@ export default async function ChatPage({
1415 const ctx = await initContext ( ) ;
1516 const chatData = await getChatOne ( chatId , ctx ) ;
1617
18+ const pagesList = await getPagesList ( ) ;
19+ const targetLang = pagesList . find (
20+ ( lang ) => lang . id === chatData . section . pagePath . split ( "/" ) [ 0 ]
21+ ) ;
22+ const targetPage = targetLang ?. pages . find (
23+ ( page ) => page . slug === chatData . section . pagePath . split ( "/" ) [ 1 ]
24+ ) ;
25+ const sections = await getMarkdownSections ( targetLang ! . id , targetPage ! . slug ) ;
26+ const targetSection = sections . find ( ( sec ) => sec . id === chatData . sectionId ) ;
27+
1728 return (
1829 < aside
1930 className = { clsx (
2031 // モバイルでは全画面表示する
21- "fixed inset-0 pt-16 bg-base-100" ,
32+ "fixed inset-0 pt-20 bg-base-100" ,
2233 // PCではスクロールで動かない右サイドバー
23- "lg:sticky lg:top-0 lg:pt-0 lg:w-1/3 lg:h-screen lg:shadow-md lg:bg-base-200 " ,
34+ "lg:sticky lg:top-0 lg:pt-4 lg:w-1/3 lg:h-screen lg:shadow-md lg:bg-base-200 " ,
35+ "p-4" ,
36+ "flex flex-col gap-2" ,
2437 "overflow-y-auto"
2538 ) }
2639 >
2740 < ChatAreaStateUpdater chatId = { chatId } />
2841 { chatId }
42+ < div className = "flex-none breadcrumbs text-sm" >
43+ < ul className = "flex-wrap" >
44+ < li >
45+ < Link href = { `/${ targetLang ?. id } /${ targetLang ?. pages [ 0 ] . slug } ` } >
46+ { targetLang ?. name }
47+ </ Link >
48+ </ li >
49+ < li >
50+ < Link href = { `/${ chatData . section . pagePath } ` } >
51+ { targetPage ?. index } . { targetPage ?. name }
52+ </ Link >
53+ </ li >
54+ < li >
55+ < Link href = { `/${ chatData . section . pagePath } #${ chatData . sectionId } ` } >
56+ { targetSection ?. title }
57+ </ Link >
58+ </ li >
59+ </ ul >
60+ </ div >
2961 < Link className = "btn" href = "/chat" >
3062 閉じる
3163 </ Link >
32- { chatData ?. messages . map ( ( msg , index ) => (
33- < div
34- key = { index }
35- className = { `chat ${ msg . role === "user" ? "chat-end" : "chat-start" } ` }
36- >
37- < div
38- className = { clsx (
39- msg . role === "user" && "chat-bubble p-0.5! bg-secondary/30" ,
40- msg . role === "ai" && "chat-bubble p-0.5!" ,
41- msg . role === "error" && "text-error"
42- ) }
43- style = { { maxWidth : "100%" , wordBreak : "break-word" } }
44- >
64+ { chatData ?. messages . map ( ( msg , index ) =>
65+ msg . role === "user" ? (
66+ < div key = { index } className = "chat chat-end" >
67+ < div
68+ className = "chat-bubble p-0.5! bg-secondary/30"
69+ style = { { maxWidth : "100%" , wordBreak : "break-word" } }
70+ >
71+ < StyledMarkdown content = { msg . content } />
72+ </ div >
73+ </ div >
74+ ) : msg . role === "ai" ? (
75+ < div key = { index } className = "" >
4576 < StyledMarkdown content = { msg . content } />
4677 </ div >
47- </ div >
48- ) ) }
78+ ) : (
79+ < div key = { index } className = "text-error" >
80+ { msg . content }
81+ </ div >
82+ )
83+ ) }
4984 </ aside >
5085 ) ;
5186}
0 commit comments