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 6548285
Show file tree
Hide file tree
Showing 3 changed files with 135 additions and 125 deletions.
52 changes: 7 additions & 45 deletions app/components/notifications/bulletins.tsx
Original file line number Diff line number Diff line change
@@ -1,65 +1,27 @@
import React from "react"
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
156 changes: 78 additions & 78 deletions app/graphql/generated.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2496,14 +2496,6 @@ export type InviteQueryVariables = Exact<{ [key: string]: never; }>;

export type InviteQuery = { readonly __typename: 'Query', readonly me?: { readonly __typename: 'User', readonly id: string, readonly username?: string | null } | null };

export type BulletinsQueryVariables = Exact<{
first: Scalars['Int']['input'];
after?: InputMaybe<Scalars['String']['input']>;
}>;


export type BulletinsQuery = { readonly __typename: 'Query', readonly me?: { readonly __typename: 'User', readonly unacknowledgedStatefulNotificationsWithBulletinEnabled: { readonly __typename: 'StatefulNotificationConnection', readonly pageInfo: { readonly __typename: 'PageInfo', readonly endCursor?: string | null, readonly hasNextPage: boolean, readonly hasPreviousPage: boolean, readonly startCursor?: string | null }, readonly edges: ReadonlyArray<{ readonly __typename: 'StatefulNotificationEdge', readonly cursor: string, readonly node: { readonly __typename: 'StatefulNotification', readonly id: string, readonly title: string, readonly body: string, readonly createdAt: number, readonly acknowledgedAt?: number | null, readonly bulletinEnabled: boolean, readonly action?: { readonly __typename: 'OpenDeepLinkAction', readonly deepLink: string } | { readonly __typename: 'OpenExternalLinkAction', readonly url: string } | null } }> } } | null };

export type BtcPriceListQueryVariables = Exact<{
range: PriceGraphRange;
}>;
Expand Down Expand Up @@ -2692,6 +2684,14 @@ export type HomeUnauthedQueryVariables = Exact<{ [key: string]: never; }>;

export type HomeUnauthedQuery = { readonly __typename: 'Query', readonly globals?: { readonly __typename: 'Globals', readonly network: Network } | null, readonly currencyList: ReadonlyArray<{ readonly __typename: 'Currency', readonly id: string, readonly flag: string, readonly name: string, readonly symbol: string, readonly fractionDigits: number }> };

export type BulletinsQueryVariables = Exact<{
first: Scalars['Int']['input'];
after?: InputMaybe<Scalars['String']['input']>;
}>;


export type BulletinsQuery = { readonly __typename: 'Query', readonly me?: { readonly __typename: 'User', readonly unacknowledgedStatefulNotificationsWithBulletinEnabled: { readonly __typename: 'StatefulNotificationConnection', readonly pageInfo: { readonly __typename: 'PageInfo', readonly endCursor?: string | null, readonly hasNextPage: boolean, readonly hasPreviousPage: boolean, readonly startCursor?: string | null }, readonly edges: ReadonlyArray<{ readonly __typename: 'StatefulNotificationEdge', readonly cursor: string, readonly node: { readonly __typename: 'StatefulNotification', readonly id: string, readonly title: string, readonly body: string, readonly createdAt: number, readonly acknowledgedAt?: number | null, readonly bulletinEnabled: boolean, readonly action?: { readonly __typename: 'OpenDeepLinkAction', readonly deepLink: string } | { readonly __typename: 'OpenExternalLinkAction', readonly url: string } | null } }> } } | null };

export type BusinessMapMarkersQueryVariables = Exact<{ [key: string]: never; }>;


Expand Down Expand Up @@ -3350,76 +3350,6 @@ export type InviteQueryHookResult = ReturnType<typeof useInviteQuery>;
export type InviteLazyQueryHookResult = ReturnType<typeof useInviteLazyQuery>;
export type InviteSuspenseQueryHookResult = ReturnType<typeof useInviteSuspenseQuery>;
export type InviteQueryResult = Apollo.QueryResult<InviteQuery, InviteQueryVariables>;
export const BulletinsDocument = 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
}
}
}
}
`;

/**
* __useBulletinsQuery__
*
* To run a query within a React component, call `useBulletinsQuery` and pass it any options that fit your needs.
* When your component renders, `useBulletinsQuery` returns an object from Apollo Client that contains loading, error, and data properties
* you can use to render your UI.
*
* @param baseOptions options that will be passed into the query, supported options are listed on: https://www.apollographql.com/docs/react/api/react-hooks/#options;
*
* @example
* const { data, loading, error } = useBulletinsQuery({
* variables: {
* first: // value for 'first'
* after: // value for 'after'
* },
* });
*/
export function useBulletinsQuery(baseOptions: Apollo.QueryHookOptions<BulletinsQuery, BulletinsQueryVariables> & ({ variables: BulletinsQueryVariables; skip?: boolean; } | { skip: boolean; }) ) {
const options = {...defaultOptions, ...baseOptions}
return Apollo.useQuery<BulletinsQuery, BulletinsQueryVariables>(BulletinsDocument, options);
}
export function useBulletinsLazyQuery(baseOptions?: Apollo.LazyQueryHookOptions<BulletinsQuery, BulletinsQueryVariables>) {
const options = {...defaultOptions, ...baseOptions}
return Apollo.useLazyQuery<BulletinsQuery, BulletinsQueryVariables>(BulletinsDocument, options);
}
export function useBulletinsSuspenseQuery(baseOptions?: Apollo.SuspenseQueryHookOptions<BulletinsQuery, BulletinsQueryVariables>) {
const options = {...defaultOptions, ...baseOptions}
return Apollo.useSuspenseQuery<BulletinsQuery, BulletinsQueryVariables>(BulletinsDocument, options);
}
export type BulletinsQueryHookResult = ReturnType<typeof useBulletinsQuery>;
export type BulletinsLazyQueryHookResult = ReturnType<typeof useBulletinsLazyQuery>;
export type BulletinsSuspenseQueryHookResult = ReturnType<typeof useBulletinsSuspenseQuery>;
export type BulletinsQueryResult = Apollo.QueryResult<BulletinsQuery, BulletinsQueryVariables>;
export const BtcPriceListDocument = gql`
query btcPriceList($range: PriceGraphRange!) {
btcPriceList(range: $range) {
Expand Down Expand Up @@ -4846,6 +4776,76 @@ export type HomeUnauthedQueryHookResult = ReturnType<typeof useHomeUnauthedQuery
export type HomeUnauthedLazyQueryHookResult = ReturnType<typeof useHomeUnauthedLazyQuery>;
export type HomeUnauthedSuspenseQueryHookResult = ReturnType<typeof useHomeUnauthedSuspenseQuery>;
export type HomeUnauthedQueryResult = Apollo.QueryResult<HomeUnauthedQuery, HomeUnauthedQueryVariables>;
export const BulletinsDocument = 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
}
}
}
}
`;

/**
* __useBulletinsQuery__
*
* To run a query within a React component, call `useBulletinsQuery` and pass it any options that fit your needs.
* When your component renders, `useBulletinsQuery` returns an object from Apollo Client that contains loading, error, and data properties
* you can use to render your UI.
*
* @param baseOptions options that will be passed into the query, supported options are listed on: https://www.apollographql.com/docs/react/api/react-hooks/#options;
*
* @example
* const { data, loading, error } = useBulletinsQuery({
* variables: {
* first: // value for 'first'
* after: // value for 'after'
* },
* });
*/
export function useBulletinsQuery(baseOptions: Apollo.QueryHookOptions<BulletinsQuery, BulletinsQueryVariables> & ({ variables: BulletinsQueryVariables; skip?: boolean; } | { skip: boolean; }) ) {
const options = {...defaultOptions, ...baseOptions}
return Apollo.useQuery<BulletinsQuery, BulletinsQueryVariables>(BulletinsDocument, options);
}
export function useBulletinsLazyQuery(baseOptions?: Apollo.LazyQueryHookOptions<BulletinsQuery, BulletinsQueryVariables>) {
const options = {...defaultOptions, ...baseOptions}
return Apollo.useLazyQuery<BulletinsQuery, BulletinsQueryVariables>(BulletinsDocument, options);
}
export function useBulletinsSuspenseQuery(baseOptions?: Apollo.SuspenseQueryHookOptions<BulletinsQuery, BulletinsQueryVariables>) {
const options = {...defaultOptions, ...baseOptions}
return Apollo.useSuspenseQuery<BulletinsQuery, BulletinsQueryVariables>(BulletinsDocument, options);
}
export type BulletinsQueryHookResult = ReturnType<typeof useBulletinsQuery>;
export type BulletinsLazyQueryHookResult = ReturnType<typeof useBulletinsLazyQuery>;
export type BulletinsSuspenseQueryHookResult = ReturnType<typeof useBulletinsSuspenseQuery>;
export type BulletinsQueryResult = Apollo.QueryResult<BulletinsQuery, BulletinsQueryVariables>;
export const BusinessMapMarkersDocument = gql`
query businessMapMarkers {
businessMapMarkers {
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 6548285

Please sign in to comment.