diff options
| author | MohamedBassem <me@mbassem.com> | 2024-03-30 17:04:47 +0000 |
|---|---|---|
| committer | MohamedBassem <me@mbassem.com> | 2024-03-30 17:04:47 +0000 |
| commit | 5edfe651861a9ff6e29ad18dbb18550d31c05f84 (patch) | |
| tree | 0e07f9a58a3ce8560b0b6c2ccc4968dbd88f9809 | |
| parent | a9c21819255860f97e5174181a357999dfba5d49 (diff) | |
| download | karakeep-5edfe651861a9ff6e29ad18dbb18550d31c05f84.tar.zst | |
fix(mobile): Refetch queries on app focus
| -rw-r--r-- | apps/mobile/app/dashboard/_layout.tsx | 15 |
1 files changed, 15 insertions, 0 deletions
diff --git a/apps/mobile/app/dashboard/_layout.tsx b/apps/mobile/app/dashboard/_layout.tsx index f1bb66d7..c9f7355b 100644 --- a/apps/mobile/app/dashboard/_layout.tsx +++ b/apps/mobile/app/dashboard/_layout.tsx @@ -1,7 +1,16 @@ +import type { AppStateStatus } from "react-native"; import { useEffect } from "react"; +import { AppState, Platform } from "react-native"; import { useRouter } from "expo-router"; import { Stack } from "expo-router/stack"; import { useIsLoggedIn } from "@/lib/session"; +import { focusManager } from "@tanstack/react-query"; + +function onAppStateChange(status: AppStateStatus) { + if (Platform.OS !== "web") { + focusManager.setFocused(status === "active"); + } +} export default function Dashboard() { const router = useRouter(); @@ -13,6 +22,12 @@ export default function Dashboard() { } }, [isLoggedIn]); + useEffect(() => { + const subscription = AppState.addEventListener("change", onAppStateChange); + + return () => subscription.remove(); + }, []); + return ( <Stack> <Stack.Screen |
