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

fix: relay style pagination for notification history screen #3262

Draft
wants to merge 1 commit into
base: main
Choose a base branch
from
Draft
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
5 changes: 5 additions & 0 deletions app/graphql/cache.ts
Original file line number Diff line number Diff line change
Expand Up @@ -109,5 +109,10 @@ export const createCache = () =>
transactions: relayStylePagination(),
},
},
User: {
fields: {
statefulNotificationsWithoutBulletinEnabled: relayStylePagination(),
},
},
},
})
36 changes: 20 additions & 16 deletions app/graphql/generated.gql
Original file line number Diff line number Diff line change
Expand Up @@ -903,26 +903,30 @@ query SettingsScreen {

query StatefulNotifications($after: String) {
me {
statefulNotificationsWithoutBulletinEnabled(first: 20, after: $after) {
nodes {
id
title
body
createdAt
acknowledgedAt
bulletinEnabled
icon
action {
... on OpenDeepLinkAction {
deepLink
__typename
}
... on OpenExternalLinkAction {
url
statefulNotificationsWithoutBulletinEnabled(first: 10, after: $after) {
edges {
node {
id
title
body
createdAt
acknowledgedAt
bulletinEnabled
icon
action {
... on OpenDeepLinkAction {
deepLink
__typename
}
... on OpenExternalLinkAction {
url
__typename
}
__typename
}
__typename
}
cursor
__typename
}
pageInfo {
Expand Down
35 changes: 19 additions & 16 deletions app/graphql/generated.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2702,7 +2702,7 @@ export type StatefulNotificationsQueryVariables = Exact<{
}>;


export type StatefulNotificationsQuery = { readonly __typename: 'Query', readonly me?: { readonly __typename: 'User', readonly statefulNotificationsWithoutBulletinEnabled: { readonly __typename: 'StatefulNotificationConnection', readonly nodes: ReadonlyArray<{ readonly __typename: 'StatefulNotification', readonly id: string, readonly title: string, readonly body: string, readonly createdAt: number, readonly acknowledgedAt?: number | null, readonly bulletinEnabled: boolean, readonly icon?: Icon | null, readonly action?: { readonly __typename: 'OpenDeepLinkAction', readonly deepLink: string } | { readonly __typename: 'OpenExternalLinkAction', readonly url: string } | null }>, readonly pageInfo: { readonly __typename: 'PageInfo', readonly endCursor?: string | null, readonly hasNextPage: boolean, readonly hasPreviousPage: boolean, readonly startCursor?: string | null } } } | null };
export type StatefulNotificationsQuery = { readonly __typename: 'Query', readonly me?: { readonly __typename: 'User', readonly statefulNotificationsWithoutBulletinEnabled: { readonly __typename: 'StatefulNotificationConnection', 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 icon?: Icon | null, readonly action?: { readonly __typename: 'OpenDeepLinkAction', readonly deepLink: string } | { readonly __typename: 'OpenExternalLinkAction', readonly url: string } | null } }>, readonly pageInfo: { readonly __typename: 'PageInfo', readonly endCursor?: string | null, readonly hasNextPage: boolean, readonly hasPreviousPage: boolean, readonly startCursor?: string | null } } } | null };

export type StatefulNotificationAcknowledgeMutationVariables = Exact<{
input: StatefulNotificationAcknowledgeInput;
Expand Down Expand Up @@ -4896,23 +4896,26 @@ export type BusinessMapMarkersQueryResult = Apollo.QueryResult<BusinessMapMarker
export const StatefulNotificationsDocument = gql`
query StatefulNotifications($after: String) {
me {
statefulNotificationsWithoutBulletinEnabled(first: 20, after: $after) {
nodes {
id
title
body
createdAt
acknowledgedAt
bulletinEnabled
icon
action {
... on OpenDeepLinkAction {
deepLink
}
... on OpenExternalLinkAction {
url
statefulNotificationsWithoutBulletinEnabled(first: 10, after: $after) {
edges {
node {
id
title
body
createdAt
acknowledgedAt
bulletinEnabled
icon
action {
... on OpenDeepLinkAction {
deepLink
}
... on OpenExternalLinkAction {
url
}
}
}
cursor
}
pageInfo {
endCursor
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,23 +12,26 @@ import { Notification } from "./notification"
gql`
query StatefulNotifications($after: String) {
me {
statefulNotificationsWithoutBulletinEnabled(first: 20, after: $after) {
nodes {
id
title
body
createdAt
acknowledgedAt
bulletinEnabled
icon
action {
... on OpenDeepLinkAction {
deepLink
}
... on OpenExternalLinkAction {
url
statefulNotificationsWithoutBulletinEnabled(first: 10, after: $after) {
edges {
node {
id
title
body
createdAt
acknowledgedAt
bulletinEnabled
icon
action {
... on OpenDeepLinkAction {
deepLink
}
... on OpenExternalLinkAction {
url
}
}
}
cursor
}
pageInfo {
endCursor
Expand Down Expand Up @@ -58,13 +61,12 @@ export const NotificationHistoryScreen = () => {
const fetchNextNotificationsPage = () => {
const pageInfo = notifications?.pageInfo

if (pageInfo?.hasNextPage) {
if (pageInfo?.hasNextPage)
fetchMore({
variables: {
after: pageInfo.endCursor,
after: pageInfo?.endCursor,
},
})
}
}

return (
Expand All @@ -80,7 +82,7 @@ export const NotificationHistoryScreen = () => {
tintColor={colors.primary} // iOS refresh indicator color
/>
}
data={notifications?.nodes.filter((n) => !n.bulletinEnabled)}
data={notifications?.edges.map(({ node }) => node)}
renderItem={({ item }) => <Notification {...item} />}
onEndReached={fetchNextNotificationsPage}
onEndReachedThreshold={0.5}
Expand Down
Loading