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