Skip to content

Commit

Permalink
fix: undoing changes on unreadCount variable since it changes with th…
Browse files Browse the repository at this point in the history
…e filter
  • Loading branch information
thoreyjona committed Jun 4, 2024
1 parent b333fc7 commit 5190cac
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 2 deletions.
1 change: 0 additions & 1 deletion apps/native/app/src/graphql/queries/inbox.graphql
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,6 @@ query ListDocuments($input: GetDocumentListInput!) {
...ListDocument
}
totalCount
unreadCount
}
}

Expand Down
19 changes: 18 additions & 1 deletion apps/native/app/src/screens/inbox/inbox.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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)

Expand All @@ -278,7 +296,6 @@ export const InboxScreen: NavigationFunctionComponent<{
bookmarked,
subjectContains: queryString,
})
const unreadCount = res?.data?.unreadCount ?? 0

useConnectivityIndicator({
componentId,
Expand Down

0 comments on commit 5190cac

Please sign in to comment.