11import { getChatOne , initContext } from "@/lib/chatHistory" ;
22import { getMarkdownSections , getPagesList } from "@/lib/docs" ;
33import { ChatAreaContent } from "./chatArea" ;
4- import { notFound } from "next/navigation" ;
4+ import { ChatAreaStateUpdater } from "@/(docs)/chatAreaState" ;
5+ import { ReactNode } from "react" ;
6+ import clsx from "clsx" ;
7+ import Link from "next/link" ;
58
69export default async function ChatPage ( {
710 params,
@@ -14,7 +17,12 @@ export default async function ChatPage({
1417 const chatData = await getChatOne ( chatId , ctx ) ;
1518
1619 if ( ! chatData ) {
17- notFound ( ) ;
20+ // notFound(); だとページ全体が404になってしまう
21+ return (
22+ < ChatAreaContainer chatId = { chatId } >
23+ < p > 指定されたチャットのデータが見つかりません。</ p >
24+ </ ChatAreaContainer >
25+ ) ;
1826 }
1927
2028 const pagesList = await getPagesList ( ) ;
@@ -28,12 +36,55 @@ export default async function ChatPage({
2836 const targetSection = sections . find ( ( sec ) => sec . id === chatData . sectionId ) ;
2937
3038 return (
31- < ChatAreaContent
32- chatId = { chatId }
33- chatData = { chatData }
34- targetLang = { targetLang }
35- targetPage = { targetPage }
36- targetSection = { targetSection }
37- />
39+ < ChatAreaContainer chatId = { chatId } >
40+ < ChatAreaContent
41+ chatId = { chatId }
42+ chatData = { chatData }
43+ targetLang = { targetLang }
44+ targetPage = { targetPage }
45+ targetSection = { targetSection }
46+ />
47+ </ ChatAreaContainer >
48+ ) ;
49+ }
50+
51+ function ChatAreaContainer ( props : { chatId : string ; children : ReactNode } ) {
52+ return (
53+ < aside
54+ className = { clsx (
55+ // モバイルでは全画面表示する
56+ "fixed inset-0 pt-20 bg-base-100" ,
57+ // PCではスクロールで動かない右サイドバー
58+ "lg:sticky lg:top-0 lg:pt-4 lg:w-1/3 lg:h-screen lg:shadow-md lg:bg-base-200 " ,
59+ "p-4" ,
60+ "flex flex-col" ,
61+ "overflow-y-auto"
62+ ) }
63+ >
64+ < ChatAreaStateUpdater chatId = { props . chatId } />
65+ < div className = "flex flex-row items-center" >
66+ < span className = "flex-1 text-base font-bold opacity-40" >
67+ AIへの質問
68+ </ span >
69+ < Link className = "btn btn-ghost" href = "/chat" scroll = { false } >
70+ < svg
71+ className = "w-8 h-8 -scale-x-100"
72+ viewBox = "0 0 24 24"
73+ fill = "none"
74+ xmlns = "http://www.w3.org/2000/svg"
75+ >
76+ < path
77+ d = "M18 17L13 12L18 7M11 17L6 12L11 7"
78+ stroke = "currentColor"
79+ strokeWidth = "1.5"
80+ strokeLinecap = "round"
81+ strokeLinejoin = "round"
82+ />
83+ </ svg >
84+ < span className = "text-lg" > 閉じる</ span >
85+ </ Link >
86+ </ div >
87+ { props . children }
88+ </ aside >
3889 ) ;
3990}
0 commit comments