fix: reload sessions on tab focus instead of only on client change

The sessions screen was using useEffect with [client] to load sessions,
which only fired when the client object reference changed. If the app
was backgrounded and later foregrounded (common scenario on mobile),
the session list was never refreshed, showing stale data.

Replaced with useFocusEffect from expo-router so sessions are
reloaded every time the sessions tab is focused — including:
- Initial mount
- Coming back from background
- Switching tabs and returning
This commit is contained in:
Dzianis Vauchok
2026-05-26 07:38:32 +00:00
committed by Dennis V
parent 416ab446c4
commit d3d60f55ab

View File

@@ -1,4 +1,4 @@
import { useEffect, useCallback, useState, useRef } from "react"
import { useCallback, useState, useRef } from "react"
import {
View,
Text,
@@ -14,7 +14,7 @@ import {
KeyboardAvoidingView,
Platform,
} from "react-native"
import { router } from "expo-router"
import { router, useFocusEffect } from "expo-router"
import { Ionicons } from "@expo/vector-icons"
import { useSessions } from "../../src/stores/sessions"
import { useConnections } from "../../src/stores/connections"
@@ -135,12 +135,14 @@ export default function SessionsScreen() {
[switchDirectory, loadSessions, refreshProject],
)
useEffect(() => {
if (client) {
loadSessions()
refreshProject()
}
}, [client])
useFocusEffect(
useCallback(() => {
if (client) {
loadSessions()
refreshProject()
}
}, [client, loadSessions, refreshProject]),
)
const onRefresh = useCallback(async () => {
setRefreshing(true)