fix: issue with generating a new url id every time (#18)

This commit is contained in:
Kirjava 2024-07-29 16:36:21 +01:00 committed by GitHub
parent a9036a1030
commit b8a197ed16
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
2 changed files with 10 additions and 3 deletions

View File

@ -63,7 +63,10 @@ export function ChatImpl({ initialMessages, storeMessageHistory }: ChatProps) {
useEffect(() => { useEffect(() => {
parseMessages(messages, isLoading); parseMessages(messages, isLoading);
if (messages.length > initialMessages.length) {
storeMessageHistory(messages).catch((error) => toast.error(error.message)); storeMessageHistory(messages).catch((error) => toast.error(error.message));
}
}, [messages, isLoading, parseMessages]); }, [messages, isLoading, parseMessages]);
const scrollTextArea = () => { const scrollTextArea = () => {

View File

@ -14,12 +14,13 @@ export interface ChatHistory {
const persistenceEnabled = !import.meta.env.VITE_DISABLE_PERSISTENCE; const persistenceEnabled = !import.meta.env.VITE_DISABLE_PERSISTENCE;
const db = persistenceEnabled ? await openDatabase() : undefined; export const db = persistenceEnabled ? await openDatabase() : undefined;
export function useChatHistory() { export function useChatHistory() {
const navigate = useNavigate(); const navigate = useNavigate();
const { id: chatId } = useLoaderData<{ id?: string }>(); const { id: mixedId } = useLoaderData<{ id?: string }>();
const [chatId, setChatId] = useState(mixedId);
const [initialMessages, setInitialMessages] = useState<Message[]>([]); const [initialMessages, setInitialMessages] = useState<Message[]>([]);
const [ready, setReady] = useState<boolean>(false); const [ready, setReady] = useState<boolean>(false);
const [entryId, setEntryId] = useState<string | undefined>(); const [entryId, setEntryId] = useState<string | undefined>();
@ -42,6 +43,9 @@ export function useChatHistory() {
.then((storedMessages) => { .then((storedMessages) => {
if (storedMessages && storedMessages.messages.length > 0) { if (storedMessages && storedMessages.messages.length > 0) {
setInitialMessages(storedMessages.messages); setInitialMessages(storedMessages.messages);
setUrlId(storedMessages.urlId);
setDescription(storedMessages.description);
setChatId(storedMessages.id);
} else { } else {
navigate(`/`, { replace: true }); navigate(`/`, { replace: true });
} }