@opexa/portal-components 0.1.72 → 0.1.73

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,7 +1,5 @@
1
1
  'use client';
2
- import { App } from '@capacitor/app';
3
2
  import { useRouter } from 'next/navigation';
4
- import { useEffect, useRef } from 'react';
5
3
  import { useTimeout } from 'usehooks-ts';
6
4
  import { useShallow } from 'zustand/shallow';
7
5
  import { useGlobalStore } from '../../client/hooks/useGlobalStore.js';
@@ -9,51 +7,13 @@ import { useSessionHealthQuery } from '../../client/hooks/useSessionHealthQuery.
9
7
  import { useSessionQuery } from '../../client/hooks/useSessionQuery.js';
10
8
  import { useSignOutMutation } from '../../client/hooks/useSignOutMutation.js';
11
9
  import { toaster } from '../../client/utils/toaster.js';
12
- const SESSION_WATCH_INTERVAL = 5_000;
13
10
  export function SessionWatcher() {
14
11
  const router = useRouter();
15
12
  const sessionQuery = useSessionQuery();
16
- const isAuthenticated = sessionQuery.data?.status === 'authenticated';
17
- const isAuthenticatedRef = useRef(isAuthenticated);
18
- isAuthenticatedRef.current = isAuthenticated;
19
13
  const sessionHealthQuery = useSessionHealthQuery({
20
- enabled: false,
14
+ enabled: sessionQuery.data?.status === 'authenticated',
15
+ refetchInterval: 1000 * 5,
21
16
  });
22
- const refetchSessionHealthRef = useRef(sessionHealthQuery.refetch);
23
- refetchSessionHealthRef.current = sessionHealthQuery.refetch;
24
- useEffect(() => {
25
- let timeout = null;
26
- let isForeground = true;
27
- let stopped = false;
28
- const listener = App.addListener('appStateChange', ({ isActive }) => {
29
- isForeground = isActive;
30
- });
31
- const assignTimeout = () => {
32
- return setTimeout(async () => {
33
- if (isForeground && isAuthenticatedRef.current) {
34
- try {
35
- await refetchSessionHealthRef.current();
36
- }
37
- catch {
38
- // A failed check must not stop future session checks.
39
- }
40
- if (stopped) {
41
- return;
42
- }
43
- }
44
- timeout = assignTimeout();
45
- }, SESSION_WATCH_INTERVAL);
46
- };
47
- timeout = assignTimeout();
48
- return () => {
49
- stopped = true;
50
- if (timeout) {
51
- clearTimeout(timeout);
52
- timeout = null;
53
- }
54
- void listener.then((handle) => handle.remove()).catch(() => undefined);
55
- };
56
- }, []);
57
17
  const { gameLaunch, reset } = useGlobalStore(useShallow((ctx) => ({
58
18
  gameLaunch: ctx.gameLaunch,
59
19
  reset: ctx.reset,
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@opexa/portal-components",
3
- "version": "0.1.72",
3
+ "version": "0.1.73",
4
4
  "exports": {
5
5
  "./ui/*": {
6
6
  "types": "./dist/ui/*/index.d.ts",