Fix CBT submission, add CBT seeds, update features table, layout AI coach chat and add local memory
This commit is contained in:
@@ -1,4 +1,4 @@
|
||||
"use client"
|
||||
"use client"
|
||||
|
||||
import { fetchWithAuth } from "@/lib/apiClient";
|
||||
import { useState, useRef, useEffect } from "react"
|
||||
@@ -33,6 +33,25 @@ export function TutorChat() {
|
||||
|
||||
const { userId, loading: userLoading } = useActiveUser();
|
||||
|
||||
// Load from localStorage on mount
|
||||
useEffect(() => {
|
||||
if (userId) {
|
||||
const saved = localStorage.getItem("ai_tutor_chat_" + userId)
|
||||
if (saved) {
|
||||
try {
|
||||
setMessages(JSON.parse(saved))
|
||||
} catch (e) {}
|
||||
}
|
||||
}
|
||||
}, [userId])
|
||||
|
||||
// Save to localStorage whenever messages change
|
||||
useEffect(() => {
|
||||
if (userId && messages.length > 1) { // Only save if there's actual history beyond initial message
|
||||
localStorage.setItem("ai_tutor_chat_" + userId, JSON.stringify(messages))
|
||||
}
|
||||
}, [messages, userId])
|
||||
|
||||
const scrollToBottom = () => {
|
||||
messagesEndRef.current?.scrollIntoView({ behavior: "smooth" })
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user