|
1
|
"use client" |
|
2
|
|
|
3
|
import Link from "next/link" |
|
4
|
import React, { useMemo } from "react" |
|
5
|
import { useSiteConfig } from "@/providers/SiteConfig" |
|
6
|
import { useAiAssistant } from "@/providers/AiAssistant" |
|
7
|
import { usePathname } from "next/navigation" |
|
8
|
import { BroomSparkle, MarkdownSolid } from "@medusajs/icons" |
|
9
|
import { useChat } from "@kapaai/react-sdk" |
|
10
|
import { ContentMenuSection } from "../Section" |
|
11
|
|
|
12
|
export const ContentMenuActions = () => { |
|
13
|
const { |
|
14
|
config: { baseUrl, basePath, features, contentMenuSections }, |
|
15
|
} = useSiteConfig() |
|
16
|
const pathname = usePathname() |
|
17
|
const { setChatOpened } = useAiAssistant() |
|
18
|
const { isGeneratingAnswer, isPreparingAnswer, submitQuery } = useChat() |
|
19
|
const loading = useMemo( |
|
20
|
() => isGeneratingAnswer || isPreparingAnswer, |
|
21
|
[isGeneratingAnswer, isPreparingAnswer] |
|
22
|
) |
|
23
|
const pageUrl = `${baseUrl}${basePath || ""}${pathname}`.replace(/\/$/, "") |
|
24
|
|
|
25
|
const handleAiAssistantClick = () => { |
|
26
|
if (loading) { |
|
27
|
return |
|
28
|
} |
|
29
|
submitQuery(`Explain the page ${pageUrl}`) |
|
30
|
setChatOpened(true) |
|
31
|
} |
|
32
|
|
|
33
|
return ( |
|
34
|
<ContentMenuSection |
|
35
|
title="Shortcuts" |
|
36
|
hideChildrenDivider={ |
|
37
|
!contentMenuSections?.products && !contentMenuSections?.whatsNew |
|
38
|
} |
|
39
|
> |
|
40
|
<div className="flex flex-col gap-docs_0.5 p-docs_1"> |
|
41
|
<Link |
|
42
|
className="flex items-center gap-docs_0.5 text-medusa-fg-subtle text-x-small-plus hover:text-medusa-fg-base" |
|
43
|
href={`${pageUrl}/index.html.md`} |
|
44
|
data-testid="markdown-link" |
|
45
|
> |
|
46
|
<MarkdownSolid width={15} height={15} /> |
|
47
|
View as Markdown |
|
48
|
</Link> |
|
49
|
{features?.aiAssistant && ( |
|
50
|
<button |
|
51
|
className="appearance-none p-0 flex items-center gap-docs_0.5 text-medusa-fg-subtle text-x-small-plus hover:text-medusa-fg-base" |
|
52
|
onClick={handleAiAssistantClick} |
|
53
|
data-testid="ai-assistant-button" |
|
54
|
> |
|
55
|
<BroomSparkle width={15} height={15} /> |
|
56
|
Explain this page |
|
57
|
</button> |
|
58
|
)} |
|
59
|
</div> |
|
60
|
</ContentMenuSection> |
|
61
|
) |
|
62
|
} |