From 1d7623084db87b09700b546dfdca0e534f3ed028 Mon Sep 17 00:00:00 2001 From: Greg D'Arcy Date: Thu, 12 Oct 2023 06:45:50 +0100 Subject: [PATCH] Fix ransome1/sleek#543 (#544) --- src/__tests__/main/CreateRecurringTodo.tsx | 8 +++++++- src/main/modules/TodoObject/CreateRecurringTodo.tsx | 6 ++++++ 2 files changed, 13 insertions(+), 1 deletion(-) diff --git a/src/__tests__/main/CreateRecurringTodo.tsx b/src/__tests__/main/CreateRecurringTodo.tsx index d6668ca5..9dee3a40 100644 --- a/src/__tests__/main/CreateRecurringTodo.tsx +++ b/src/__tests__/main/CreateRecurringTodo.tsx @@ -91,5 +91,11 @@ describe('Create recurring todos', () => { const fileContent = await fs.readFile('./src/__tests__/__mock__/recurrence.txt', 'utf8'); expect(fileContent.split('\n').pop()).toEqual(`${dateTodayString} Line 1 rec:+1d t:2023-09-20 due:${dateTomorrowString}`); }); - + + test('Should add a new todo and set the priority to the value of the pri extension', async () => { + const recurringTodo = await createRecurringTodo(`x ${dateTodayString} ${dateTodayString} Line 1 rec:1d pri:A`, '1d'); + const fileContent = await fs.readFile('./src/__tests__/__mock__/recurrence.txt', 'utf8'); + expect(fileContent.split('\n').pop()).toEqual(`(A) ${dateTodayString} Line 1 rec:1d due:${dateTomorrowString} pri:A`); + }); + }); \ No newline at end of file diff --git a/src/main/modules/TodoObject/CreateRecurringTodo.tsx b/src/main/modules/TodoObject/CreateRecurringTodo.tsx index cf0ed346..58845a79 100644 --- a/src/main/modules/TodoObject/CreateRecurringTodo.tsx +++ b/src/main/modules/TodoObject/CreateRecurringTodo.tsx @@ -52,6 +52,12 @@ const createRecurringTodo = async (string: string, recurrence: string): Promise< recurringTodoObject.setCreated(null); } + const previousPriorityIndex = recurringTodoObject.extensions().findIndex((extension) => extension.key === 'pri'); + const previousPriorityString = recurringTodoObject.extensions()[previousPriorityIndex]?.value; + if(previousPriorityString && previousPriorityString !== 'null') { + recurringTodoObject.setPriority(previousPriorityString) + } + if (recurrence && completedDate) { const strictRecurrence: boolean = recurrence.startsWith('+'); const recurrenceInterval: any = strictRecurrence ? recurrence.slice(1) : recurrence;