@opexa/portal-components 0.0.1102 → 0.0.1103
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
|
@@ -1,16 +1,38 @@
|
|
|
1
|
-
import { useQuery } from '@tanstack/react-query';
|
|
1
|
+
import { useQuery, useQueryClient } from '@tanstack/react-query';
|
|
2
|
+
import { useEffect } from 'react';
|
|
2
3
|
import { getJackpotsCount, } from '../../services/report.js';
|
|
3
|
-
import {
|
|
4
|
+
import { getQueryClient } from '../../utils/getQueryClient.js';
|
|
5
|
+
import { getJackpotsCountQueryKey, getSessionQueryKey, } from '../../utils/queryKeys.js';
|
|
6
|
+
import { getSession } from '../services/getSession.js';
|
|
7
|
+
import { useSessionQuery } from './useSessionQuery.js';
|
|
4
8
|
export const useJackpotsCountQuery = (input, config) => {
|
|
9
|
+
const sessionQuery = useSessionQuery();
|
|
10
|
+
const queryClient = useQueryClient();
|
|
11
|
+
// biome-ignore lint/correctness/useExhaustiveDependencies: intentionally only re-runs on session status change; input is stable per call site and queryClient is stable from useQueryClient
|
|
12
|
+
useEffect(() => {
|
|
13
|
+
if (sessionQuery.data?.status === 'authenticated') {
|
|
14
|
+
queryClient.invalidateQueries({
|
|
15
|
+
queryKey: getJackpotsCountQueryKey(input),
|
|
16
|
+
});
|
|
17
|
+
}
|
|
18
|
+
}, [sessionQuery.data?.status]);
|
|
5
19
|
return useQuery({
|
|
6
20
|
refetchOnMount: false,
|
|
7
21
|
refetchOnReconnect: false,
|
|
8
22
|
refetchOnWindowFocus: false,
|
|
9
23
|
refetchInterval: 3000, // 3 seconds
|
|
24
|
+
staleTime: 0,
|
|
10
25
|
...config,
|
|
11
26
|
queryKey: getJackpotsCountQueryKey(input),
|
|
12
27
|
queryFn: async ({ signal }) => {
|
|
13
|
-
|
|
28
|
+
const session = await getQueryClient().fetchQuery({
|
|
29
|
+
queryKey: getSessionQueryKey(),
|
|
30
|
+
queryFn: async () => getSession(),
|
|
31
|
+
});
|
|
32
|
+
const authHeader = session.status === 'authenticated'
|
|
33
|
+
? { Authorization: `Bearer ${session.token}` }
|
|
34
|
+
: {};
|
|
35
|
+
return await getJackpotsCount(input, { signal, headers: authHeader });
|
|
14
36
|
},
|
|
15
37
|
});
|
|
16
38
|
};
|
|
@@ -1,12 +1,34 @@
|
|
|
1
|
-
import { useQuery } from '@tanstack/react-query';
|
|
1
|
+
import { useQuery, useQueryClient } from '@tanstack/react-query';
|
|
2
|
+
import { useEffect } from 'react';
|
|
2
3
|
import { getTournamentsCount, } from '../../services/report.js';
|
|
3
|
-
import {
|
|
4
|
+
import { getQueryClient } from '../../utils/getQueryClient.js';
|
|
5
|
+
import { getTournamentsCountQueryKey, getSessionQueryKey, } from '../../utils/queryKeys.js';
|
|
6
|
+
import { getSession } from '../services/getSession.js';
|
|
7
|
+
import { useSessionQuery } from './useSessionQuery.js';
|
|
4
8
|
export const useTournamentsCountQuery = (input, config) => {
|
|
9
|
+
const sessionQuery = useSessionQuery();
|
|
10
|
+
const queryClient = useQueryClient();
|
|
11
|
+
// biome-ignore lint/correctness/useExhaustiveDependencies: intentionally only re-runs on session status change; input is stable per call site and queryClient is stable from useQueryClient
|
|
12
|
+
useEffect(() => {
|
|
13
|
+
if (sessionQuery.data?.status === 'authenticated') {
|
|
14
|
+
queryClient.invalidateQueries({
|
|
15
|
+
queryKey: getTournamentsCountQueryKey(input),
|
|
16
|
+
});
|
|
17
|
+
}
|
|
18
|
+
}, [sessionQuery.data?.status]);
|
|
5
19
|
return useQuery({
|
|
20
|
+
staleTime: 0,
|
|
6
21
|
...config,
|
|
7
22
|
queryKey: getTournamentsCountQueryKey(input),
|
|
8
23
|
queryFn: async ({ signal }) => {
|
|
9
|
-
|
|
24
|
+
const session = await getQueryClient().fetchQuery({
|
|
25
|
+
queryKey: getSessionQueryKey(),
|
|
26
|
+
queryFn: async () => getSession(),
|
|
27
|
+
});
|
|
28
|
+
const authHeader = session.status === 'authenticated'
|
|
29
|
+
? { Authorization: `Bearer ${session.token}` }
|
|
30
|
+
: {};
|
|
31
|
+
return await getTournamentsCount(input, { signal, headers: authHeader });
|
|
10
32
|
},
|
|
11
33
|
});
|
|
12
34
|
};
|