diff --git a/apps/native/app/src/graphql/queries/inbox.graphql b/apps/native/app/src/graphql/queries/inbox.graphql index 716248a9a003..f6ff407ded03 100644 --- a/apps/native/app/src/graphql/queries/inbox.graphql +++ b/apps/native/app/src/graphql/queries/inbox.graphql @@ -12,7 +12,6 @@ query ListDocuments($input: GetDocumentListInput!) { ...ListDocument } totalCount - unreadCount } } diff --git a/apps/native/app/src/screens/inbox/inbox.tsx b/apps/native/app/src/screens/inbox/inbox.tsx index ae6ed6203ee9..5450f864966d 100644 --- a/apps/native/app/src/screens/inbox/inbox.tsx +++ b/apps/native/app/src/screens/inbox/inbox.tsx @@ -136,6 +136,23 @@ function useThrottleState(state: string, delay = 500) { return throttledState } +const useUnreadCount = () => { + const res = useListDocumentsQuery({ + fetchPolicy: 'cache-first', + variables: { + input: { + page: 1, + pageSize: 50, + opened: false, + }, + }, + }) + const unopened = res?.data?.listDocumentsV2?.data?.filter( + (item) => item.opened === false, + ) + return unopened?.length ?? 0 +} + type Filters = { opened?: boolean archived?: boolean @@ -269,6 +286,7 @@ export const InboxScreen: NavigationFunctionComponent<{ const [query, setQuery] = useState('') const queryString = useThrottleState(query) const theme = useTheme() + const unreadCount = useUnreadCount() const [visible, setVisible] = useState(false) const [refetching, setRefetching] = useState(false) @@ -278,7 +296,6 @@ export const InboxScreen: NavigationFunctionComponent<{ bookmarked, subjectContains: queryString, }) - const unreadCount = res?.data?.unreadCount ?? 0 useConnectivityIndicator({ componentId,