Skip to content

Commit 4c23db9

Browse files
committed
chore(dev-docs) requested comments
1 parent e358cbd commit 4c23db9

File tree

2 files changed

+29
-43
lines changed

2 files changed

+29
-43
lines changed

apps/developer-hub/src/components/PageActions/index.tsx

Lines changed: 28 additions & 40 deletions
Original file line numberDiff line numberDiff line change
@@ -14,14 +14,7 @@ type PageActionOption = {
1414
icon: ReactNode;
1515
url?: string;
1616
type: "copy" | "markdown" | "llm";
17-
ariaLabel?: string;
18-
};
19-
20-
type PageAction = {
21-
id: string;
22-
label: string;
23-
icon: ReactNode;
24-
onClick: () => void;
17+
llmProvider?: "openai" | "claude";
2518
ariaLabel?: string;
2619
};
2720

@@ -52,6 +45,7 @@ const getPageActionOptions = (): PageActionOption[] => [
5245
icon: <OpenAiLogo />,
5346
url: "https://chat.openai.com",
5447
type: "llm",
48+
llmProvider: "openai",
5549
ariaLabel: "Ask in ChatGPT",
5650
},
5751
{
@@ -60,6 +54,7 @@ const getPageActionOptions = (): PageActionOption[] => [
6054
icon: <ClaudeIcon />,
6155
url: "https://claude.ai",
6256
type: "llm",
57+
llmProvider: "claude",
6358
ariaLabel: "Ask in Claude",
6459
},
6560
];
@@ -92,65 +87,58 @@ export function PageActions({ content, title, url }: PageActionsProps) {
9287

9388
const encodedInstruction = encodeURIComponent(prompt);
9489
const shareUrl =
95-
option.label === "Ask in Claude"
90+
option.llmProvider === "claude"
9691
? `https://claude.ai/new?q=${encodedInstruction}`
9792
: `${option.url}?q=${encodedInstruction}`;
9893

9994
window.open(shareUrl, "_blank");
10095
}
10196
}
10297

103-
const actions: PageAction[] = pageActionOptions.map((option) => {
104-
let onClick: () => void;
105-
106-
if (option.type === "copy") {
107-
onClick = copy;
108-
} else if (option.type === "markdown") {
109-
onClick = handleViewMarkdown;
110-
} else {
111-
onClick = () => {
98+
function handleActionClick(option: PageActionOption) {
99+
switch (option.type) {
100+
case "copy": {
101+
copy();
102+
break;
103+
}
104+
case "markdown": {
105+
handleViewMarkdown();
106+
break;
107+
}
108+
case "llm": {
112109
handleShare(option);
113-
};
110+
break;
111+
}
114112
}
115-
116-
return {
117-
id: option.id,
118-
label: option.label,
119-
icon: option.icon,
120-
onClick,
121-
ariaLabel: option.ariaLabel ?? option.label,
122-
};
123-
});
113+
}
124114

125115
return (
126116
<div className={styles.wrapper}>
127117
<div className={styles.container}>
128-
{actions.map((action, index) => {
129-
const isLast = index === actions.length - 1;
130-
131-
const pageOption = pageActionOptions.find(
132-
(opt) => opt.id === action.id,
133-
);
134-
const isCopyAction = pageOption?.type === "copy";
118+
{pageActionOptions.map((option, index) => {
119+
const isLast = index === pageActionOptions.length - 1;
120+
const isCopyAction = option.type === "copy";
135121
const showCheckIcon = isCopyAction && isCopied;
136122

137123
return (
138-
<div key={action.id} className={styles.buttonWrapper}>
124+
<div key={option.id} className={styles.buttonWrapper}>
139125
<Button
140-
onPress={action.onClick}
126+
onPress={() => {
127+
handleActionClick(option);
128+
}}
141129
size="sm"
142130
variant="ghost"
143131
className={styles.button ?? ""}
144-
aria-label={action.ariaLabel ?? action.label}
132+
aria-label={option.ariaLabel ?? option.label}
145133
beforeIcon={
146134
showCheckIcon ? (
147135
<Check className={styles.icon ?? ""} />
148136
) : (
149-
action.icon
137+
option.icon
150138
)
151139
}
152140
>
153-
{action.label}
141+
{option.label}
154142
</Button>
155143
{!isLast && (
156144
<div className={styles.verticalDivider} aria-hidden="true" />

apps/developer-hub/src/lib/get-llm-text.ts

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -11,9 +11,7 @@ import remarkMdx from "remark-mdx";
1111
const processor = remark().use(remarkMdx).use(remarkInclude).use(remarkGfm);
1212

1313
function resolveMdxPath(page: Page): string {
14-
const parts: string[] = Array.isArray(page.path) ? page.path : [page.path];
15-
16-
const appRelPath = [process.cwd(), "content", "docs", ...parts] as [
14+
const appRelPath = [process.cwd(), "content", "docs", page.path] as [
1715
string,
1816
...string[],
1917
];

0 commit comments

Comments
 (0)