-
Notifications
You must be signed in to change notification settings - Fork 5
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: implement notifications system and UI (#155)
### TL;DR Added notifications screen with support for friend requests, habit invites, and nudges. https://github.com/user-attachments/assets/319a4c5f-1e35-4be7-ac01-6a8cb28ca932 ### What changed? - Added notifications screen with real-time updates and interactive responses - Upgraded @gorhom/bottom-sheet from 4.6.3 to 5.0.6 to gain access to dynamic sizing: https://gorhom.dev/react-native-bottom-sheet/dynamic-sizing - Created new components for notification cards and user info displays - Implemented mock notification data and handlers - Added single habit query hook ### How to test? 1. Navigate to the notifications tab 2. Verify different notification types display correctly: - Friend requests - Habit invites - Nudge reminders 3. Test notification interactions: - Respond to friend requests - Accept/decline habit invites - Dismiss nudges 4. Confirm user profiles and habit details load in notification modals 5. Verify time ago formatting works correctly
- Loading branch information
1 parent
e82a13c
commit 9097a7a
Showing
23 changed files
with
625 additions
and
157 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,50 @@ | ||
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'; | ||
|
||
type Variables = { id: HabitT['id'] }; | ||
type Response = HabitT; | ||
|
||
export const useHabit = createQuery<Response, Variables, Error>({ | ||
queryKey: ['habit'], | ||
fetcher: async ({ id }) => { | ||
const dbHabit = await addTestDelay( | ||
mockHabits.find((habit) => habit.id === id), | ||
); | ||
if (!dbHabit) throw new Error('Habit not found'); | ||
|
||
const { data } = dbHabit; | ||
return { | ||
id, | ||
...data, | ||
color: habitColors[data.colorName], | ||
participants: Object.fromEntries( | ||
Object.entries(data.participants).map( | ||
([participantId, participant]) => { | ||
if (!participant) | ||
throw new Error('Participant not found for habit ' + id); | ||
|
||
return [ | ||
participantId, | ||
{ | ||
id: participantId as UserIdT, | ||
displayName: participant.displayName, | ||
username: participant.username, | ||
lastActivity: new Date(participant.lastActivity), | ||
hasActivityToday: | ||
participant.lastActivity.toLocaleDateString('en-CA') === | ||
new Date().toLocaleDateString('en-CA'), | ||
isOwner: participant?.isOwner ?? false, | ||
}, | ||
]; | ||
}, | ||
), | ||
), | ||
}; | ||
}, | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,4 +1,5 @@ | ||
export * from './colors-schemas'; | ||
export * from './common'; | ||
export * from './habits'; | ||
export * from './notifications'; | ||
export * from './users'; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1 +1,2 @@ | ||
export * from './types'; | ||
export * from './use-notifications'; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,45 @@ | ||
import { type HabitIdT } from '../habits'; | ||
import { type UserIdT } from '../users'; | ||
import { | ||
type FriendNotificationT, | ||
type HabitNotificationT, | ||
type NotificationT, | ||
} from './types'; | ||
|
||
const now = new Date(); | ||
const getTimeAgoDate = (seconds: number) => | ||
new Date(now.getTime() - seconds * 1000); | ||
|
||
export const mockNotifications: (FriendNotificationT | HabitNotificationT)[] = [ | ||
{ | ||
type: 'friendRequest', | ||
senderId: '3' as UserIdT, | ||
receiverId: '1' as UserIdT, | ||
sentAt: getTimeAgoDate(20), // 20 seconds ago | ||
}, | ||
{ | ||
type: 'friendRequest', | ||
senderId: '6' as UserIdT, | ||
receiverId: '1' as UserIdT, | ||
sentAt: getTimeAgoDate(3600), // 1 hour ago | ||
}, | ||
{ | ||
type: 'habitInvite', | ||
habitId: '4' as HabitIdT, | ||
senderId: '2' as UserIdT, | ||
receiverId: '1' as UserIdT, | ||
sentAt: getTimeAgoDate(1800), // 30 minutes ago | ||
}, | ||
{ | ||
type: 'nudge', | ||
habitId: '1' as HabitIdT, | ||
senderId: '4' as UserIdT, | ||
receiverId: '1' as UserIdT, | ||
sentAt: getTimeAgoDate(172800), // 2 days ago | ||
}, | ||
]; | ||
|
||
export const setMockNotifications = (newNotifications: NotificationT[]) => { | ||
mockNotifications.length = 0; | ||
mockNotifications.push(...newNotifications); | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
import { createQuery } from 'react-query-kit'; | ||
|
||
import { addTestDelay } from '../common'; | ||
import { mockNotifications } from './mock-notifications'; | ||
import { type FriendNotificationT, type HabitNotificationT } from './types'; | ||
|
||
type Response = (FriendNotificationT | HabitNotificationT)[]; | ||
type Variables = void; | ||
|
||
export const useNotifications = createQuery<Response, Variables, Error>({ | ||
queryKey: ['notifications'], | ||
fetcher: async () => { | ||
const myId = '1'; | ||
const notifications = await addTestDelay( | ||
mockNotifications.filter( | ||
(notification) => notification.receiverId === myId, | ||
), | ||
); | ||
return notifications; | ||
}, | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.