-
Notifications
You must be signed in to change notification settings - Fork 127
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
7db2d6a
commit 6ddc20c
Showing
12 changed files
with
382 additions
and
1 deletion.
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
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
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
90 changes: 90 additions & 0 deletions
90
app/screens/notification-history-screen/notification-history-screen.tsx
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,90 @@ | ||
import { gql } from "@apollo/client" | ||
import { Screen } from "@app/components/screen" | ||
import { useStatefulNotificationsQuery } from "@app/graphql/generated" | ||
import { useIsAuthed } from "@app/graphql/is-authed-context" | ||
import { useI18nContext } from "@app/i18n/i18n-react" | ||
import { testProps } from "@app/utils/testProps" | ||
import { useIsFocused } from "@react-navigation/native" | ||
import { Text, makeStyles, useTheme } from "@rneui/themed" | ||
import { FlatList, RefreshControl } from "react-native-gesture-handler" | ||
import { Notification } from "./notification" | ||
|
||
gql` | ||
query StatefulNotifications($after: String) { | ||
me { | ||
statefulNotifications(first: 10, after: $after) { | ||
nodes { | ||
id | ||
title | ||
body | ||
deepLink | ||
createdAt | ||
acknowledgedAt | ||
} | ||
pageInfo { | ||
endCursor | ||
hasNextPage | ||
hasPreviousPage | ||
startCursor | ||
} | ||
} | ||
} | ||
} | ||
` | ||
|
||
export const NotificationHistoryScreen = () => { | ||
const styles = useStyles() | ||
const { | ||
theme: { colors }, | ||
} = useTheme() | ||
const isFocused = useIsFocused() | ||
|
||
const { LL } = useI18nContext() | ||
|
||
const { data, fetchMore, refetch, loading } = useStatefulNotificationsQuery({ | ||
skip: !useIsAuthed(), | ||
}) | ||
const notifications = data?.me?.statefulNotifications | ||
|
||
const fetchNextNotificationsPage = () => { | ||
const pageInfo = notifications?.pageInfo | ||
|
||
if (pageInfo?.hasNextPage) { | ||
fetchMore({ | ||
variables: { | ||
after: pageInfo.endCursor, | ||
}, | ||
}) | ||
} | ||
} | ||
|
||
return ( | ||
<Screen> | ||
<FlatList | ||
{...testProps("notification-screen")} | ||
contentContainerStyle={styles.scrollViewContainer} | ||
refreshControl={ | ||
<RefreshControl | ||
refreshing={loading && isFocused} | ||
onRefresh={refetch} | ||
colors={[colors.primary]} // Android refresh indicator colors | ||
tintColor={colors.primary} // iOS refresh indicator color | ||
/> | ||
} | ||
data={notifications?.nodes} | ||
renderItem={({ item }) => <Notification {...item} />} | ||
onEndReached={fetchNextNotificationsPage} | ||
onEndReachedThreshold={0.5} | ||
onRefresh={refetch} | ||
refreshing={loading} | ||
ListEmptyComponent={ | ||
loading ? <></> : <Text>{LL.NotificationHistory.noNotifications()}</Text> | ||
} | ||
></FlatList> | ||
</Screen> | ||
) | ||
} | ||
|
||
const useStyles = makeStyles(() => ({ | ||
scrollViewContainer: {}, | ||
})) |
Oops, something went wrong.