Skip to content

Commit

Permalink
Adds back in default conversation selector/create logic.
Browse files Browse the repository at this point in the history
  • Loading branch information
bLopata committed Dec 16, 2024
1 parent 7c70c4a commit 29a0cb8
Showing 1 changed file with 22 additions and 0 deletions.
22 changes: 22 additions & 0 deletions www/app/Chat.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -158,6 +158,28 @@ const { data: conversations, mutate: mutateConversations } = useSWR(
{
fallbackData: initialConversations,
provider: localStorageProvider,
onSuccess: async (conversations) => {
if (conversations.length) {
// If there are existing conversations:
// 1. Set the current conversation to the first one if none is selected
// 2. Or if the selected conversation doesn't exist in the list
if (
!conversationId ||
!conversations.find((c) => c.conversationId === conversationId)
) {
setConversationId(conversations[0].conversationId);
}
setCanSend(true);
} else {
// If no conversations exist:
// 1. Create a new conversation
// 2. Set it as the current conversation
// 3. Refresh the conversations list
const newConvo = await createConversation();
setConversationId(newConvo?.conversationId);
await mutateConversations();
}
},
revalidateOnFocus: false,
dedupingInterval: 60000,
revalidateIfStale: false,
Expand Down

0 comments on commit 29a0cb8

Please sign in to comment.