Browse Source

fix: new session should insert at top

Yidadaa 2 years ago
parent
commit
4f10b9a60f
2 changed files with 7 additions and 4 deletions
  1. 5 2
      app/components/home.tsx
  2. 2 2
      app/store.ts

+ 5 - 2
app/components/home.tsx

@@ -130,11 +130,14 @@ export function Chat() {
     );
 
   useEffect(() => {
-    latestMessageRef.current?.scrollIntoView(false);
+    latestMessageRef.current?.scrollIntoView({
+      behavior: "smooth",
+      block: "end",
+    });
   });
 
   return (
-    <div className={styles.chat}>
+    <div className={styles.chat} key={session.topic}>
       <div className={styles["chat-header"]}>
         <div>
           <div className={styles["chat-header-title"]}>{session.topic}</div>

+ 2 - 2
app/store.ts

@@ -106,8 +106,8 @@ export const useChatStore = create<ChatStore>()(
 
       newSession() {
         set((state) => ({
-          currentSessionIndex: state.sessions.length,
-          sessions: state.sessions.concat([createEmptySession()]),
+          currentSessionIndex: 0,
+          sessions: [createEmptySession()].concat(state.sessions),
         }));
       },