Skip to content

Commit

Permalink
Merge pull request obsidian-tasks-group#3073 from ilandikov/feat-post…
Browse files Browse the repository at this point in the history
…pone-item-check

feat: check postpone item if its date matches the one in the task
  • Loading branch information
claremacrae authored Sep 11, 2024
2 parents 9572d0e + 26e3409 commit dee3dd8
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 6 deletions.
21 changes: 17 additions & 4 deletions src/ui/Menus/PostponeMenu.ts
Original file line number Diff line number Diff line change
Expand Up @@ -38,11 +38,24 @@ export class PostponeMenu extends TaskEditingMenu {
itemNamingFunction: NamingFunction,
postponingFunction: PostponingFunction,
) => {
// TODO some of the code below is duplicated in postponeOnClickCallback() and may be refactored
let isCurrentValue = false;
const dateFieldToPostpone = getDateFieldToPostpone(task);
if (dateFieldToPostpone) {
const { postponedDate } = postponingFunction(task, dateFieldToPostpone, timeUnit, amount);

if (task[dateFieldToPostpone]?.isSame(postponedDate, 'day')) {
isCurrentValue = true;
}
}

const title = itemNamingFunction(task, amount, timeUnit);
// TODO Call setChecked() to put a checkmark against the item, if it represents the current task field value.
item.setTitle(title).onClick(() =>
PostponeMenu.postponeOnClickCallback(button, task, amount, timeUnit, postponingFunction, taskSaver),
);

item.setChecked(isCurrentValue)
.setTitle(title)
.onClick(() =>
PostponeMenu.postponeOnClickCallback(button, task, amount, timeUnit, postponingFunction, taskSaver),
);
};

const fixedTitle = fixedDateMenuItemTitle;
Expand Down
4 changes: 2 additions & 2 deletions tests/ui/Menus/PostponeMenu.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -88,7 +88,7 @@ describe('PostponeMenu', () => {
const itemsAsText = contentsOfPostponeMenuForTask(new TaskBuilder().startDate(today));
expect(itemsAsText).toMatchInlineSnapshot(`
"
Start today, on Sun 3rd Dec
x Start today, on Sun 3rd Dec
Start tomorrow, on Mon 4th Dec
---
Start in 2 days, on Tue 5th Dec
Expand All @@ -114,7 +114,7 @@ describe('PostponeMenu', () => {
expect(itemsAsText).toMatchInlineSnapshot(`
"
Scheduled today, on Sun 3rd Dec
Scheduled tomorrow, on Mon 4th Dec
x Scheduled tomorrow, on Mon 4th Dec
---
Postpone scheduled date by 2 days, to Wed 6th Dec
Postpone scheduled date by 3 days, to Thu 7th Dec
Expand Down

0 comments on commit dee3dd8

Please sign in to comment.