Skip to content

Commit b39d85f

Browse files
feat: improve container status check triggering
- Add multiple triggers for container status checks: - When component mounts (tab becomes active) - When scripts data loads - Every 60 seconds via interval - Add manual 'Refresh Container Status' button for on-demand checking - Add console logging for debugging status check triggers - Ensure status checks happen reliably when switching to installed scripts tab Fixes issue where status checks weren't triggering when tab loads
1 parent dc62a08 commit b39d85f

File tree

1 file changed

+30
-0
lines changed

1 file changed

+30
-0
lines changed

src/app/_components/InstalledScriptsTab.tsx

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -165,6 +165,7 @@ export function InstalledScriptsTab() {
165165

166166
// Function to fetch container statuses
167167
const fetchContainerStatuses = () => {
168+
console.log('Fetching container statuses...', { scriptsCount: scripts.length });
168169
const containersWithIds = scripts
169170
.filter(script => script.container_id)
170171
.map(script => ({
@@ -180,6 +181,7 @@ export function InstalledScriptsTab() {
180181
} : undefined
181182
}));
182183

184+
console.log('Containers to check:', containersWithIds.length);
183185
if (containersWithIds.length > 0) {
184186
containerStatusMutation.mutate({ containers: containersWithIds });
185187
}
@@ -203,6 +205,26 @@ export function InstalledScriptsTab() {
203205
}
204206
}, [scripts.length]);
205207

208+
// Trigger status check when component becomes visible (tab is active)
209+
useEffect(() => {
210+
if (scripts.length > 0) {
211+
// Small delay to ensure component is fully rendered
212+
const timeoutId = setTimeout(() => {
213+
fetchContainerStatuses();
214+
}, 100);
215+
216+
return () => clearTimeout(timeoutId);
217+
}
218+
}, []); // Empty dependency array means this runs on mount
219+
220+
// Also trigger status check when scripts data loads
221+
useEffect(() => {
222+
if (scripts.length > 0 && !isLoading) {
223+
console.log('Scripts data loaded, triggering status check');
224+
fetchContainerStatuses();
225+
}
226+
}, [scriptsData, isLoading]);
227+
206228
// Update scripts with container statuses
207229
const scriptsWithStatus = scripts.map(script => ({
208230
...script,
@@ -493,6 +515,14 @@ export function InstalledScriptsTab() {
493515
>
494516
{showAutoDetectForm ? 'Cancel Auto-Detect' : '🔍 Auto-Detect LXC Containers (Must contain a tag with "community-script")'}
495517
</Button>
518+
<Button
519+
onClick={fetchContainerStatuses}
520+
disabled={containerStatusMutation.isPending || scripts.length === 0}
521+
variant="outline"
522+
size="default"
523+
>
524+
{containerStatusMutation.isPending ? '🔄 Checking...' : '🔄 Refresh Container Status'}
525+
</Button>
496526
</div>
497527

498528
{/* Add Script Form */}

0 commit comments

Comments
 (0)