Skip to content

Commit

Permalink
fix: #641 delete wrong chat list
Browse files Browse the repository at this point in the history
  • Loading branch information
Yidadaa committed Apr 9, 2023
1 parent 174c745 commit 4a49226
Show file tree
Hide file tree
Showing 4 changed files with 8 additions and 6 deletions.
2 changes: 1 addition & 1 deletion app/components/chat-list.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -96,7 +96,7 @@ export function ChatList() {
index={i}
selected={i === selectedIndex}
onClick={() => selectSession(i)}
onDelete={chatStore.deleteSession}
onDelete={() => chatStore.deleteSession(i)}
/>
))}
{provided.placeholder}
Expand Down
2 changes: 2 additions & 0 deletions app/components/ui-lib.module.scss
Original file line number Diff line number Diff line change
Expand Up @@ -127,6 +127,7 @@
width: 100vw;
display: flex;
justify-content: center;
pointer-events: none;

.toast-content {
max-width: 80vw;
Expand All @@ -141,6 +142,7 @@
margin-bottom: 20px;
display: flex;
align-items: center;
pointer-events: all;

.toast-action {
padding-left: 20px;
Expand Down
2 changes: 1 addition & 1 deletion app/components/ui-lib.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -156,7 +156,7 @@ export function showToast(
};

setTimeout(() => {
close();
// close();
}, delay);

root.render(<Toast content={content} action={action} />);
Expand Down
8 changes: 4 additions & 4 deletions app/store/app.ts
Original file line number Diff line number Diff line change
Expand Up @@ -205,7 +205,7 @@ interface ChatStore {
moveSession: (from: number, to: number) => void;
selectSession: (index: number) => void;
newSession: () => void;
deleteSession: () => void;
deleteSession: (index?: number) => void;
currentSession: () => ChatSession;
onNewMessage: (message: Message) => void;
onUserInput: (content: string) => Promise<void>;
Expand Down Expand Up @@ -326,13 +326,13 @@ export const useChatStore = create<ChatStore>()(
}));
},

deleteSession() {
deleteSession(i?: number) {
const deletedSession = get().currentSession();
const index = get().currentSessionIndex;
const index = i ?? get().currentSessionIndex;
const isLastSession = get().sessions.length === 1;
if (!isMobileScreen() || confirm(Locale.Home.DeleteChat)) {
get().removeSession(index);

showToast(Locale.Home.DeleteToast, {
text: Locale.Home.Revert,
onClick() {
Expand Down

0 comments on commit 4a49226

Please sign in to comment.