mirror of
https://github.com/stackblitz/bolt.new
synced 2024-11-27 14:32:46 +00:00
fix: issue with generating a new url id every time (#18)
This commit is contained in:
parent
a9036a1030
commit
b8a197ed16
@ -63,7 +63,10 @@ export function ChatImpl({ initialMessages, storeMessageHistory }: ChatProps) {
|
||||
|
||||
useEffect(() => {
|
||||
parseMessages(messages, isLoading);
|
||||
|
||||
if (messages.length > initialMessages.length) {
|
||||
storeMessageHistory(messages).catch((error) => toast.error(error.message));
|
||||
}
|
||||
}, [messages, isLoading, parseMessages]);
|
||||
|
||||
const scrollTextArea = () => {
|
||||
|
@ -14,12 +14,13 @@ export interface ChatHistory {
|
||||
|
||||
const persistenceEnabled = !import.meta.env.VITE_DISABLE_PERSISTENCE;
|
||||
|
||||
const db = persistenceEnabled ? await openDatabase() : undefined;
|
||||
export const db = persistenceEnabled ? await openDatabase() : undefined;
|
||||
|
||||
export function useChatHistory() {
|
||||
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 [ready, setReady] = useState<boolean>(false);
|
||||
const [entryId, setEntryId] = useState<string | undefined>();
|
||||
@ -42,6 +43,9 @@ export function useChatHistory() {
|
||||
.then((storedMessages) => {
|
||||
if (storedMessages && storedMessages.messages.length > 0) {
|
||||
setInitialMessages(storedMessages.messages);
|
||||
setUrlId(storedMessages.urlId);
|
||||
setDescription(storedMessages.description);
|
||||
setChatId(storedMessages.id);
|
||||
} else {
|
||||
navigate(`/`, { replace: true });
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user