mirror of
https://github.com/NovaOSS/nova-betterchat.git
synced 2024-11-26 00:23:59 +01:00
handle edge cases
This commit is contained in:
parent
46642e24c2
commit
a2b3c5e884
|
@ -51,9 +51,16 @@ function App() {
|
||||||
} else {
|
} else {
|
||||||
// existing local storage
|
// existing local storage
|
||||||
const chats = useStore.getState().chats;
|
const chats = useStore.getState().chats;
|
||||||
|
const currentChatIndex = useStore.getState().currentChatIndex;
|
||||||
if (!chats || chats.length === 0) {
|
if (!chats || chats.length === 0) {
|
||||||
initialiseNewChat();
|
initialiseNewChat();
|
||||||
}
|
}
|
||||||
|
if (
|
||||||
|
chats &&
|
||||||
|
!(currentChatIndex >= 0 && currentChatIndex < chats.length)
|
||||||
|
) {
|
||||||
|
setCurrentChatIndex(0);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}, []);
|
}, []);
|
||||||
|
|
||||||
|
|
|
@ -14,10 +14,20 @@ const ChatContent = () => {
|
||||||
const inputRole = useStore((state) => state.inputRole);
|
const inputRole = useStore((state) => state.inputRole);
|
||||||
const setError = useStore((state) => state.setError);
|
const setError = useStore((state) => state.setError);
|
||||||
const messages = useStore((state) =>
|
const messages = useStore((state) =>
|
||||||
state.chats ? state.chats[state.currentChatIndex].messages : []
|
state.chats &&
|
||||||
|
state.chats.length > 0 &&
|
||||||
|
state.currentChatIndex >= 0 &&
|
||||||
|
state.currentChatIndex < state.chats.length
|
||||||
|
? state.chats[state.currentChatIndex].messages
|
||||||
|
: []
|
||||||
);
|
);
|
||||||
const stickyIndex = useStore((state) =>
|
const stickyIndex = useStore((state) =>
|
||||||
state.chats ? state.chats[state.currentChatIndex].messages.length : 0
|
state.chats &&
|
||||||
|
state.chats.length > 0 &&
|
||||||
|
state.currentChatIndex >= 0 &&
|
||||||
|
state.currentChatIndex < state.chats.length
|
||||||
|
? state.chats[state.currentChatIndex].messages.length
|
||||||
|
: 0
|
||||||
);
|
);
|
||||||
|
|
||||||
const { handleSubmit, error } = useSubmit();
|
const { handleSubmit, error } = useSubmit();
|
||||||
|
|
|
@ -6,7 +6,10 @@ import useAddChat from '@hooks/useAddChat';
|
||||||
|
|
||||||
const MobileBar = () => {
|
const MobileBar = () => {
|
||||||
const chatTitle = useStore((state) =>
|
const chatTitle = useStore((state) =>
|
||||||
state.chats && state.chats.length > 0
|
state.chats &&
|
||||||
|
state.chats.length > 0 &&
|
||||||
|
state.currentChatIndex >= 0 &&
|
||||||
|
state.currentChatIndex < state.chats.length
|
||||||
? state.chats[state.currentChatIndex].title
|
? state.chats[state.currentChatIndex].title
|
||||||
: 'New Chat'
|
: 'New Chat'
|
||||||
);
|
);
|
||||||
|
|
Loading…
Reference in a new issue