From 24e209b5925099fbeddbad49f34f71fbf20460a7 Mon Sep 17 00:00:00 2001 From: Nick Savage Date: Mon, 25 Nov 2024 06:49:11 -0500 Subject: [PATCH] frontend: working on chat page --- .../src/assets/icons/StopIcon.tsx | 16 +++++ zettelkasten-front/src/components/Sidebar.tsx | 2 +- .../src/components/chat/AssistantMessage.tsx | 19 ++++++ .../src/components/chat/ChatPage.tsx | 61 +++++++++++++++++++ .../src/components/chat/UserMessage.tsx | 15 +++++ zettelkasten-front/src/pages/MainApp.tsx | 3 +- 6 files changed, 114 insertions(+), 2 deletions(-) create mode 100644 zettelkasten-front/src/assets/icons/StopIcon.tsx create mode 100644 zettelkasten-front/src/components/chat/AssistantMessage.tsx create mode 100644 zettelkasten-front/src/components/chat/ChatPage.tsx create mode 100644 zettelkasten-front/src/components/chat/UserMessage.tsx diff --git a/zettelkasten-front/src/assets/icons/StopIcon.tsx b/zettelkasten-front/src/assets/icons/StopIcon.tsx new file mode 100644 index 0000000..2ab44fe --- /dev/null +++ b/zettelkasten-front/src/assets/icons/StopIcon.tsx @@ -0,0 +1,16 @@ +import React from "react"; + +export function StopIcon() { + return ( + + + + ); +} diff --git a/zettelkasten-front/src/components/Sidebar.tsx b/zettelkasten-front/src/components/Sidebar.tsx index 432edce..0409cf1 100644 --- a/zettelkasten-front/src/components/Sidebar.tsx +++ b/zettelkasten-front/src/components/Sidebar.tsx @@ -175,7 +175,7 @@ export function Sidebar() { /> {import.meta.env.VITE_FEATURE_CHAT === "true" ? ( diff --git a/zettelkasten-front/src/components/chat/AssistantMessage.tsx b/zettelkasten-front/src/components/chat/AssistantMessage.tsx new file mode 100644 index 0000000..c878ca1 --- /dev/null +++ b/zettelkasten-front/src/components/chat/AssistantMessage.tsx @@ -0,0 +1,19 @@ +import React from "react"; + +interface AssistantMessageProps { + message: string; +} +export function AssistantMessage({ message }: AssistantMessageProps) { + return ( +
+
+
+

Zettelgarden

+
+
+ {message} +
+
+
+ ); +} diff --git a/zettelkasten-front/src/components/chat/ChatPage.tsx b/zettelkasten-front/src/components/chat/ChatPage.tsx new file mode 100644 index 0000000..4e8b7eb --- /dev/null +++ b/zettelkasten-front/src/components/chat/ChatPage.tsx @@ -0,0 +1,61 @@ +import React, { useState, useEffect, KeyboardEvent, ChangeEvent } from "react"; +import { StopIcon } from "../../assets/icons/StopIcon"; + +import { AssistantMessage } from "./AssistantMessage"; +import { UserMessage } from "./UserMessage"; + +interface ChatPageProps {} + +export function ChatPage({}: ChatPageProps) { + const [query, setQuery] = useState(""); + const [isLoading, setIsLoading] = useState(false); + + function handleSearchUpdate(e: ChangeEvent) { + setQuery(e.target.value); + } + function handleQuery() { + setIsLoading(true); + } + + function handleStop() {} + + return ( +
+ + +
+ + ) => { + if (event.key === "Enter") { + handleQuery(); + } + }} + /> + {isLoading && ( + + )} +
+
+ ); +} diff --git a/zettelkasten-front/src/components/chat/UserMessage.tsx b/zettelkasten-front/src/components/chat/UserMessage.tsx new file mode 100644 index 0000000..ea962f2 --- /dev/null +++ b/zettelkasten-front/src/components/chat/UserMessage.tsx @@ -0,0 +1,15 @@ +import React from "react"; + +interface UserMessageProps { + message: string; +} + +export function UserMessage({ message }: UserMessageProps) { + return ( +
+
+

{message}

+
+
+ ); +} diff --git a/zettelkasten-front/src/pages/MainApp.tsx b/zettelkasten-front/src/pages/MainApp.tsx index 9be222f..a9e8a30 100644 --- a/zettelkasten-front/src/pages/MainApp.tsx +++ b/zettelkasten-front/src/pages/MainApp.tsx @@ -14,7 +14,7 @@ import { BillingSuccess } from "./BillingSuccess"; import { BillingCancelled } from "./BillingCancelled"; import { SubscriptionPage } from "./SubscriptionPage"; import { DashboardPage } from "./DashboardPage"; -import { FlashcardNextPage } from "./flashcards/FlashcardNextPage"; +import { ChatPage } from "../components/chat/ChatPage"; import { Card, PartialCard } from "../models/Card"; import { TaskPage } from "./tasks/TaskPage"; @@ -103,6 +103,7 @@ function MainAppContent() { } /> } /> } /> + } /> } /> ) : (