mirror of
https://github.com/coaidev/coai.git
synced 2025-05-20 13:30:13 +09:00
fix file double click and file format
This commit is contained in:
parent
f0eacf2aba
commit
bd959d89db
@ -16,10 +16,21 @@ type MarkdownProps = {
|
|||||||
|
|
||||||
function Markdown({ children, className }: MarkdownProps) {
|
function Markdown({ children, className }: MarkdownProps) {
|
||||||
useEffect(() => {
|
useEffect(() => {
|
||||||
document.querySelectorAll(".file-instance").forEach((e) => {
|
document.querySelectorAll(".file-instance").forEach((el) => {
|
||||||
e.addEventListener("click", () => {
|
el.removeEventListener("click", () => {});
|
||||||
const filename = e.getAttribute("file") as string;
|
el.addEventListener("click", (e) => {
|
||||||
const data = e.getAttribute("content") as string;
|
e.preventDefault();
|
||||||
|
e.stopPropagation();
|
||||||
|
// prevent double click
|
||||||
|
// @ts-ignore
|
||||||
|
if (window.hasOwnProperty("file") && window.file + 250 > new Date().getTime()) {
|
||||||
|
return;
|
||||||
|
} else {
|
||||||
|
// @ts-ignore
|
||||||
|
window.file = new Date().getTime();
|
||||||
|
}
|
||||||
|
const filename = el.getAttribute("file") as string;
|
||||||
|
const data = el.getAttribute("content") as string;
|
||||||
if (data) {
|
if (data) {
|
||||||
saveAsFile(filename, data);
|
saveAsFile(filename, data);
|
||||||
}
|
}
|
||||||
|
@ -14,7 +14,7 @@ import {
|
|||||||
ContextMenuItem,
|
ContextMenuItem,
|
||||||
ContextMenuTrigger,
|
ContextMenuTrigger,
|
||||||
} from "./ui/context-menu.tsx";
|
} from "./ui/context-menu.tsx";
|
||||||
import { copyClipboard, saveAsFile, useInputValue } from "../utils.ts";
|
import {copyClipboard, filterMessage, saveAsFile, useInputValue} from "../utils.ts";
|
||||||
import { useTranslation } from "react-i18next";
|
import { useTranslation } from "react-i18next";
|
||||||
import {
|
import {
|
||||||
Tooltip,
|
Tooltip,
|
||||||
@ -56,18 +56,18 @@ function MessageSegment({ message }: MessageProps) {
|
|||||||
</div>
|
</div>
|
||||||
</ContextMenuTrigger>
|
</ContextMenuTrigger>
|
||||||
<ContextMenuContent>
|
<ContextMenuContent>
|
||||||
<ContextMenuItem onClick={() => copyClipboard(message.content)}>
|
<ContextMenuItem onClick={() => copyClipboard(filterMessage(message.content))}>
|
||||||
<Copy className={`h-4 w-4 mr-2`} /> {t("message.copy")}
|
<Copy className={`h-4 w-4 mr-2`} /> {t("message.copy")}
|
||||||
</ContextMenuItem>
|
</ContextMenuItem>
|
||||||
<ContextMenuItem
|
<ContextMenuItem
|
||||||
onClick={() =>
|
onClick={() =>
|
||||||
saveAsFile(`message-${message.role}.txt`, message.content)
|
saveAsFile(`message-${message.role}.txt`, filterMessage(message.content))
|
||||||
}
|
}
|
||||||
>
|
>
|
||||||
<File className={`h-4 w-4 mr-2`} /> {t("message.save")}
|
<File className={`h-4 w-4 mr-2`} /> {t("message.save")}
|
||||||
</ContextMenuItem>
|
</ContextMenuItem>
|
||||||
<ContextMenuItem
|
<ContextMenuItem
|
||||||
onClick={() => useInputValue("input", message.content)}
|
onClick={() => useInputValue("input", filterMessage(message.content))}
|
||||||
>
|
>
|
||||||
<MousePointerSquare className={`h-4 w-4 mr-2`} /> {t("message.use")}
|
<MousePointerSquare className={`h-4 w-4 mr-2`} /> {t("message.use")}
|
||||||
</ContextMenuItem>
|
</ContextMenuItem>
|
||||||
|
@ -30,7 +30,7 @@ import {
|
|||||||
updateConversationList,
|
updateConversationList,
|
||||||
} from "../conversation/history.ts";
|
} from "../conversation/history.ts";
|
||||||
import React, { useEffect, useRef, useState } from "react";
|
import React, { useEffect, useRef, useState } from "react";
|
||||||
import {formatMessage, mobile, useAnimation, useEffectAsync} from "../utils.ts";
|
import {filterMessage, formatMessage, mobile, useAnimation, useEffectAsync} from "../utils.ts";
|
||||||
import { useToast } from "../components/ui/use-toast.ts";
|
import { useToast } from "../components/ui/use-toast.ts";
|
||||||
import { ConversationInstance, Message } from "../conversation/types.ts";
|
import { ConversationInstance, Message } from "../conversation/types.ts";
|
||||||
import {
|
import {
|
||||||
@ -122,7 +122,7 @@ function SideBar() {
|
|||||||
}}
|
}}
|
||||||
>
|
>
|
||||||
<MessageSquare className={`h-4 w-4 mr-1`} />
|
<MessageSquare className={`h-4 w-4 mr-1`} />
|
||||||
<div className={`title`}>{conversation.name}</div>
|
<div className={`title`}>{filterMessage(conversation.name)}</div>
|
||||||
<div className={`id`}>{conversation.id}</div>
|
<div className={`id`}>{conversation.id}</div>
|
||||||
<AlertDialog>
|
<AlertDialog>
|
||||||
<AlertDialogTrigger asChild>
|
<AlertDialogTrigger asChild>
|
||||||
@ -136,7 +136,7 @@ function SideBar() {
|
|||||||
<AlertDialogDescription>
|
<AlertDialogDescription>
|
||||||
{t("conversation.remove-description")}
|
{t("conversation.remove-description")}
|
||||||
<strong className={`conversation-name`}>
|
<strong className={`conversation-name`}>
|
||||||
{conversation.name}
|
{filterMessage(conversation.name)}
|
||||||
</strong>
|
</strong>
|
||||||
{t("end")}
|
{t("end")}
|
||||||
</AlertDialogDescription>
|
</AlertDialogDescription>
|
||||||
|
@ -157,6 +157,21 @@ ${message}`;
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
export function filterMessage(message: string): string {
|
||||||
|
/**
|
||||||
|
* remove file block
|
||||||
|
* :::file
|
||||||
|
* [[<filename>]]
|
||||||
|
* <file content>
|
||||||
|
* :::
|
||||||
|
*/
|
||||||
|
|
||||||
|
return message.replace(
|
||||||
|
/:::file\n\[\[.*]]\n[\s\S]*?\n:::\n\n/g,
|
||||||
|
"",
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
export function useDraggableInput(
|
export function useDraggableInput(
|
||||||
t: any,
|
t: any,
|
||||||
toast: any,
|
toast: any,
|
||||||
|
Loading…
Reference in New Issue
Block a user