Skip to content

Commit

Permalink
update chat
Browse files Browse the repository at this point in the history
  • Loading branch information
an-lee committed Aug 7, 2024
1 parent a660d36 commit 4a0fc6c
Show file tree
Hide file tree
Showing 3 changed files with 24 additions and 6 deletions.
2 changes: 1 addition & 1 deletion enjoy/src/main/db/handlers/chat-sessions-handler.ts
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ class ChatSessionsHandler {
};
}
const chatSessions = await ChatSession.findAll({
order: [["updatedAt", "DESC"]],
order: [["createdAt", "ASC"]],
where,
...options,
});
Expand Down
16 changes: 12 additions & 4 deletions enjoy/src/renderer/components/chats/chat-session.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ import {
import { MarkdownWrapper, WavesurferPlayer } from "@renderer/components";
import { formatDateTime } from "@renderer/lib/utils";
import { t } from "i18next";
import { MicIcon } from "lucide-react";

export const ChatSession = (props: { chatSession: ChatSessionType }) => {
const {
Expand Down Expand Up @@ -72,10 +73,17 @@ export const ChatMessage = (props: { chatMessage: ChatMessageType }) => {
{chatMessage.content}
</MarkdownWrapper>
{chatMessage.state === "pending" && (
<div className="w-full flex items-center justify-end space-x-4">
<Button variant="secondary">{t("refine")}</Button>
<Button variant="secondary">{t("reRecord")}</Button>
<Button variant="default">{t("confirm")}</Button>
<div className="w-full flex items-center justify-end space-x-2">
<Button size="sm" variant="secondary">
{t("refine")}
</Button>
<Button size="sm" variant="secondary">
<MicIcon className="w-4 h-4 mr-2" />
{t("reRecord")}
</Button>
<Button size="sm" variant="default">
{t("confirm")}
</Button>
</div>
)}
</div>
Expand Down
12 changes: 11 additions & 1 deletion enjoy/src/renderer/components/chats/chat.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,8 @@ export const Chat = () => {
chatSessionsReducer,
[]
);
const [currentSession, setCurrentSession] =
useState<ChatSessionType | null>();

const askForMediaAccess = () => {
EnjoyApp.system.preferences.mediaAccess("microphone").then((access) => {
Expand All @@ -51,7 +53,6 @@ export const Chat = () => {

const fetchChatSessions = async (chatId: string) => {
EnjoyApp.chatSessions.findAll({ where: { chatId } }).then((data) => {
console.log(data);
dispatchChatSessions({ type: "set", records: data });
});
};
Expand Down Expand Up @@ -153,6 +154,14 @@ export const Chat = () => {
}
}, [recordingTime]);

useEffect(() => {
if (chatSessions.length) {
setCurrentSession(chatSessions[chatSessions.length - 1]);
} else {
setCurrentSession(null);
}
}, [chatSessions]);

if (!currentChat) {
return (
<div className="flex items-center justify-center h-screen">
Expand Down Expand Up @@ -245,6 +254,7 @@ export const Chat = () => {
<Button
onClick={startRecording}
className="rounded-full shadow w-10 h-10"
disabled={currentSession?.state === "pending"}
size="icon"
>
<MicIcon className="w-6 h-6" />
Expand Down

0 comments on commit 4a0fc6c

Please sign in to comment.