Skip to content

Commit b684d20

Browse files
committed
feat: 增加 share link
1 parent 1ed0ffa commit b684d20

File tree

6 files changed

+132
-18
lines changed

6 files changed

+132
-18
lines changed

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
{
22
"name": "cc-editor",
33
"private": true,
4-
"version": "1.0.5",
4+
"version": "1.0.6",
55
"type": "module",
66
"scripts": {
77
"dev": "vite",

src/components/StartPanel/StartPanel.tsx

Lines changed: 107 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,22 @@
11
import {
22
Button,
3+
Dialog,
4+
DialogActions,
5+
DialogBody,
6+
DialogContent,
7+
DialogSurface,
8+
DialogTitle,
9+
DialogTrigger,
310
Field,
411
Input,
512
Spinner,
613
Text,
14+
Textarea,
715
tokens,
816
} from "@fluentui/react-components";
917
import { useStyles } from "../useStyles";
1018
import { useI18n } from "../../tools/i18n";
11-
import { useCallback, useState } from "react";
19+
import { useCallback, useEffect, useRef, useState } from "react";
1220
import { useGlobalDrop } from "../useGlobalDrop";
1321
import { CharacterCard } from "@lenml/char-card-reader";
1422
import { useGlobalPaste } from "../useGlobalPaste";
@@ -55,6 +63,8 @@ export const StartPanel = ({
5563
const [dragHighlight, setDragHighlight] = useState(false);
5664
const [isLoading, setIsLoading] = useState(false);
5765
const [loadFromUrl, setLoadFromUrl] = useState("");
66+
const loadFromUrlRef = useRef(loadFromUrl);
67+
loadFromUrlRef.current = loadFromUrl;
5868

5969
const handleFileCard = useCallback(
6070
async (getCard: () => Promise<CharacterCard>) => {
@@ -160,11 +170,34 @@ export const StartPanel = ({
160170
const handleLoadFromUrl = useCallback(async () => {
161171
// 下载文件
162172
await handleFileCard(async () => {
163-
const response = await fetch(getRawImageUrl(loadFromUrl));
173+
const response = await fetch(getRawImageUrl(loadFromUrlRef.current));
164174
const arrayBuffer = await response.arrayBuffer();
165175
return CharacterCard.from_file(arrayBuffer);
166176
});
167-
}, [loadFromUrl]);
177+
}, []);
178+
179+
useEffect(() => {
180+
// 从 ?load_url=xxx 读取
181+
const urlParams = new URLSearchParams(window.location.search);
182+
const loadFromUrl = urlParams.get("load_url");
183+
if (loadFromUrl) {
184+
setLoadFromUrl(decodeURIComponent(loadFromUrl));
185+
loadFromUrlRef.current = decodeURIComponent(loadFromUrl);
186+
handleLoadFromUrl();
187+
// 删除路径中的 url
188+
urlParams.delete("load_url");
189+
history.replaceState(
190+
null,
191+
"",
192+
`${window.location.pathname}?${urlParams.toString()}`
193+
);
194+
}
195+
}, [handleLoadFromUrl]);
196+
197+
const [shareModal, updateShareModal] = useState({
198+
open: false,
199+
url: "",
200+
});
168201

169202
return (
170203
<div
@@ -252,22 +285,87 @@ export const StartPanel = ({
252285
<div style={{ width: "40vw" }}>
253286
<Field label={"3. " + t("Load image from url")}>
254287
<Input
288+
type="url"
255289
placeholder="https://example.com/avatar.png"
256290
onChange={(e) => {
257291
const avatarUrl = e.target.value;
258292
setLoadFromUrl(avatarUrl);
259293
}}
294+
onKeyDown={(e) => {
295+
if (e.key === "Enter") {
296+
handleLoadFromUrl();
297+
}
298+
}}
260299
contentAfter={
261-
<Button
262-
appearance="transparent"
263-
size="small"
264-
onClick={handleLoadFromUrl}
300+
<span
301+
style={{
302+
display: loadFromUrl ? "inline-block" : "none",
303+
}}
265304
>
266-
{t("Load")}
267-
</Button>
305+
<Button
306+
style={{ minWidth: 0, padding: 0, paddingLeft: "0.5rem" }}
307+
appearance="transparent"
308+
size="small"
309+
onClick={() => {
310+
const urlObj = new URL(window.location.href);
311+
urlObj.searchParams.set("load_url", loadFromUrl);
312+
updateShareModal({
313+
open: true,
314+
url: urlObj.href,
315+
});
316+
}}
317+
>
318+
{t("Share")}
319+
</Button>
320+
<Button
321+
style={{ minWidth: 0, padding: 0, paddingLeft: "0.5rem" }}
322+
appearance="transparent"
323+
size="small"
324+
onClick={handleLoadFromUrl}
325+
>
326+
{t("Load")}
327+
</Button>
328+
</span>
268329
}
269330
/>
270331
</Field>
332+
333+
<Dialog
334+
open={shareModal.open}
335+
onOpenChange={(_: any, data: { open: any }) =>
336+
updateShareModal((prev) => ({ ...prev, open: data.open }))
337+
}
338+
>
339+
<DialogSurface>
340+
<DialogBody>
341+
<DialogTitle>{t("Share Link")}</DialogTitle>
342+
<DialogContent>
343+
<p className="mb-3">
344+
{t(
345+
// 你可以使用下面的链接分享你的卡片,你的朋友点击之后就可以到达此工具的编辑页面
346+
"You can share the link to edit this card, your friend can click it to reach this tool's edit page"
347+
)}
348+
</p>
349+
<Textarea
350+
className="w-full"
351+
readOnly
352+
rows={10}
353+
value={shareModal.url}
354+
/>
355+
</DialogContent>
356+
<DialogActions>
357+
<DialogTrigger disableButtonEnhancement>
358+
<Button
359+
appearance="primary"
360+
onClick={() => updateShareModal({ open: false, url: "" })}
361+
>
362+
{t("Ok")}
363+
</Button>
364+
</DialogTrigger>
365+
</DialogActions>
366+
</DialogBody>
367+
</DialogSurface>
368+
</Dialog>
271369
</div>
272370

273371
{/* Option 3: 复制粘贴文件 */}

src/locals/en.json

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -56,7 +56,7 @@
5656
"word_count": "{{chars}} Chars | {{tokens}} Token",
5757
"OR": "OR",
5858
"Tool": "Tool",
59-
"Apply Template": "Apply Template",
59+
"Test Template": "Test Template",
6060
"User Name": "User Name",
6161
"Assistant Name": "Assistant Name",
6262
"Generate": "Generate",
@@ -181,5 +181,9 @@
181181
"Load image from url": "Load image from url",
182182
"Load": "Load",
183183
"Copy/Paste character card current page will auto detect": "Copy/Paste character card current page will auto detect",
184-
"Are you sure you want to delete this entry?": "Are you sure you want to delete this entry?"
184+
"Are you sure you want to delete this entry?": "Are you sure you want to delete this entry?",
185+
"Share": "Share",
186+
"Share Link": "Share Link",
187+
"You can share the link to edit this card, your friend can click it to reach this tool's edit page": "You can share the link to edit this card, your friend can click it to reach this tool's edit page",
188+
"Ok": "Ok"
185189
}

src/locals/ja.json

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -68,7 +68,7 @@
6868
"word_count": "{{chars}} 文字 | {{tokens}} Token",
6969
"OR": "または",
7070
"Tool": "ツール",
71-
"Apply Template": "テンプレートを適用",
71+
"Test Template": "テストテンプレート",
7272
"User Name": "ユーザー名",
7373
"Assistant Name": "アシスタント名",
7474
"Generate": "生成",
@@ -193,5 +193,9 @@
193193
"Load image from url": "Load image from url",
194194
"Load": "Load",
195195
"Copy/Paste character card current page will auto detect": "Copy/Paste character card current page will auto detect",
196-
"Are you sure you want to delete this entry?": "Are you sure you want to delete this entry?"
196+
"Are you sure you want to delete this entry?": "Are you sure you want to delete this entry?",
197+
"Share": "Share",
198+
"Share Link": "Share Link",
199+
"You can share the link to edit this card, your friend can click it to reach this tool's edit page": "You can share the link to edit this card, your friend can click it to reach this tool's edit page",
200+
"Ok": "Ok"
197201
}

src/locals/ko.json

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -68,7 +68,7 @@
6868
"word_count": "{{chars}} 문자 | {{tokens}} Token",
6969
"OR": "또는",
7070
"Tool": "도구",
71-
"Apply Template": "템플릿 적용",
71+
"Test Template": "테스트 템플릿",
7272
"User Name": "사용자 이름",
7373
"Assistant Name": "어시스턴트 이름",
7474
"Generate": "생성",
@@ -193,5 +193,9 @@
193193
"Load image from url": "Load image from url",
194194
"Load": "Load",
195195
"Copy/Paste character card current page will auto detect": "Copy/Paste character card current page will auto detect",
196-
"Are you sure you want to delete this entry?": "Are you sure you want to delete this entry?"
196+
"Are you sure you want to delete this entry?": "Are you sure you want to delete this entry?",
197+
"Share": "Share",
198+
"Share Link": "Share Link",
199+
"You can share the link to edit this card, your friend can click it to reach this tool's edit page": "You can share the link to edit this card, your friend can click it to reach this tool's edit page",
200+
"Ok": "Ok"
197201
}

src/locals/zh.json

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -70,7 +70,7 @@
7070
"Input or select tags": "输入或者选择Tag",
7171
"Expand": "展开",
7272
"Collapse": "收起",
73-
"Apply Template": "应用模板",
73+
"Test Template": "测试模板",
7474
"Generate": "生成",
7575
"Output Result": "输出结果",
7676
"Tool": "工具",
@@ -193,5 +193,9 @@
193193
"Load image from url": "从url加载图片",
194194
"Load": "加载",
195195
"Copy/Paste character card current page will auto detect": "复制/粘贴角色卡当前页面将自动检测",
196-
"Are you sure you want to delete this entry?": "您确定要删除此条目吗?"
196+
"Are you sure you want to delete this entry?": "您确定要删除此条目吗?",
197+
"Share": "分享",
198+
"Share Link": "分享链接",
199+
"You can share the link to edit this card, your friend can click it to reach this tool's edit page": "您可以分享编辑此卡的链接,您的朋友可以点击它到达此工具的编辑页面",
200+
"Ok": "好的"
197201
}

0 commit comments

Comments
 (0)