Skip to content

Commit

Permalink
chore: move bulletins query to home screen for refetches
Browse files Browse the repository at this point in the history
  • Loading branch information
sandipndev committed May 14, 2024
1 parent 2eb6380 commit 89ebd17
Show file tree
Hide file tree
Showing 2 changed files with 56 additions and 47 deletions.
51 changes: 6 additions & 45 deletions app/components/notifications/bulletins.tsx
Original file line number Diff line number Diff line change
@@ -1,65 +1,26 @@
import { Linking } from "react-native"
import { gql } from "@apollo/client"

import { useNotifications } from "."
import { NotificationCardUI } from "./notification-card-ui"
import {
BulletinsDocument,
useBulletinsQuery,
BulletinsQuery,
useStatefulNotificationAcknowledgeMutation,
} from "@app/graphql/generated"
import { BLINK_DEEP_LINK_PREFIX } from "@app/config"

gql`
query Bulletins($first: Int!, $after: String) {
me {
unacknowledgedStatefulNotificationsWithBulletinEnabled(
first: $first
after: $after
) {
pageInfo {
endCursor
hasNextPage
hasPreviousPage
startCursor
}
edges {
node {
id
title
body
createdAt
acknowledgedAt
bulletinEnabled
action {
... on OpenDeepLinkAction {
deepLink
}
... on OpenExternalLinkAction {
url
}
}
}
cursor
}
}
}
}
`
type Props = {
loading: boolean
bulletins: BulletinsQuery | undefined
}

export const BulletinsCard: React.FC = () => {
export const BulletinsCard: React.FC<Props> = ({ loading, bulletins }) => {
const { cardInfo } = useNotifications()

const [ack, { loading: ackLoading }] = useStatefulNotificationAcknowledgeMutation({
refetchQueries: [BulletinsDocument],
})

const { data: bulletins, loading } = useBulletinsQuery({
fetchPolicy: "cache-and-network",
variables: { first: 1 },
pollInterval: 30000,
})

if (loading) return null

if (
Expand Down
52 changes: 50 additions & 2 deletions app/screens/home-screen/home-screen.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ import {
TransactionFragment,
TxDirection,
TxStatus,
useBulletinsQuery,
useHasPromptedSetDefaultAccountQuery,
useHomeAuthedQuery,
useHomeUnauthedQuery,
Expand Down Expand Up @@ -92,6 +93,41 @@ gql`
fractionDigits
}
}
query Bulletins($first: Int!, $after: String) {
me {
unacknowledgedStatefulNotificationsWithBulletinEnabled(
first: $first
after: $after
) {
pageInfo {
endCursor
hasNextPage
hasPreviousPage
startCursor
}
edges {
node {
id
title
body
createdAt
acknowledgedAt
bulletinEnabled
action {
... on OpenDeepLinkAction {
deepLink
}
... on OpenExternalLinkAction {
url
}
}
}
cursor
}
}
}
}
`

export const HomeScreen: React.FC = () => {
Expand Down Expand Up @@ -161,15 +197,27 @@ export const HomeScreen: React.FC = () => {
nextFetchPolicy: "cache-and-network",
})

// load bulletins on home screen
const {
data: bulletins,
loading: bulletinsLoading,
refetch: refetchBulletins,
} = useBulletinsQuery({
skip: !isAuthed,
fetchPolicy: "cache-and-network",
variables: { first: 1 },
})

const loading = loadingAuthed || loadingPrice || loadingUnauthed || loadingSettings

const refetch = React.useCallback(() => {
if (isAuthed) {
refetchRealtimePrice()
refetchAuthed()
refetchUnauthed()
refetchBulletins()
}
}, [isAuthed, refetchAuthed, refetchRealtimePrice, refetchUnauthed])
}, [isAuthed, refetchAuthed, refetchBulletins, refetchRealtimePrice, refetchUnauthed])

const pendingIncomingTransactions =
dataAuthed?.me?.defaultAccount?.pendingIncomingTransactions
Expand Down Expand Up @@ -382,7 +430,7 @@ export const HomeScreen: React.FC = () => {
</View>
))}
</View>
<BulletinsCard />
<BulletinsCard loading={bulletinsLoading} bulletins={bulletins} />
<View>
{recentTransactionsData && (
<>
Expand Down

0 comments on commit 89ebd17

Please sign in to comment.