Skip to content

Commit 2fd7134

Browse files
committed
fix merge
1 parent ba75a7d commit 2fd7134

1 file changed

Lines changed: 17 additions & 2 deletions

File tree

src/shared/syncUtils.ts

Lines changed: 17 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -73,6 +73,22 @@ export function mergeLists<T>(
7373
return Array.from(map.values());
7474
}
7575

76+
// Helper for sessions without IDs
77+
function mergeSessions(
78+
curr: PomodoroSession[] = [],
79+
inc: PomodoroSession[] = [],
80+
): PomodoroSession[] {
81+
const map = new Map<string, PomodoroSession>();
82+
83+
const generateKey = (s: PomodoroSession) =>
84+
`${s.start}-${s.end}-${s.type || "work"}`;
85+
86+
for (const c of curr) map.set(generateKey(c), c);
87+
for (const i of inc) map.set(generateKey(i), i);
88+
89+
return Array.from(map.values()).sort((a, b) => a.start - b.start);
90+
}
91+
7692
export function mergeData(curr: SyncData, inc: SyncData): SyncData {
7793
return {
7894
tasks: mergeLists(curr.tasks, inc.tasks),
@@ -82,10 +98,9 @@ export function mergeData(curr: SyncData, inc: SyncData): SyncData {
8298
habits: mergeLists(curr.habits, inc.habits),
8399
flashcards: mergeLists(curr.flashcards, inc.flashcards, null),
84100
decks: mergeLists(curr.decks, inc.decks, null),
85-
pomodoroSessions: mergeLists(
101+
pomodoroSessions: mergeSessions(
86102
curr.pomodoroSessions,
87103
inc.pomodoroSessions,
88-
null,
89104
),
90105
timers: mergeLists(curr.timers, inc.timers, null),
91106
trips: mergeLists(curr.trips, inc.trips, "updatedAt"),

0 commit comments

Comments
 (0)