Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

refactor: rename mostRecentCompletionDate to lastActivity #152

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions src/api/habits/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -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';
14 changes: 7 additions & 7 deletions src/api/habits/mock-habits.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -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,
},
},
Expand All @@ -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,
},
},
Expand All @@ -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,
},
},
Expand Down
5 changes: 2 additions & 3 deletions src/api/habits/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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<typeof dbParticipantSchema>;
Expand Down Expand Up @@ -82,7 +82,6 @@ export type DbHabitT = z.infer<typeof dbHabitSchema>;
// 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(),
});
Expand All @@ -98,7 +97,7 @@ export type ParticipantWithoutIdT = z.infer<typeof participantWithoutIdSchema>;

export const participantsSchema = z.record(
UserIdSchema,
participantWithoutIdSchema,
participantWithIdSchema,
);
export type ParticipantsT = z.infer<typeof participantsSchema>;

Expand Down
2 changes: 1 addition & 1 deletion src/api/habits/use-create-habit.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ export const useCreateHabit = createMutation<Response, Variables, Error>({
['1' as UserIdT]: {
displayName: 'Alex Chen',
username: 'alexchen',
mostRecentCompletionDate: new Date(),
lastActivity: new Date(),
isOwner: true,
},
},
Expand Down
9 changes: 5 additions & 4 deletions src/api/habits/use-habits.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -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';

Expand All @@ -27,13 +28,13 @@ export const useHabits = createQuery<Response, Variables, Error>({
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,
},
];
Expand Down
5 changes: 2 additions & 3 deletions src/api/habits/use-modify-entry.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,6 @@ export const useModifyHabitEntry = createMutation<Response, Variables, Error>({
},
});

// update mostRecentCompletionDate in mockHabits
setMockHabits(
mockHabits.map((habit) => {
if (habit.id === variables.habitId) {
Expand All @@ -74,11 +73,11 @@ export const useModifyHabitEntry = createMutation<Response, Variables, Error>({
...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`),
Expand Down
5 changes: 2 additions & 3 deletions src/api/habits/use-press-habit-button.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,6 @@ export const usePressHabitButton = createMutation<Response, Variables, Error>({
},
});

// update mostRecentCompletionDate in mockHabits
setMockHabits(
mockHabits.map((habit) => {
if (habit.id === variables.habitId) {
Expand All @@ -70,11 +69,11 @@ export const usePressHabitButton = createMutation<Response, Variables, Error>({
...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`),
Expand Down
Loading