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:
committed by
Dennis V
parent
416ab446c4
commit
d3d60f55ab
@@ -1,4 +1,4 @@
|
|||||||
import { useEffect, useCallback, useState, useRef } from "react"
|
import { useCallback, useState, useRef } from "react"
|
||||||
import {
|
import {
|
||||||
View,
|
View,
|
||||||
Text,
|
Text,
|
||||||
@@ -14,7 +14,7 @@ import {
|
|||||||
KeyboardAvoidingView,
|
KeyboardAvoidingView,
|
||||||
Platform,
|
Platform,
|
||||||
} from "react-native"
|
} from "react-native"
|
||||||
import { router } from "expo-router"
|
import { router, useFocusEffect } from "expo-router"
|
||||||
import { Ionicons } from "@expo/vector-icons"
|
import { Ionicons } from "@expo/vector-icons"
|
||||||
import { useSessions } from "../../src/stores/sessions"
|
import { useSessions } from "../../src/stores/sessions"
|
||||||
import { useConnections } from "../../src/stores/connections"
|
import { useConnections } from "../../src/stores/connections"
|
||||||
@@ -135,12 +135,14 @@ export default function SessionsScreen() {
|
|||||||
[switchDirectory, loadSessions, refreshProject],
|
[switchDirectory, loadSessions, refreshProject],
|
||||||
)
|
)
|
||||||
|
|
||||||
useEffect(() => {
|
useFocusEffect(
|
||||||
if (client) {
|
useCallback(() => {
|
||||||
loadSessions()
|
if (client) {
|
||||||
refreshProject()
|
loadSessions()
|
||||||
}
|
refreshProject()
|
||||||
}, [client])
|
}
|
||||||
|
}, [client, loadSessions, refreshProject]),
|
||||||
|
)
|
||||||
|
|
||||||
const onRefresh = useCallback(async () => {
|
const onRefresh = useCallback(async () => {
|
||||||
setRefreshing(true)
|
setRefreshing(true)
|
||||||
|
|||||||
Reference in New Issue
Block a user