From 35975b7e6fa42eebff8f68bcaa618b95650bb157 Mon Sep 17 00:00:00 2001 From: Daniel Metcalfe Date: Tue, 3 Dec 2024 11:16:25 +0000 Subject: [PATCH] =?UTF-8?q?=F0=9F=90=9B=20Duplicate=20today=20journey=20la?= =?UTF-8?q?bel=20after=20completing?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- components/pages/Home.tsx | 64 +++++++++++++++---- .../todos/groupTodosByCompletedAt.spec.ts | 35 +++++++++- components/todos/groupTodosByCompletedAt.ts | 2 +- 3 files changed, 85 insertions(+), 16 deletions(-) diff --git a/components/pages/Home.tsx b/components/pages/Home.tsx index 6d584f8..fedbe0d 100644 --- a/components/pages/Home.tsx +++ b/components/pages/Home.tsx @@ -73,7 +73,6 @@ const Home = () => { <> -
@@ -83,11 +82,11 @@ const Home = () => { translucent > - + { - menuController.toggle('end') + menuController.toggle('start') }} > { /> - - - @@ -253,10 +246,13 @@ export const TodoLists = ({}: {}) => { const [present] = useTodoActionSheet() - const logGroups = useMemo( - () => (todos?.log ? groupTodosByCompletedAt(todos.log) : []), - [todos?.log], - ) + const [logGroups, todayCompletedTodos] = useMemo(() => { + if (!todos?.log) return [[], []] + const groups = groupTodosByCompletedAt(todos.log) + const todayGroup = groups[groups.length - 1] + const logGroups = groups.slice(0, -1) + return [logGroups, todayGroup.todos] + }, [todos?.log]) return ( { }) }} > + {todayCompletedTodos.map(todo => ( + { + present(todo) + }} + onCompletionChange={event => { + db.transaction( + 'rw', + db.wayfinderOrder, + db.todos, + async () => { + const wayfinderOrder = await db.wayfinderOrder + .orderBy('order') + .limit(1) + .keys() + await Promise.all([ + db.wayfinderOrder.add({ + todoId: todo.id, + order: order( + undefined, + wayfinderOrder[0]?.toString(), + ), + }), + db.todos.update(todo.id, { + completedAt: event.detail.checked + ? new Date() + : undefined, + }), + ]) + }, + ) + setLogLimit(limit => limit - 1) + }} + starRole={starRoles?.find( + starRole => todo.starRole === starRole.id, + )} + todo={todo} + /> + ))} {todos.wayfinder.map((todo, index) => ( { diff --git a/components/todos/groupTodosByCompletedAt.spec.ts b/components/todos/groupTodosByCompletedAt.spec.ts index 2d48ea4..e7f15a5 100644 --- a/components/todos/groupTodosByCompletedAt.spec.ts +++ b/components/todos/groupTodosByCompletedAt.spec.ts @@ -6,7 +6,12 @@ beforeAll(() => { }) test('no completed todos', () => { - expect(groupTodosByCompletedAt([])).toEqual([]) + expect(groupTodosByCompletedAt([])).toEqual([ + { + label: 'Today', + todos: [], + }, + ]) }) describe('one completed todo', () => { @@ -53,6 +58,10 @@ describe('one completed todo', () => { }, ], }, + { + label: 'Today', + todos: [], + }, ]) }) @@ -77,6 +86,10 @@ describe('one completed todo', () => { }, ], }, + { + label: 'Today', + todos: [], + }, ]) const mondayStart = new Date('2019-12-30T00:00:00.000Z') @@ -99,6 +112,10 @@ describe('one completed todo', () => { }, ], }, + { + label: 'Today', + todos: [], + }, ]) }) @@ -122,6 +139,10 @@ describe('one completed todo', () => { }, ], }, + { + label: 'Today', + todos: [], + }, ]) expect( @@ -143,6 +164,10 @@ describe('one completed todo', () => { }, ], }, + { + label: 'Today', + todos: [], + }, ]) }) }) @@ -231,6 +256,10 @@ describe('multiple completed todos', () => { }, ], }, + { + label: 'Today', + todos: [], + }, ]) }) @@ -317,6 +346,10 @@ describe('multiple completed todos', () => { }, ], }, + { + label: 'Today', + todos: [], + }, ]) }) diff --git a/components/todos/groupTodosByCompletedAt.ts b/components/todos/groupTodosByCompletedAt.ts index 159f207..7d7296c 100644 --- a/components/todos/groupTodosByCompletedAt.ts +++ b/components/todos/groupTodosByCompletedAt.ts @@ -80,6 +80,6 @@ export function groupTodosByCompletedAt(completedTodos: Todo[]) { const indexB = groupMeta.findIndex(meta => meta.label === b[0]) return indexA - indexB }) - .filter(([, todos]) => todos.length > 0) + .filter(([label, todos]) => todos.length > 0 || label === 'Today') // Always include today because want to show the marker even when there are no todos yet completed .map(([label, todos]) => ({ label, todos })) }