Skip to content

Commit

Permalink
Update reduceTimeSpans function to filter out duplicate entries whe…
Browse files Browse the repository at this point in the history
…n time spans overlap

* Add `isDuplicateNote` helper function to check for duplicate entries based on note paths
* Format `src/constants.ts` with prettier
* Add description in `src/settingsTab.ts` to inform users about overlapping time spans and potential duplicates
* Update settings UI to include a warning about overlapping time spans
  • Loading branch information
Kageetai committed Oct 25, 2024
1 parent ed7b790 commit f27953f
Show file tree
Hide file tree
Showing 3 changed files with 17 additions and 2 deletions.
6 changes: 6 additions & 0 deletions .devcontainer.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
{
"tasks": {
"test": "npm run lint",
"build": "npm run build"
}
}
11 changes: 10 additions & 1 deletion src/constants.ts
Original file line number Diff line number Diff line change
Expand Up @@ -101,6 +101,9 @@ const sortRenderedTimeSpanByDateDesc = (
b: RenderedTimeSpan,
) => (a.moment.isAfter(b.moment) ? -1 : 1);

const isDuplicateNote = (note: TFile, notes: TFile[]) =>
notes.some((existingNote) => existingNote.path === note.path);

export const reduceTimeSpans = (
timeSpans: TimeSpan[],
allDailyNotes: AllDailyNotes,
Expand Down Expand Up @@ -132,7 +135,13 @@ export const reduceTimeSpans = (
acc[title] = {
title,
moment: mom,
notes: acc[title] ? acc[title].notes.concat(notes) : notes,
notes: acc[title]
? acc[title].notes.concat(
notes.filter(
(note) => !isDuplicateNote(note, acc[title].notes),
),
)
: notes,
};
}
} while (mom.isAfter(oldestNoteDate) && recurring);
Expand Down
2 changes: 1 addition & 1 deletion src/settingsTab.ts
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ export class SettingsTab extends PluginSettingTab {

container.createEl("li", {
cls: "setting-item-description",
text: "Define time spans to review, e.g. '1 month' or 'every 6 months'",
text: "Define time spans to review, e.g. '1 month' or 'every 6 months'. Overlapping time spans may cause duplicate entries.",
});

this.plugin.settings.timeSpans.forEach(
Expand Down

0 comments on commit f27953f

Please sign in to comment.