From 1585b3a31436ff149e1c1d045280b20a56c9e5c6 Mon Sep 17 00:00:00 2001 From: Owen Gretzinger Date: Sat, 11 Jan 2025 12:40:43 -0500 Subject: [PATCH] refactor: rename mostRecentCompletionDate to lastActivity --- src/api/habits/index.tsx | 1 + src/api/habits/mock-habits.tsx | 14 +++++++------- src/api/habits/types.ts | 5 ++--- src/api/habits/use-create-habit.tsx | 2 +- src/api/habits/use-habits.tsx | 9 +++++---- src/api/habits/use-modify-entry.tsx | 5 ++--- src/api/habits/use-press-habit-button.tsx | 5 ++--- 7 files changed, 20 insertions(+), 21 deletions(-) diff --git a/src/api/habits/index.tsx b/src/api/habits/index.tsx index e4a70d6..993af14 100644 --- a/src/api/habits/index.tsx +++ b/src/api/habits/index.tsx @@ -2,5 +2,6 @@ export * from './types'; export * from './use-create-habit'; export * from './use-delete-habit'; export * from './use-edit-habit'; +export * from './use-habit-completions'; export * from './use-habits'; export * from './use-press-habit-button'; diff --git a/src/api/habits/mock-habits.tsx b/src/api/habits/mock-habits.tsx index 15719e1..8b987de 100644 --- a/src/api/habits/mock-habits.tsx +++ b/src/api/habits/mock-habits.tsx @@ -21,31 +21,31 @@ export const mockHabits: { id: HabitIdT; data: DbHabitT }[] = [ ['1' as UserIdT]: { displayName: 'John Doe', username: 'johndoe', - mostRecentCompletionDate: new Date('2024-12-01T00:00:00'), + lastActivity: new Date('2024-12-01T00:00:00'), isOwner: true, }, ['2' as UserIdT]: { displayName: 'Sarah Johnson', username: 'sarahj', - mostRecentCompletionDate: new Date('2024-12-08T00:00:00'), + lastActivity: new Date('2024-12-08T00:00:00'), isOwner: false, }, ['3' as UserIdT]: { displayName: 'Mike Wilson', username: 'mikew', - mostRecentCompletionDate: new Date('2024-12-08T00:00:00'), + lastActivity: new Date('2024-12-08T00:00:00'), isOwner: false, }, ['4' as UserIdT]: { displayName: 'Emily Brown', username: 'emilyb', - mostRecentCompletionDate: new Date('2024-12-07T00:00:00'), + lastActivity: new Date('2024-12-07T00:00:00'), isOwner: false, }, ['5' as UserIdT]: { displayName: 'Chris Lee', username: 'chrisl', - mostRecentCompletionDate: new Date('2024-12-03T00:00:00'), + lastActivity: new Date('2024-12-03T00:00:00'), isOwner: false, }, }, @@ -66,7 +66,7 @@ export const mockHabits: { id: HabitIdT; data: DbHabitT }[] = [ ['1' as UserIdT]: { displayName: 'Jane Smith', username: 'janesmith', - mostRecentCompletionDate: new Date('2024-01-15T00:00:00'), + lastActivity: new Date('2024-01-15T00:00:00'), isOwner: true, }, }, @@ -87,7 +87,7 @@ export const mockHabits: { id: HabitIdT; data: DbHabitT }[] = [ ['1' as UserIdT]: { displayName: 'Alex Chen', username: 'alexchen', - mostRecentCompletionDate: new Date('2024-12-01T00:00:00'), + lastActivity: new Date('2024-12-01T00:00:00'), isOwner: true, }, }, diff --git a/src/api/habits/types.ts b/src/api/habits/types.ts index 3887a57..e7f7edc 100644 --- a/src/api/habits/types.ts +++ b/src/api/habits/types.ts @@ -18,7 +18,7 @@ export const HabitIdSchema = z.coerce export const dbParticipantSchema = z.object({ displayName: z.string(), username: z.string(), - mostRecentCompletionDate: z.date(), + lastActivity: z.date(), isOwner: z.boolean().optional(), }); export type DbParticipantT = z.infer; @@ -82,7 +82,6 @@ export type DbHabitT = z.infer; // PARTICIPANTS const participantSchema = dbParticipantSchema // indicator of whether the user has activity today instead of the most recent completion date - .omit({ mostRecentCompletionDate: true }) .extend({ hasActivityToday: z.boolean(), }); @@ -98,7 +97,7 @@ export type ParticipantWithoutIdT = z.infer; export const participantsSchema = z.record( UserIdSchema, - participantWithoutIdSchema, + participantWithIdSchema, ); export type ParticipantsT = z.infer; diff --git a/src/api/habits/use-create-habit.tsx b/src/api/habits/use-create-habit.tsx index 32deee3..f7f118e 100644 --- a/src/api/habits/use-create-habit.tsx +++ b/src/api/habits/use-create-habit.tsx @@ -33,7 +33,7 @@ export const useCreateHabit = createMutation({ ['1' as UserIdT]: { displayName: 'Alex Chen', username: 'alexchen', - mostRecentCompletionDate: new Date(), + lastActivity: new Date(), isOwner: true, }, }, diff --git a/src/api/habits/use-habits.tsx b/src/api/habits/use-habits.tsx index a9e4f49..59b826b 100644 --- a/src/api/habits/use-habits.tsx +++ b/src/api/habits/use-habits.tsx @@ -3,6 +3,7 @@ import { createQuery } from 'react-query-kit'; import { habitColors } from '@/ui/colors'; import { addTestDelay } from '../common'; +import { type UserIdT } from '../users'; import { mockHabits } from './mock-habits'; import { type HabitT } from './types'; @@ -27,13 +28,13 @@ export const useHabits = createQuery({ return [ participantId, { + id: participantId as UserIdT, displayName: participant.displayName, username: participant.username, - mostRecentCompletionDate: participant.mostRecentCompletionDate, + lastActivity: new Date(participant.lastActivity), hasActivityToday: - participant.mostRecentCompletionDate.toLocaleDateString( - 'en-CA', - ) === new Date().toLocaleDateString('en-CA'), + participant.lastActivity.toLocaleDateString('en-CA') === + new Date().toLocaleDateString('en-CA'), isOwner: participant?.isOwner ?? false, }, ]; diff --git a/src/api/habits/use-modify-entry.tsx b/src/api/habits/use-modify-entry.tsx index 56cf6bb..8ef5f5f 100644 --- a/src/api/habits/use-modify-entry.tsx +++ b/src/api/habits/use-modify-entry.tsx @@ -60,7 +60,6 @@ export const useModifyHabitEntry = createMutation({ }, }); - // update mostRecentCompletionDate in mockHabits setMockHabits( mockHabits.map((habit) => { if (habit.id === variables.habitId) { @@ -74,11 +73,11 @@ export const useModifyHabitEntry = createMutation({ ...habit.data.participants, [variables.userId]: { ...participant, - mostRecentCompletionDate: participant.mostRecentCompletionDate + lastActivity: participant.lastActivity ? new Date( Math.max( new Date(`${variables.date}T00:00:00`).getTime(), - participant.mostRecentCompletionDate?.getTime() ?? 0, + participant.lastActivity?.getTime() ?? 0, ), ) : new Date(`${variables.date}T00:00:00`), diff --git a/src/api/habits/use-press-habit-button.tsx b/src/api/habits/use-press-habit-button.tsx index 9e8b193..076b55f 100644 --- a/src/api/habits/use-press-habit-button.tsx +++ b/src/api/habits/use-press-habit-button.tsx @@ -56,7 +56,6 @@ export const usePressHabitButton = createMutation({ }, }); - // update mostRecentCompletionDate in mockHabits setMockHabits( mockHabits.map((habit) => { if (habit.id === variables.habitId) { @@ -70,11 +69,11 @@ export const usePressHabitButton = createMutation({ ...habit.data.participants, [variables.userId]: { ...participant, - mostRecentCompletionDate: participant.mostRecentCompletionDate + lastActivity: participant.lastActivity ? new Date( Math.max( new Date(`${variables.date}T00:00:00`).getTime(), - participant.mostRecentCompletionDate?.getTime() ?? 0, + participant.lastActivity?.getTime() ?? 0, ), ) : new Date(`${variables.date}T00:00:00`),