diff --git a/enjoy/src/i18n/en.json b/enjoy/src/i18n/en.json index 35cd9d0b..8eae3080 100644 --- a/enjoy/src/i18n/en.json +++ b/enjoy/src/i18n/en.json @@ -335,5 +335,7 @@ "shareAudio": "Share audio", "areYouSureToShareThisAudioToCommunity": "Are you sure to share this audio to community?", "shareVideo": "Share video", - "areYouSureToShareThisVideoToCommunity": "Are you sure to share this video to community?" + "areYouSureToShareThisVideoToCommunity": "Are you sure to share this video to community?", + "sharePrompt": "Share prompt", + "areYouSureToShareThisPromptToCommunity": "Are you sure to share this prompt to community?" } diff --git a/enjoy/src/i18n/zh-CN.json b/enjoy/src/i18n/zh-CN.json index cf809eb7..7083abc6 100644 --- a/enjoy/src/i18n/zh-CN.json +++ b/enjoy/src/i18n/zh-CN.json @@ -335,5 +335,7 @@ "shareAudio": "分享音频", "areYouSureToShareThisAudioToCommunity": "您确定要分享此音频到社区吗?", "shareVideo": "分享视频", - "areYouSureToShareThisVideoToCommunity": "您确定要分享此视频到社区吗?" + "areYouSureToShareThisVideoToCommunity": "您确定要分享此视频到社区吗?", + "sharePrompt": "分享提示语", + "areYouSureToShareThisPromptToCommunity": "您确定要分享此提示语到社区吗?" } diff --git a/enjoy/src/main/db/models/transcription.ts b/enjoy/src/main/db/models/transcription.ts index 385b8fa4..29d1ce1d 100644 --- a/enjoy/src/main/db/models/transcription.ts +++ b/enjoy/src/main/db/models/transcription.ts @@ -157,7 +157,7 @@ export class Transcription extends Model { @AfterFind static expireProcessingState(transcription: Transcription) { - if (transcription.state !== "processing") return; + if (transcription?.state !== "processing") return; if (transcription.updatedAt.getTime() + PROCESS_TIMEOUT < Date.now()) { if (transcription.result) { diff --git a/enjoy/src/renderer/components/messages/assistant-message.tsx b/enjoy/src/renderer/components/messages/assistant-message.tsx index 59cca9c6..da61bbf9 100644 --- a/enjoy/src/renderer/components/messages/assistant-message.tsx +++ b/enjoy/src/renderer/components/messages/assistant-message.tsx @@ -94,14 +94,14 @@ export const AssistantMessageComponent = (props: { AI -
+
{configuration?.autoSpeech && speeching ? (
) : ( void; onRemove?: () => void; + onShare?: () => void; }) => { - const { message, configuration, onResend, onRemove } = props; + const { message, configuration, onResend, onRemove, onShare } = props; if (message.role === "assistant") { return ( ); } diff --git a/enjoy/src/renderer/components/messages/user-message.tsx b/enjoy/src/renderer/components/messages/user-message.tsx index c275687d..25ff3444 100644 --- a/enjoy/src/renderer/components/messages/user-message.tsx +++ b/enjoy/src/renderer/components/messages/user-message.tsx @@ -17,6 +17,7 @@ import { AlertCircleIcon, CopyIcon, CheckIcon, + Share2Icon, } from "lucide-react"; import { useCopyToClipboard } from "@uidotdev/usehooks"; import { t } from "i18next"; @@ -27,8 +28,9 @@ export const UserMessageComponent = (props: { configuration?: { [key: string]: any }; onResend?: () => void; onRemove?: () => void; + onShare?: () => void; }) => { - const { message, onResend, onRemove } = props; + const { message, onResend, onRemove, onShare } = props; const speech = message.speeches?.[0]; const { user } = useContext(AppSettingsProviderContext); const [_, copyToClipboard] = useCopyToClipboard(); @@ -41,7 +43,7 @@ export const UserMessageComponent = (props: { >
- {message.content} + {message.content} {Boolean(speech) && } @@ -81,6 +83,15 @@ export const UserMessageComponent = (props: { }} /> )} + + {message.createdAt && ( + + )}
diff --git a/enjoy/src/renderer/components/posts/posts.tsx b/enjoy/src/renderer/components/posts/posts.tsx index 86b62740..3d36c4ad 100644 --- a/enjoy/src/renderer/components/posts/posts.tsx +++ b/enjoy/src/renderer/components/posts/posts.tsx @@ -8,6 +8,7 @@ import { DefaultVideoLayout, defaultLayoutIcons, } from "@vidstack/react/player/layouts/default"; +import Markdown from "react-markdown"; export const Posts = () => { const { webApi } = useContext(AppSettingsProviderContext); @@ -16,7 +17,6 @@ export const Posts = () => { const fetchPosts = async () => { webApi.posts().then( (res) => { - console.log(res); setPosts(res.posts); }, (err) => { @@ -60,7 +60,9 @@ const PostCard = (props: { post: PostType }) => {
{post.user.name}
- {post.content &&
{post.content}
} + {post.content && ( + {post.content} + )} {post.targetType == "Medium" && } ); diff --git a/enjoy/src/renderer/pages/conversation.tsx b/enjoy/src/renderer/pages/conversation.tsx index 403ead35..61019c7d 100644 --- a/enjoy/src/renderer/pages/conversation.tsx +++ b/enjoy/src/renderer/pages/conversation.tsx @@ -1,5 +1,12 @@ import { useState, useEffect, useReducer, useContext, useRef } from "react"; import { + AlertDialog, + AlertDialogHeader, + AlertDialogDescription, + AlertDialogTitle, + AlertDialogContent, + AlertDialogFooter, + AlertDialogCancel, Button, ScrollArea, Textarea, @@ -8,11 +15,7 @@ import { SheetTrigger, useToast, } from "@renderer/components/ui"; -import { - MessageComponent, - ConversationForm, - SpeechForm, -} from "@renderer/components"; +import { MessageComponent, ConversationForm } from "@renderer/components"; import { SendIcon, BotIcon, LoaderIcon, SettingsIcon } from "lucide-react"; import { Link, useParams } from "react-router-dom"; import { t } from "i18next"; @@ -29,9 +32,11 @@ export default () => { const [editting, setEditting] = useState(false); const [conversation, setConversation] = useState(); const { addDblistener, removeDbListener } = useContext(DbProviderContext); - const { EnjoyApp } = useContext(AppSettingsProviderContext); + const { EnjoyApp, webApi } = useContext(AppSettingsProviderContext); const [content, setConent] = useState(""); const [submitting, setSubmitting] = useState(false); + const [sharing, setSharing] = useState(); + const { toast } = useToast(); const [messages, dispatchMessages] = useReducer(messagesReducer, []); @@ -169,6 +174,28 @@ export default () => { }, 500); }; + const handleShare = async (message: MessageType) => { + if (message.role === "user") { + const content = message.content; + webApi + .createPost({ + content, + }) + .then(() => { + toast({ + description: t("sharedSuccessfully"), + }); + }) + .catch((err) => { + toast({ + title: t("shareFailed"), + description: err.message, + }); + }); + setSharing(null); + } + }; + useEffect(() => { fetchConversation(); fetchMessages(); @@ -258,6 +285,7 @@ export default () => { dispatchMessages({ type: "destroy", record: message }); }} + onShare={() => setSharing(message)} /> ))} {offset > -1 && ( @@ -278,6 +306,26 @@ export default () => { + setSharing(null)} + > + + + {t("sharePrompt")} + + {t("areYouSureToShareThisPromptToCommunity")} + + + + {t("cancel")} + + + + +