Skip to content

Commit

Permalink
Merge pull request #563 from lifeomic/retry-queries-on-interval
Browse files Browse the repository at this point in the history
Retry queries on interval
  • Loading branch information
bruce-glazier authored May 24, 2024
2 parents 5e2ff0a + 4aa95ad commit efc6c37
Show file tree
Hide file tree
Showing 3 changed files with 17 additions and 10 deletions.
4 changes: 2 additions & 2 deletions example/AppDemo.tsx
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import React from 'react';
import { authConfig, baseURL } from './storybook/helpers/oauthConfig';
import { authConfig, baseURL, account } from './storybook/helpers/oauthConfig';
import { DeveloperConfigProvider, RootProviders, LoggedInStack } from '../src';
import { FhirExampleScreen } from './src/screens/FhirExampleScreen';

Expand All @@ -22,7 +22,7 @@ function App() {
showPreLoginWarning: false,
}}
>
<RootProviders account="mockaccount" authConfig={authConfig}>
<RootProviders account={account ?? 'mockaccount'} authConfig={authConfig}>
<LoggedInStack />
</RootProviders>
</DeveloperConfigProvider>
Expand Down
3 changes: 2 additions & 1 deletion example/storybook/helpers/oauthConfig.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { AuthConfiguration } from 'react-native-app-auth';
import { oauthConfig, apiBaseUrl } from '../../config';
import { oauthConfig, apiBaseUrl, accountToUse } from '../../config';

export const authConfig: AuthConfiguration = {
clientId: oauthConfig.clientId,
Expand All @@ -18,3 +18,4 @@ export const authConfig: AuthConfiguration = {
};

export const baseURL = apiBaseUrl;
export const account = accountToUse;
20 changes: 13 additions & 7 deletions src/hooks/useActiveProject.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -156,13 +156,19 @@ export const ActiveProjectContextProvider: React.FC<ActiveProjectContextProvider
const state = calculateState();

useEffect(() => {
if (
!query.isRefetching &&
state.status === 'not-a-patient' &&
keepWaitingForPatientId
) {
query.refetchAll();
}
const intervalId = setInterval(() => {
if (
!query.isRefetching &&
state.status === 'not-a-patient' &&
keepWaitingForPatientId
) {
query.refetchAll();
} else {
clearInterval(intervalId);
}
}, 2000);

return () => clearInterval(intervalId);
}, [keepWaitingForPatientId, query, state.status]);

// This effect handles setting the initial value in async storage.
Expand Down

0 comments on commit efc6c37

Please sign in to comment.