Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
124 changes: 109 additions & 15 deletions webui/src/components/ContainerList.svelte
Original file line number Diff line number Diff line change
Expand Up @@ -5,9 +5,10 @@
containers: Container[];
displayMode: 'compact' | 'standard';
onAction: (containerId: string, action: 'start' | 'stop' | 'restart', isSelf: boolean) => void;
loadingActions: Map<string, 'start' | 'stop' | 'restart'>;
}

let { containers, displayMode, onAction }: Props = $props();
let { containers, displayMode, onAction, loadingActions }: Props = $props();

const stateEmojis: Record<string, string> = {
created: '🆕',
Expand All @@ -25,6 +26,16 @@
starting: '🔄',
none: ''
};

// Helper function to check if a specific action is loading for a container
function isActionLoading(containerId: string, action: 'start' | 'stop' | 'restart'): boolean {
return loadingActions.get(containerId) === action;
}

// Helper function to check if any action is loading for a container
function isContainerLoading(containerId: string): boolean {
return loadingActions.has(containerId);
}
</script>

<div class="container-list" class:compact={displayMode === 'compact'}>
Expand Down Expand Up @@ -52,36 +63,57 @@
{#if container.state === 'running'}
<button
class="action-btn-compact stop"
class:loading={isActionLoading(container.id, 'stop')}
onclick={() => onAction(container.id, 'stop', container.is_self ?? false)}
disabled={container.is_self}
disabled={container.is_self || isContainerLoading(container.id)}
title={container.is_self ? "无法停止本应用容器" : "停止"}
>
⏸️
{#if isActionLoading(container.id, 'stop')}
<span class="spinner-compact"></span>
{:else}
⏸️
{/if}
</button>
<button
class="action-btn-compact restart"
class:loading={isActionLoading(container.id, 'restart')}
onclick={() => onAction(container.id, 'restart', container.is_self ?? false)}
disabled={container.is_self}
disabled={container.is_self || isContainerLoading(container.id)}
title={container.is_self ? "无法重启本应用容器" : "重启"}
>
🔄
{#if isActionLoading(container.id, 'restart')}
<span class="spinner-compact"></span>
{:else}
🔄
{/if}
</button>
{:else if ['exited', 'created', 'dead'].includes(container.state)}
<button
class="action-btn-compact start"
class:loading={isActionLoading(container.id, 'start')}
onclick={() => onAction(container.id, 'start', container.is_self ?? false)}
disabled={isContainerLoading(container.id)}
title="启动"
>
▶️
{#if isActionLoading(container.id, 'start')}
<span class="spinner-compact"></span>
{:else}
▶️
{/if}
</button>
{:else}
<button
class="action-btn-compact restart"
class:loading={isActionLoading(container.id, 'restart')}
onclick={() => onAction(container.id, 'restart', container.is_self ?? false)}
disabled={container.is_self}
disabled={container.is_self || isContainerLoading(container.id)}
title={container.is_self ? "无法重启本应用容器" : "重启"}
>
🔄
{#if isActionLoading(container.id, 'restart')}
<span class="spinner-compact"></span>
{:else}
🔄
{/if}
</button>
{/if}
<a
Expand Down Expand Up @@ -117,35 +149,60 @@
{#if container.state === 'running'}
<button
class="action-btn stop"
class:loading={isActionLoading(container.id, 'stop')}
onclick={() => onAction(container.id, 'stop', container.is_self ?? false)}
disabled={container.is_self}
disabled={container.is_self || isContainerLoading(container.id)}
title={container.is_self ? "无法停止本应用容器" : ""}
>
⏸️ 停止
{#if isActionLoading(container.id, 'stop')}
<span class="spinner"></span>
{:else}
⏸️
{/if}
停止
</button>
<button
class="action-btn restart"
class:loading={isActionLoading(container.id, 'restart')}
onclick={() => onAction(container.id, 'restart', container.is_self ?? false)}
disabled={container.is_self}
disabled={container.is_self || isContainerLoading(container.id)}
title={container.is_self ? "无法重启本应用容器" : ""}
>
🔄 重启
{#if isActionLoading(container.id, 'restart')}
<span class="spinner"></span>
{:else}
🔄
{/if}
重启
</button>
{:else if ['exited', 'created', 'dead'].includes(container.state)}
<button
class="action-btn start"
class:loading={isActionLoading(container.id, 'start')}
onclick={() => onAction(container.id, 'start', container.is_self ?? false)}
disabled={isContainerLoading(container.id)}
>
▶️ 启动
{#if isActionLoading(container.id, 'start')}
<span class="spinner"></span>
{:else}
▶️
{/if}
启动
</button>
{:else}
<button
class="action-btn restart"
class:loading={isActionLoading(container.id, 'restart')}
onclick={() => onAction(container.id, 'restart', container.is_self ?? false)}
disabled={container.is_self}
disabled={container.is_self || isContainerLoading(container.id)}
title={container.is_self ? "无法重启本应用容器" : ""}
>
🔄 重启
{#if isActionLoading(container.id, 'restart')}
<span class="spinner"></span>
{:else}
🔄
{/if}
重启
</button>
{/if}
<a
Expand Down Expand Up @@ -333,6 +390,22 @@
cursor: not-allowed;
}

.action-btn.loading {
opacity: 0.8;
position: relative;
}

/* Spinner for standard mode buttons */
.spinner {
display: inline-block;
width: 12px;
height: 12px;
border: 2px solid rgba(255, 255, 255, 0.3);
border-top: 2px solid white;
border-radius: 50%;
animation: spin 0.6s linear infinite;
}

.action-btn.logs {
background: var(--color-secondary, #525252);
color: white;
Expand Down Expand Up @@ -430,6 +503,27 @@
cursor: not-allowed;
}

.action-btn-compact.loading {
opacity: 0.8;
}

/* Spinner for compact mode buttons */
.spinner-compact {
display: inline-block;
width: 10px;
height: 10px;
border: 2px solid rgba(0, 0, 0, 0.2);
border-top: 2px solid rgba(0, 0, 0, 0.6);
border-radius: 50%;
animation: spin 0.6s linear infinite;
}

/* Keyframe animation for spinners */
@keyframes spin {
from { transform: rotate(0deg); }
to { transform: rotate(360deg); }
}

.action-btn-compact.logs {
text-decoration: none;
display: inline-flex;
Expand Down
24 changes: 23 additions & 1 deletion webui/src/pages/Home.svelte
Original file line number Diff line number Diff line change
Expand Up @@ -19,10 +19,14 @@
let availableLabelKeys: string[] = [];
let filterText: string = '';

// Track loading state for individual container actions
let loadingActions = new Map<string, 'start' | 'stop' | 'restart'>();

// Track if component has mounted to prevent reload during initial setup
let isMounted = false;
let filterDebounceTimer: number | null = null;
let filterDebounceTimer: number | undefined = undefined;

Copilot AI Jan 16, 2026

Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The type change from number | null to number | undefined is inconsistent with other timer variables in the codebase. Files like Volumes.svelte and VolumeExplorer.svelte use number | null for their timeout IDs. Consider changing this to number | null = null for consistency across the codebase, or update all timer variables to use the same pattern.

Suggested change
let filterDebounceTimer: number | undefined = undefined;
let filterDebounceTimer: number | null = null;

Copilot uses AI. Check for mistakes.
const FILTER_DEBOUNCE_DELAY = 500; // milliseconds to wait before reloading after filter text changes
const REFRESH_DELAY = 200; // milliseconds to wait after action before refreshing



Expand Down Expand Up @@ -351,7 +355,14 @@

try {
actionError = '';
// Set loading state for this specific action
loadingActions = new Map(loadingActions).set(containerId, action);

await containerApi.controlContainer({ containerId, action });

// Wait before refreshing to allow container state to stabilize
await new Promise(resolve => setTimeout(resolve, REFRESH_DELAY));

await loadContainers();
} catch (err) {
const errorMessage = err instanceof Error ? err.message : '未知错误';
Expand All @@ -362,6 +373,11 @@
}
console.error('Container action failed:', err);
setTimeout(() => { actionError = ''; }, 3000);
} finally {
// Clear loading state for this container
const newLoadingActions = new Map(loadingActions);
newLoadingActions.delete(containerId);
loadingActions = newLoadingActions;
}
}

Expand Down Expand Up @@ -503,6 +519,7 @@
containers={projectContainers}
displayMode={displayMode}
onAction={handleAction}
loadingActions={loadingActions}
/>
{/if}
</div>
Expand All @@ -528,6 +545,7 @@
containers={ungrouped}
displayMode={displayMode}
onAction={handleAction}
loadingActions={loadingActions}
/>
{/if}
</div>
Expand Down Expand Up @@ -573,6 +591,7 @@
containers={labelContainers}
displayMode={displayMode}
onAction={handleAction}
loadingActions={loadingActions}
/>
{/if}
</div>
Expand All @@ -598,6 +617,7 @@
containers={ungrouped}
displayMode={displayMode}
onAction={handleAction}
loadingActions={loadingActions}
/>
{/if}
</div>
Expand Down Expand Up @@ -640,6 +660,7 @@
containers={groupContainers}
displayMode={displayMode}
onAction={handleAction}
loadingActions={loadingActions}
/>
{/if}
</div>
Expand All @@ -651,6 +672,7 @@
containers={sortedContainers}
displayMode={displayMode}
onAction={handleAction}
loadingActions={loadingActions}
/>
{/if}
{/if}
Expand Down