Skip to content

Commit de78fcd

Browse files
authored
Only re-render CharmList when connection status actually changes (#1038)
* Only re-render CharmList when connection status actually changes * Update types
1 parent 4a40833 commit de78fcd

File tree

2 files changed

+10
-5
lines changed

2 files changed

+10
-5
lines changed

jumble/src/contexts/SyncStatusContext.tsx

+8-3
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@ import { useCharmManager } from "@/contexts/CharmManagerContext.tsx";
1111
interface SyncStatusContextType {
1212
isSyncing: boolean;
1313
lastSyncTime: Date | null;
14+
hasConnected: boolean;
1415
}
1516

1617
const SyncStatusContext = createContext<SyncStatusContextType | undefined>(
@@ -27,7 +28,8 @@ export function SyncStatusProvider({
2728
intervalMs = 50,
2829
}: SyncStatusProviderProps) {
2930
const [isSyncing, setIsSyncing] = useState(true);
30-
const [lastSyncTime, setLastSyncTime] = useState<Date | null>(null);
31+
const lastSyncTimeRef = useRef<Date | null>(null);
32+
const [hasConnected, setHasConnected] = useState(false);
3133
const { charmManager } = useCharmManager();
3234
const isCheckingSyncRef = useRef(false);
3335

@@ -44,7 +46,10 @@ export function SyncStatusProvider({
4446
await charmManager.synced();
4547

4648
if (isMounted) {
47-
setLastSyncTime(new Date());
49+
lastSyncTimeRef.current = new Date();
50+
if (!hasConnected) {
51+
setHasConnected(true);
52+
}
4853
}
4954
} catch (error) {
5055
console.error("Sync error:", error);
@@ -68,7 +73,7 @@ export function SyncStatusProvider({
6873
};
6974
}, [charmManager, intervalMs]);
7075

71-
const value = { isSyncing, lastSyncTime };
76+
const value = { isSyncing, lastSyncTime: lastSyncTimeRef.current, hasConnected };
7277

7378
return (
7479
<SyncStatusContext.Provider value={value}>

jumble/src/views/CharmList.tsx

+2-2
Original file line numberDiff line numberDiff line change
@@ -100,9 +100,9 @@ export default function CharmList() {
100100
const [charms] = useCell(charmManager.getCharms());
101101
const [trash] = useCell(charmManager.getTrash());
102102

103-
const { lastSyncTime } = useSyncedStatus();
103+
const { hasConnected } = useSyncedStatus();
104104

105-
if (lastSyncTime == null) {
105+
if (!hasConnected) {
106106
return (
107107
<div className="flex flex-col items-center justify-center h-[70vh] text-center p-8">
108108
<div className="mb-6">

0 commit comments

Comments
 (0)