Skip to content

Commit ece42b5

Browse files
refactor: rename mostRecentCompletionDate to lastActivity (#152)
### TL;DR Renamed `mostRecentCompletionDate` to `lastActivity` and added participant ID to habit data structure. ### What changed? - Renamed `mostRecentCompletionDate` field to `lastActivity` across all habit-related files - Added participant ID to the habit data structure - Added `use-habit-completions` export - Updated participant schema to include ID in the record type ### Why make this change? The rename from `mostRecentCompletionDate` to `lastActivity` better reflects the field's purpose, as it tracks general user activity rather than just completions. Adding participant IDs improves data consistency and makes it easier to reference specific participants throughout the application.
1 parent 05f6d7d commit ece42b5

File tree

7 files changed

+20
-21
lines changed

7 files changed

+20
-21
lines changed

src/api/habits/index.tsx

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,5 +2,6 @@ export * from './types';
22
export * from './use-create-habit';
33
export * from './use-delete-habit';
44
export * from './use-edit-habit';
5+
export * from './use-habit-completions';
56
export * from './use-habits';
67
export * from './use-press-habit-button';

src/api/habits/mock-habits.tsx

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -21,31 +21,31 @@ export const mockHabits: { id: HabitIdT; data: DbHabitT }[] = [
2121
['1' as UserIdT]: {
2222
displayName: 'John Doe',
2323
username: 'johndoe',
24-
mostRecentCompletionDate: new Date('2024-12-01T00:00:00'),
24+
lastActivity: new Date('2024-12-01T00:00:00'),
2525
isOwner: true,
2626
},
2727
['2' as UserIdT]: {
2828
displayName: 'Sarah Johnson',
2929
username: 'sarahj',
30-
mostRecentCompletionDate: new Date('2024-12-08T00:00:00'),
30+
lastActivity: new Date('2024-12-08T00:00:00'),
3131
isOwner: false,
3232
},
3333
['3' as UserIdT]: {
3434
displayName: 'Mike Wilson',
3535
username: 'mikew',
36-
mostRecentCompletionDate: new Date('2024-12-08T00:00:00'),
36+
lastActivity: new Date('2024-12-08T00:00:00'),
3737
isOwner: false,
3838
},
3939
['4' as UserIdT]: {
4040
displayName: 'Emily Brown',
4141
username: 'emilyb',
42-
mostRecentCompletionDate: new Date('2024-12-07T00:00:00'),
42+
lastActivity: new Date('2024-12-07T00:00:00'),
4343
isOwner: false,
4444
},
4545
['5' as UserIdT]: {
4646
displayName: 'Chris Lee',
4747
username: 'chrisl',
48-
mostRecentCompletionDate: new Date('2024-12-03T00:00:00'),
48+
lastActivity: new Date('2024-12-03T00:00:00'),
4949
isOwner: false,
5050
},
5151
},
@@ -66,7 +66,7 @@ export const mockHabits: { id: HabitIdT; data: DbHabitT }[] = [
6666
['1' as UserIdT]: {
6767
displayName: 'Jane Smith',
6868
username: 'janesmith',
69-
mostRecentCompletionDate: new Date('2024-01-15T00:00:00'),
69+
lastActivity: new Date('2024-01-15T00:00:00'),
7070
isOwner: true,
7171
},
7272
},
@@ -87,7 +87,7 @@ export const mockHabits: { id: HabitIdT; data: DbHabitT }[] = [
8787
['1' as UserIdT]: {
8888
displayName: 'Alex Chen',
8989
username: 'alexchen',
90-
mostRecentCompletionDate: new Date('2024-12-01T00:00:00'),
90+
lastActivity: new Date('2024-12-01T00:00:00'),
9191
isOwner: true,
9292
},
9393
},

src/api/habits/types.ts

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ export const HabitIdSchema = z.coerce
1818
export const dbParticipantSchema = z.object({
1919
displayName: z.string(),
2020
username: z.string(),
21-
mostRecentCompletionDate: z.date(),
21+
lastActivity: z.date(),
2222
isOwner: z.boolean().optional(),
2323
});
2424
export type DbParticipantT = z.infer<typeof dbParticipantSchema>;
@@ -82,7 +82,6 @@ export type DbHabitT = z.infer<typeof dbHabitSchema>;
8282
// PARTICIPANTS
8383
const participantSchema = dbParticipantSchema
8484
// indicator of whether the user has activity today instead of the most recent completion date
85-
.omit({ mostRecentCompletionDate: true })
8685
.extend({
8786
hasActivityToday: z.boolean(),
8887
});
@@ -98,7 +97,7 @@ export type ParticipantWithoutIdT = z.infer<typeof participantWithoutIdSchema>;
9897

9998
export const participantsSchema = z.record(
10099
UserIdSchema,
101-
participantWithoutIdSchema,
100+
participantWithIdSchema,
102101
);
103102
export type ParticipantsT = z.infer<typeof participantsSchema>;
104103

src/api/habits/use-create-habit.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,7 @@ export const useCreateHabit = createMutation<Response, Variables, Error>({
3333
['1' as UserIdT]: {
3434
displayName: 'Alex Chen',
3535
username: 'alexchen',
36-
mostRecentCompletionDate: new Date(),
36+
lastActivity: new Date(),
3737
isOwner: true,
3838
},
3939
},

src/api/habits/use-habits.tsx

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@ import { createQuery } from 'react-query-kit';
33
import { habitColors } from '@/ui/colors';
44

55
import { addTestDelay } from '../common';
6+
import { type UserIdT } from '../users';
67
import { mockHabits } from './mock-habits';
78
import { type HabitT } from './types';
89

@@ -27,13 +28,13 @@ export const useHabits = createQuery<Response, Variables, Error>({
2728
return [
2829
participantId,
2930
{
31+
id: participantId as UserIdT,
3032
displayName: participant.displayName,
3133
username: participant.username,
32-
mostRecentCompletionDate: participant.mostRecentCompletionDate,
34+
lastActivity: new Date(participant.lastActivity),
3335
hasActivityToday:
34-
participant.mostRecentCompletionDate.toLocaleDateString(
35-
'en-CA',
36-
) === new Date().toLocaleDateString('en-CA'),
36+
participant.lastActivity.toLocaleDateString('en-CA') ===
37+
new Date().toLocaleDateString('en-CA'),
3738
isOwner: participant?.isOwner ?? false,
3839
},
3940
];

src/api/habits/use-modify-entry.tsx

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -60,7 +60,6 @@ export const useModifyHabitEntry = createMutation<Response, Variables, Error>({
6060
},
6161
});
6262

63-
// update mostRecentCompletionDate in mockHabits
6463
setMockHabits(
6564
mockHabits.map((habit) => {
6665
if (habit.id === variables.habitId) {
@@ -74,11 +73,11 @@ export const useModifyHabitEntry = createMutation<Response, Variables, Error>({
7473
...habit.data.participants,
7574
[variables.userId]: {
7675
...participant,
77-
mostRecentCompletionDate: participant.mostRecentCompletionDate
76+
lastActivity: participant.lastActivity
7877
? new Date(
7978
Math.max(
8079
new Date(`${variables.date}T00:00:00`).getTime(),
81-
participant.mostRecentCompletionDate?.getTime() ?? 0,
80+
participant.lastActivity?.getTime() ?? 0,
8281
),
8382
)
8483
: new Date(`${variables.date}T00:00:00`),

src/api/habits/use-press-habit-button.tsx

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -56,7 +56,6 @@ export const usePressHabitButton = createMutation<Response, Variables, Error>({
5656
},
5757
});
5858

59-
// update mostRecentCompletionDate in mockHabits
6059
setMockHabits(
6160
mockHabits.map((habit) => {
6261
if (habit.id === variables.habitId) {
@@ -70,11 +69,11 @@ export const usePressHabitButton = createMutation<Response, Variables, Error>({
7069
...habit.data.participants,
7170
[variables.userId]: {
7271
...participant,
73-
mostRecentCompletionDate: participant.mostRecentCompletionDate
72+
lastActivity: participant.lastActivity
7473
? new Date(
7574
Math.max(
7675
new Date(`${variables.date}T00:00:00`).getTime(),
77-
participant.mostRecentCompletionDate?.getTime() ?? 0,
76+
participant.lastActivity?.getTime() ?? 0,
7877
),
7978
)
8079
: new Date(`${variables.date}T00:00:00`),

0 commit comments

Comments
 (0)