From 5edfe651861a9ff6e29ad18dbb18550d31c05f84 Mon Sep 17 00:00:00 2001
From: MohamedBassem <me@mbassem.com>
Date: Sat, 30 Mar 2024 17:04:47 +0000
Subject: fix(mobile): Refetch queries on app focus

---
 apps/mobile/app/dashboard/_layout.tsx | 15 +++++++++++++++
 1 file changed, 15 insertions(+)

(limited to 'apps/mobile/app/dashboard/_layout.tsx')

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
-- 
cgit v1.2.3-70-g09d2

