Skip to content

Commit 739d95a

Browse files
committed
チャットサイドバーの表示を改善
1 parent 6ff62d9 commit 739d95a

3 files changed

Lines changed: 77 additions & 21 deletions

File tree

Lines changed: 52 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
import { ChatAreaStateUpdater } from "@/(docs)/chatAreaState";
22
import { getChatOne, initContext } from "@/lib/chatHistory";
3+
import { getMarkdownSections, getPagesList } from "@/lib/docs";
34
import { StyledMarkdown } from "@/markdown/markdown";
45
import clsx from "clsx";
56
import 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
}

app/(docs)/@docs/[lang]/[pageId]/pageContent.tsx

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -259,7 +259,11 @@ function ChatListForSection(props: {
259259
<li className="menu-title">チャット</li>
260260
{filteredChatHistories.map(({ chatId }) => (
261261
<li key={chatId} className="">
262-
<Link className="link link-info" href={`/chat/${chatId}`}>
262+
<Link
263+
className="link link-info"
264+
href={`/chat/${chatId}`}
265+
scroll={false}
266+
>
263267
{chatId}
264268
</Link>
265269
</li>
@@ -306,7 +310,11 @@ function ChatListForSection(props: {
306310
>
307311
{filteredChatHistories.map(({ chatId }) => (
308312
<li key={chatId} className="">
309-
<Link className="link link-info" href={`/chat/${chatId}`}>
313+
<Link
314+
className="link link-info"
315+
href={`/chat/${chatId}`}
316+
scroll={false}
317+
>
310318
{chatId}
311319
</Link>
312320
</li>

app/markdown/multiHighlight.tsx

Lines changed: 15 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,8 @@ import type { Root, PhrasingContent } from "mdast";
44
import { JSX } from "react";
55
import { ExtraProps } from "react-markdown";
66
import clsx from "clsx";
7+
import { useChatId } from "@/(docs)/chatAreaState";
8+
import Link from "next/link";
79

810
export interface ReplacedRange {
911
start: number;
@@ -97,17 +99,28 @@ export const remarkMultiHighlight: Plugin<[ReplacedRange[]], Root> = (
9799
export function MultiHighlightTag({
98100
node,
99101
className,
102+
children,
100103
...props
101104
}: JSX.IntrinsicElements["ins"] & ExtraProps) {
105+
const currentChatId = useChatId(); // 現在開いているチャットid
106+
const thisChatIds = className ? className.split(" ") : [];
102107
return (
103108
<ins
104109
className={clsx(
105110
// classNameにチャットidが入っている。
106111
// 選択しているチャットに対応するdiffのみ濃いハイライトにするなど (TODO)
107112
className,
108-
"underline decoration-dashed underline-offset-[0.2rem] decoration-secondary/50"
113+
"underline decoration-dashed underline-offset-[0.2rem] decoration-secondary/50",
114+
currentChatId && thisChatIds.includes(currentChatId)
115+
? "bg-secondary/10"
116+
: "",
117+
"cursor-pointer hover:decoration-solid hover:decoration-secondary/80"
109118
)}
110119
{...props}
111-
/>
120+
>
121+
<Link href={`/chat/${thisChatIds.at(-1)}`} scroll={false}>
122+
{children}
123+
</Link>
124+
</ins>
112125
);
113126
}

0 commit comments

Comments
 (0)