Kirjava
commited on
fix: issue with generating a new url id every time (#18)
Browse files
packages/bolt/app/components/chat/Chat.client.tsx
CHANGED
@@ -63,7 +63,10 @@ export function ChatImpl({ initialMessages, storeMessageHistory }: ChatProps) {
|
|
63 |
|
64 |
useEffect(() => {
|
65 |
parseMessages(messages, isLoading);
|
66 |
-
|
|
|
|
|
|
|
67 |
}, [messages, isLoading, parseMessages]);
|
68 |
|
69 |
const scrollTextArea = () => {
|
|
|
63 |
|
64 |
useEffect(() => {
|
65 |
parseMessages(messages, isLoading);
|
66 |
+
|
67 |
+
if (messages.length > initialMessages.length) {
|
68 |
+
storeMessageHistory(messages).catch((error) => toast.error(error.message));
|
69 |
+
}
|
70 |
}, [messages, isLoading, parseMessages]);
|
71 |
|
72 |
const scrollTextArea = () => {
|
packages/bolt/app/lib/persistence/useChatHistory.ts
CHANGED
@@ -14,12 +14,13 @@ export interface ChatHistory {
|
|
14 |
|
15 |
const persistenceEnabled = !import.meta.env.VITE_DISABLE_PERSISTENCE;
|
16 |
|
17 |
-
const db = persistenceEnabled ? await openDatabase() : undefined;
|
18 |
|
19 |
export function useChatHistory() {
|
20 |
const navigate = useNavigate();
|
21 |
-
const { id:
|
22 |
|
|
|
23 |
const [initialMessages, setInitialMessages] = useState<Message[]>([]);
|
24 |
const [ready, setReady] = useState<boolean>(false);
|
25 |
const [entryId, setEntryId] = useState<string | undefined>();
|
@@ -42,6 +43,9 @@ export function useChatHistory() {
|
|
42 |
.then((storedMessages) => {
|
43 |
if (storedMessages && storedMessages.messages.length > 0) {
|
44 |
setInitialMessages(storedMessages.messages);
|
|
|
|
|
|
|
45 |
} else {
|
46 |
navigate(`/`, { replace: true });
|
47 |
}
|
|
|
14 |
|
15 |
const persistenceEnabled = !import.meta.env.VITE_DISABLE_PERSISTENCE;
|
16 |
|
17 |
+
export const db = persistenceEnabled ? await openDatabase() : undefined;
|
18 |
|
19 |
export function useChatHistory() {
|
20 |
const navigate = useNavigate();
|
21 |
+
const { id: mixedId } = useLoaderData<{ id?: string }>();
|
22 |
|
23 |
+
const [chatId, setChatId] = useState(mixedId);
|
24 |
const [initialMessages, setInitialMessages] = useState<Message[]>([]);
|
25 |
const [ready, setReady] = useState<boolean>(false);
|
26 |
const [entryId, setEntryId] = useState<string | undefined>();
|
|
|
43 |
.then((storedMessages) => {
|
44 |
if (storedMessages && storedMessages.messages.length > 0) {
|
45 |
setInitialMessages(storedMessages.messages);
|
46 |
+
setUrlId(storedMessages.urlId);
|
47 |
+
setDescription(storedMessages.description);
|
48 |
+
setChatId(storedMessages.id);
|
49 |
} else {
|
50 |
navigate(`/`, { replace: true });
|
51 |
}
|