Skip to content

Commit

Permalink
feat(mobile): Only sync store when user signed in and fix crash (#244)
Browse files Browse the repository at this point in the history
  • Loading branch information
bkdev98 committed Sep 1, 2024
1 parent 50ced7d commit e58dda3
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 3 deletions.
10 changes: 7 additions & 3 deletions apps/mobile/stores/core/store-interval-update.tsx
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import { useSuspenseQueries } from '@tanstack/react-query'
import { useAuth } from '@clerk/clerk-expo'
import { useQueries } from '@tanstack/react-query'
import type { FC } from 'react'
import { useCategoryListQueryOptions } from '../category/hooks'
import { useTransactionListQueryOptions } from '../transaction/hooks'
Expand All @@ -12,18 +13,21 @@ export type StoreIntervalUpdateProps = {
export const StoreIntervalUpdate: FC<StoreIntervalUpdateProps> = ({
interval = STORE_SYNC_INTERVAL,
}) => {
const { isSignedIn } = useAuth()

const queryOptions: StoreHookQueryOptions = {
refetchInterval: interval,
refetchIntervalInBackground: true,
enabled: isSignedIn,
}
const categoryListQueryOptions = useCategoryListQueryOptions(queryOptions)
const transactionListQueryOptions = useTransactionListQueryOptions(
undefined,
queryOptions,
)

useSuspenseQueries({
queries: [{ ...categoryListQueryOptions }, transactionListQueryOptions],
useQueries({
queries: [categoryListQueryOptions, transactionListQueryOptions],
})

return null
Expand Down
1 change: 1 addition & 0 deletions apps/mobile/stores/core/stores.d.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
export type StoreHookQueryOptions = {
refetchInterval?: number
refetchIntervalInBackground?: boolean
enabled?: boolean
}

0 comments on commit e58dda3

Please sign in to comment.