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(() => {
|
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 = () => {
|
||||||
|
@ -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 });
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user