-
Notifications
You must be signed in to change notification settings - Fork 129
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* feat: bulletin added * chore: deeplink fix * chore: schema updates * chore: linking and actions of bulletins * chore: move bulletins query to home screen for refetches
- Loading branch information
1 parent
bba2970
commit fe8958a
Showing
9 changed files
with
302 additions
and
44 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,72 @@ | ||
import React from "react" | ||
import { Linking } from "react-native" | ||
|
||
import { useNotifications } from "." | ||
import { NotificationCardUI } from "./notification-card-ui" | ||
import { | ||
BulletinsDocument, | ||
BulletinsQuery, | ||
useStatefulNotificationAcknowledgeMutation, | ||
} from "@app/graphql/generated" | ||
import { BLINK_DEEP_LINK_PREFIX } from "@app/config" | ||
|
||
type Props = { | ||
loading: boolean | ||
bulletins: BulletinsQuery | undefined | ||
} | ||
|
||
export const BulletinsCard: React.FC<Props> = ({ loading, bulletins }) => { | ||
const { cardInfo } = useNotifications() | ||
|
||
const [ack, { loading: ackLoading }] = useStatefulNotificationAcknowledgeMutation({ | ||
refetchQueries: [BulletinsDocument], | ||
}) | ||
|
||
if (loading) return null | ||
|
||
if ( | ||
bulletins && | ||
bulletins.me?.unacknowledgedStatefulNotificationsWithBulletinEnabled?.edges && | ||
bulletins.me?.unacknowledgedStatefulNotificationsWithBulletinEnabled?.edges.length > 0 | ||
) { | ||
return ( | ||
<> | ||
{bulletins.me?.unacknowledgedStatefulNotificationsWithBulletinEnabled?.edges.map( | ||
({ node: bulletin }) => ( | ||
<NotificationCardUI | ||
key={bulletin.id} | ||
title={bulletin.title} | ||
text={bulletin.body} | ||
action={async () => { | ||
ack({ variables: { input: { notificationId: bulletin.id } } }) | ||
if (bulletin.action?.__typename === "OpenDeepLinkAction") | ||
Linking.openURL(BLINK_DEEP_LINK_PREFIX + bulletin.action.deepLink) | ||
else if (bulletin.action?.__typename === "OpenExternalLinkAction") | ||
Linking.openURL(bulletin.action.url) | ||
}} | ||
dismissAction={() => | ||
ack({ variables: { input: { notificationId: bulletin.id } } }) | ||
} | ||
loading={ackLoading} | ||
/> | ||
), | ||
)} | ||
</> | ||
) | ||
} | ||
|
||
if (!cardInfo) { | ||
return null | ||
} | ||
|
||
return ( | ||
<NotificationCardUI | ||
title={cardInfo.title} | ||
text={cardInfo.text} | ||
icon={cardInfo.icon} | ||
action={cardInfo.action} | ||
loading={cardInfo.loading} | ||
dismissAction={cardInfo.dismissAction} | ||
/> | ||
) | ||
} |
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
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.