Skip to content

Commit a81512c

Browse files
committed
feat: Create new conversations from default
1 parent b87d0c0 commit a81512c

File tree

5 files changed

+25
-6
lines changed

5 files changed

+25
-6
lines changed

client/src/components/Chat/Menus/HeaderNewChat.tsx

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ import { useChatContext } from '~/Providers';
33
import { useMediaQuery, useLocalize } from '~/hooks';
44

55
export default function HeaderNewChat() {
6-
const { newConversation } = useChatContext();
6+
const { newDefaultConversation } = useChatContext();
77
const isSmallScreen = useMediaQuery('(max-width: 768px)');
88
const localize = useLocalize();
99
if (isSmallScreen) {
@@ -15,7 +15,7 @@ export default function HeaderNewChat() {
1515
aria-label={localize("com_ui_new_chat")}
1616
type="button"
1717
className="btn btn-neutral btn-small border-token-border-medium relative ml-2 flex hidden h-9 w-9 items-center justify-center whitespace-nowrap rounded-lg rounded-lg border focus:border-black-500 dark:focus:border-white-500 md:flex"
18-
onClick={() => newConversation()}
18+
onClick={() => newDefaultConversation()}
1919
>
2020
<div className="flex w-full items-center justify-center gap-2">
2121
<NewChatIcon />

client/src/components/Nav/MobileNav.tsx

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ export default function MobileNav({
1010
setNavVisible: Dispatch<SetStateAction<boolean>>;
1111
}) {
1212
const localize = useLocalize();
13-
const { newConversation } = useNewConvo(0);
13+
const { newDefaultConversation } = useNewConvo(0);
1414
const conversation = useRecoilValue(store.conversationByIndex(0));
1515
const { title = 'New Chat' } = conversation || {};
1616

@@ -52,7 +52,7 @@ export default function MobileNav({
5252
type="button"
5353
aria-label={localize('com_ui_new_chat')}
5454
className="m-1 inline-flex size-10 items-center justify-center rounded-full hover:bg-surface-hover"
55-
onClick={() => newConversation()}
55+
onClick={() => newDefaultConversation()}
5656
>
5757
<svg
5858
width="24"

client/src/components/Nav/NewChat.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -66,7 +66,7 @@ export default function NewChat({
6666
isSmallScreen: boolean;
6767
}) {
6868
/** Note: this component needs an explicit index passed if using more than one */
69-
const { newConversation: newConvo } = useNewConvo(index);
69+
const { newDefaultConversation: newConvo } = useNewConvo(index);
7070
const navigate = useNavigate();
7171
const localize = useLocalize();
7272

client/src/hooks/Chat/useChatHelpers.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ export default function useChatHelpers(index = 0, paramId?: string) {
1818
const queryClient = useQueryClient();
1919
const { isAuthenticated } = useAuthContext();
2020

21-
const { newConversation } = useNewConvo(index);
21+
const { newConversation, newDefaultConversation } = useNewConvo(index);
2222
const { useCreateConversationAtom } = store;
2323
const { conversation, setConversation } = useCreateConversationAtom(index);
2424
const { conversationId } = conversation ?? {};
@@ -143,6 +143,7 @@ export default function useChatHelpers(index = 0, paramId?: string) {
143143

144144
return {
145145
newConversation,
146+
newDefaultConversation,
146147
conversation,
147148
setConversation,
148149
// getConvos,

client/src/hooks/useNewConvo.ts

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -262,10 +262,28 @@ const useNewConvo = (index = 0) => {
262262
mutateAsync,
263263
],
264264
);
265+
const newDefaultConversation = useRecoilCallback(() => () => {
266+
let preset = defaultPreset;
267+
const defaultModelSpec = getDefaultModelSpec(startupConfig?.modelSpecs?.list);
268+
if (!preset && defaultModelSpec) {
269+
preset = {
270+
...defaultModelSpec.preset,
271+
iconURL: getModelSpecIconURL(defaultModelSpec),
272+
spec: defaultModelSpec.name,
273+
} as TConversation;
274+
}
275+
return newConversation({ conversation: {}, preset })
276+
}, [
277+
defaultPreset,
278+
startupConfig,
279+
switchToConversation,
280+
])
281+
265282

266283
return {
267284
switchToConversation,
268285
newConversation,
286+
newDefaultConversation,
269287
};
270288
};
271289

0 commit comments

Comments
 (0)