Files
Jellymove/ui/src/lib/Jobs.svelte
T
IxianPixel 2bd4489b1a
CI / test (push) Successful in 1m14s
Update library lists when a move finishes (#1)
The Library now follows moves on both servers: an item shows "Moving to …" while it moves and "Moved to …" until the source's Jellyfin drops
it after its rescan; the list reloads when a move finishes and checks again every 20 s for a few minutes. The destination shows the new item
straight away.
2026-11-06 17:21:22 +00:00

251 lines
6.1 KiB
Svelte

<script lang="ts">
import { api, bytes, STAGE_LABEL, STAGES, type Job } from './api';
import { moves, trackMove } from './moves.svelte';
interface Props {
localName: string;
}
let { localName }: Props = $props();
let retryError = $state<string | null>(null);
let open = $state<Record<string, boolean>>({});
const sorted = $derived(Object.values(moves.jobs).sort((a, b) => b.created.localeCompare(a.created)));
const error = $derived(retryError ?? moves.error);
async function retry(id: string) {
try {
trackMove(await api.retry(id));
retryError = null;
} catch (e) {
retryError = (e as Error).message;
}
}
function pct(j: Job): number {
if (j.status.kind === 'Done') return 100;
if (!j.progress.bytes_total) return 0;
return Math.min(100, (j.progress.bytes_done / j.progress.bytes_total) * 100);
}
function statusText(j: Job): string {
switch (j.status.kind) {
case 'Done':
return 'Moved';
case 'Planned':
return 'Dry run complete';
case 'Failed':
return 'Failed';
case 'Queued':
return 'Queued';
default:
return STAGE_LABEL[j.stage];
}
}
const sideClass = (node: string) => (node === localName ? 'local' : 'peer');
</script>
{#if error}<p class="panel msg error">{error}</p>{/if}
{#if moves.peerError}<p class="panel msg muted">Couldn't load moves running on the peer: {moves.peerError}</p>{/if}
{#if moves.loaded && !sorted.length}
<p class="panel empty muted">No moves yet. Pick something in Library to get started.</p>
{/if}
<ul class="jobs">
{#each sorted as j (j.id)}
<li class="panel job" class:failed={j.status.kind === 'Failed'}>
<div class="top">
<div class="what">
<div class="name">{j.name}</div>
<div class="route">
<span class={sideClass(j.source_node)}>{j.source_node}</span>
<span class="muted">→</span>
<span class={sideClass(j.target_node)}>{j.target_node}</span>
{#if j.target_library}<span class="muted">· {j.target_library}</span>{/if}
{#if j.dry_run}<span class="tag">dry run</span>{/if}
</div>
</div>
<div class="state">
<span class="label s-{j.status.kind.toLowerCase()}">{statusText(j)}</span>
{#if (j.status.kind === 'Failed' || j.status.kind === 'Planned') && j.target_node === localName}
<button onclick={() => retry(j.id)}>{j.status.kind === 'Planned' ? 'Run for real' : 'Retry'}</button>
{/if}
</div>
</div>
<div class="steps" aria-hidden="true">
{#each STAGES.slice(0, -1) as s, i (s)}
<span class="step" class:done={STAGES.indexOf(j.stage) > i} class:now={STAGES.indexOf(j.stage) === i && j.status.kind === 'Running'}></span>
{/each}
</div>
{#if j.progress.bytes_total}
<div class="bar" role="progressbar" aria-valuenow={Math.round(pct(j))} aria-valuemin={0} aria-valuemax={100}>
<div style:width="{pct(j)}%"></div>
</div>
<div class="meta muted">
{bytes(j.progress.bytes_done)} of {bytes(j.progress.bytes_total)}
{#if j.progress.current_file && j.status.kind === 'Running'}
· <span class="mono">{j.progress.current_file}</span>
{/if}
</div>
{/if}
{#if j.status.kind === 'Failed'}
<p class="error why">{j.status.detail}</p>
{/if}
<button class="logtoggle" onclick={() => (open[j.id] = !open[j.id])} aria-expanded={!!open[j.id]}>
{open[j.id] ? 'Hide' : 'Show'} log ({j.log.length})
</button>
{#if open[j.id]}
<pre class="log">{j.log.join('\n')}</pre>
{/if}
</li>
{/each}
</ul>
<style>
.msg,
.empty {
padding: 0.8rem 1rem;
}
.empty {
text-align: center;
padding: 2rem;
}
.jobs {
list-style: none;
margin: 0;
padding: 0;
display: grid;
gap: 0.8rem;
}
.job {
padding: 1rem 1.1rem;
}
.job.failed {
border-color: color-mix(in srgb, var(--bad) 50%, var(--line));
}
.top {
display: flex;
gap: 1rem;
align-items: flex-start;
justify-content: space-between;
}
.name {
font-weight: 650;
font-size: 1.05rem;
}
.route {
font-size: 0.88rem;
display: flex;
gap: 0.35rem;
align-items: center;
flex-wrap: wrap;
}
.route .local {
color: var(--local);
}
.route .peer {
color: var(--peer);
}
.tag {
font-size: 0.72rem;
border: 1px solid var(--line);
border-radius: 5px;
padding: 0 0.35rem;
color: var(--muted);
}
.state {
display: flex;
gap: 0.6rem;
align-items: center;
flex-shrink: 0;
}
.label {
font-size: 0.85rem;
font-weight: 600;
}
.s-done {
color: var(--ok);
}
.s-failed {
color: var(--bad);
}
.s-running {
color: var(--peer);
}
.steps {
display: grid;
grid-template-columns: repeat(7, 1fr);
gap: 4px;
margin: 0.8rem 0 0.5rem;
}
.step {
height: 4px;
border-radius: 2px;
background: var(--line);
}
.step.done {
background: var(--ok);
}
.step.now {
background: var(--peer);
animation: pulse 1.4s ease-in-out infinite;
}
@keyframes pulse {
50% {
opacity: 0.45;
}
}
@media (prefers-reduced-motion: reduce) {
.step.now {
animation: none;
}
}
.bar {
height: 8px;
border-radius: 4px;
background: var(--panel-2);
overflow: hidden;
margin-top: 0.6rem;
}
.bar div {
height: 100%;
background: linear-gradient(90deg, var(--local), var(--peer));
transition: width 0.4s ease;
}
.meta {
font-size: 0.82rem;
margin-top: 0.35rem;
white-space: nowrap;
overflow: hidden;
text-overflow: ellipsis;
}
.why {
margin: 0.7rem 0 0;
font-size: 0.9rem;
}
.logtoggle {
margin-top: 0.7rem;
font-size: 0.8rem;
padding: 0.2rem 0.6rem;
background: transparent;
color: var(--muted);
}
.log {
margin: 0.5rem 0 0;
padding: 0.7rem;
background: var(--panel-2);
border-radius: 8px;
font-family: var(--mono);
font-size: 0.78rem;
max-height: 18rem;
overflow: auto;
white-space: pre-wrap;
}
</style>