-
Notifications
You must be signed in to change notification settings - Fork 6
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fix: delete associated tags when entries are deleted
- Loading branch information
Showing
3 changed files
with
62 additions
and
37 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,26 +1,35 @@ | ||
import type { Entry } from "~types/entry"; | ||
import type { Settings } from "~types/settings"; | ||
|
||
export const applyLocalItemLimit = ( | ||
entries: Entry[], | ||
favoriteEntryIdSet: Set<string>, | ||
localItemLimit: number, | ||
) => | ||
entries | ||
.reduceRight<[Entry[], number]>( | ||
(acc, curr) => { | ||
if (favoriteEntryIdSet.has(curr.id)) { | ||
acc[0].push(curr); | ||
return acc; | ||
} | ||
{ localItemLimit }: Settings, | ||
favoriteEntryIds: string[], | ||
): [Entry[], string[]] => { | ||
if (localItemLimit === null) { | ||
return [entries, []]; | ||
} | ||
|
||
if (acc[1] < localItemLimit) { | ||
acc[0].push(curr); | ||
acc[1] += 1; | ||
return acc; | ||
} | ||
const favoriteEntryIdSet = new Set(favoriteEntryIds); | ||
|
||
const [newEntries, skippedEntryIds] = entries.reduceRight<[Entry[], string[], number]>( | ||
(acc, curr) => { | ||
if (favoriteEntryIdSet.has(curr.id)) { | ||
acc[0].push(curr); | ||
return acc; | ||
}, | ||
[[], 0], | ||
)[0] | ||
.reverse(); | ||
} | ||
|
||
if (acc[2] < localItemLimit) { | ||
acc[0].push(curr); | ||
acc[2] += 1; | ||
return acc; | ||
} | ||
|
||
acc[1].push(curr.id); | ||
return acc; | ||
}, | ||
[[], [], 0], | ||
); | ||
|
||
return [newEntries.reverse(), skippedEntryIds]; | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters