diff --git a/drb-frontend/app/trips/[id]/page.tsx b/drb-frontend/app/trips/[id]/page.tsx index fc754f5..d2f8505 100644 --- a/drb-frontend/app/trips/[id]/page.tsx +++ b/drb-frontend/app/trips/[id]/page.tsx @@ -497,6 +497,8 @@ interface SuggestionCard { added?: boolean; } +const CHAT_STORAGE_KEY = (tripId: string) => `drb-trip-chat-${tripId}`; + function AssistantPanel({ trip, onAddEvent, @@ -504,15 +506,26 @@ function AssistantPanel({ trip: TripRecord & { events: TripEvent[] }; onAddEvent: (event: TripEvent) => void; }) { - const [messages, setMessages] = useState([]); + const storageKey = CHAT_STORAGE_KEY(trip.trip_id); + const [messages, setMessages] = useState(() => { + try { + const saved = localStorage.getItem(storageKey); + return saved ? JSON.parse(saved) : []; + } catch { return []; } + }); const [input, setInput] = useState(""); const [loading, setLoading] = useState(false); - const bottomRef = useRef(null); + const bottomRef = useRef(null); + const inputRef = useRef(null); useEffect(() => { bottomRef.current?.scrollIntoView({ behavior: "smooth" }); }, [messages]); + useEffect(() => { + try { localStorage.setItem(storageKey, JSON.stringify(messages)); } catch { /* quota */ } + }, [messages, storageKey]); + async function send() { const text = input.trim(); if (!text || loading) return; @@ -540,6 +553,7 @@ function AssistantPanel({ ]); } finally { setLoading(false); + inputRef.current?.focus(); } } @@ -703,6 +717,7 @@ function AssistantPanel({