diff --git a/frontend/src/components/Chat/FlashCards.tsx b/frontend/src/components/Chat/FlashCards.tsx index a2d2aab7..b60b1f42 100755 --- a/frontend/src/components/Chat/FlashCards.tsx +++ b/frontend/src/components/Chat/FlashCards.tsx @@ -3,16 +3,33 @@ import type { FlashCard } from "../../lib/api"; type Props = { items?: FlashCard[]; onAdd: (item: { kind: "flashcard" | "note"; title: string; content: string }) => void; + onToggleCollapse?: () => void; }; -export default function FlashCards({ items = [], onAdd }: Props) { +export default function FlashCards({ items = [], onAdd, onToggleCollapse }: Props) { return ( -
+
{children}
);
}
return (
-
+
{children}
@@ -48,7 +48,7 @@ const components: Components = {
export default function MarkdownView({ md }: Props) {
return (
-
+
(null);
+ // Fetch chats only when the drawer is opened to avoid redundant requests on mount
useEffect(() => {
- getChats().then(data => setChats(data));
- }, []);
+ if (isToggled) {
+ getChats().then(data => setChats(data));
+ }
+ }, [isToggled]);
+
+ // Dismiss drawer on Escape key press
+ useEffect(() => {
+ const onKeyDown = (e: KeyboardEvent) => {
+ if (e.key === 'Escape' && isToggled) {
+ setIsToggled(false);
+ }
+ };
+ window.addEventListener('keydown', onKeyDown);
+ return () => window.removeEventListener('keydown', onKeyDown);
+ }, [isToggled]);
const b = (t: string) => `p-2 rounded-xl duration-300 transition-all ${p === t ? 'text-white bg-stone-800' : 'hover:bg-stone-900 hover:text-stone-200'}`
const chatButtonClass = `p-2 rounded-xl duration-300 transition-all ${isToggled ? 'text-white bg-stone-800' : 'hover:bg-stone-900 hover:text-stone-200'}`
- function toggleC() {
- const idk = document.getElementById("idk")
- idk?.classList.toggle("flex");
- idk?.classList.toggle("hidden");
- document.getElementById("idk0")?.classList.toggle("md:rounded-r-none")
- setIsToggled(!isToggled)
- }
return (
-