Skip to content

Commit

Permalink
fix: conversation group order when adding the first 'today' conv
Browse files Browse the repository at this point in the history
  • Loading branch information
edwardzjl committed Dec 28, 2024
1 parent a491724 commit aa5c496
Showing 1 changed file with 5 additions and 7 deletions.
12 changes: 5 additions & 7 deletions web/src/contexts/conversation.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -141,16 +141,14 @@ export const conversationReducer = (groupedConvs, action) => {

// action.conv: { id, title, created_at, last_message_at, owner, pinned }
const { conv } = action;
// Update 'Today' group only if it exists, without side effects
const updatedGroupedConvs = { ...groupedConvs };

if (updatedGroupedConvs.Today) {
updatedGroupedConvs.Today = [conv, ...updatedGroupedConvs.Today];
if (!groupedConvs.Today) {
return { Today: [conv], ...groupedConvs };
} else {
updatedGroupedConvs.Today = [conv];
const updatedGroupedConvs = { ...groupedConvs };
updatedGroupedConvs.Today = [conv, ...updatedGroupedConvs.Today];
return updatedGroupedConvs;
}

return updatedGroupedConvs;
}
case "deleted": {
const convs = flatConvs(groupedConvs);
Expand Down

0 comments on commit aa5c496

Please sign in to comment.