- project card stage segments: running -> --run, awaiting confirm -> --warn - running counters/dots and 'testing' states -> --run; warn-named notes -> --warn - image/video/usage kind tags and plain entry/card icons -> neutral tokens Co-authored-by: multica-agent <github@multica.ai>
533 lines
13 KiB
Svelte
533 lines
13 KiB
Svelte
<script lang="ts">
|
|
import { goto } from '$app/navigation';
|
|
import { createMutation, useQueryClient } from '@tanstack/svelte-query';
|
|
import { assetUrl, projects, type Project } from '$lib/api';
|
|
import { toast } from '$lib/toast';
|
|
import Button from '$lib/components/ui/Button.svelte';
|
|
import ConfirmDialog from '$lib/components/ui/ConfirmDialog.svelte';
|
|
import Icon from '$lib/components/ui/Icon.svelte';
|
|
import Modal from '$lib/components/ui/Modal.svelte';
|
|
import { t } from '$lib/i18n.svelte';
|
|
|
|
/**
|
|
* A「片场暗房」project card for the home overview (a1, HEL-608).
|
|
* All numbers come from the real project record — no sample progress.
|
|
*/
|
|
|
|
interface Props {
|
|
project: Project;
|
|
}
|
|
|
|
let { project }: Props = $props();
|
|
|
|
const client = useQueryClient();
|
|
|
|
const stats = $derived(
|
|
project.stats ?? {
|
|
scene_count: 0,
|
|
character_count: 0,
|
|
asset_ready_count: 0,
|
|
asset_total_count: 0,
|
|
stage_confirmed: 0,
|
|
stage_status: {} as Record<string, string>,
|
|
active_jobs: 0,
|
|
},
|
|
);
|
|
|
|
// Five-stage creation progress (HEL-614) — real stage rows only.
|
|
const STAGE_SEGMENTS = ['script', 'style', 'storyboard', 'assets', 'shot'] as const;
|
|
function segClass(key: string): string {
|
|
const state = stats.stage_status?.[key];
|
|
if (state === 'confirmed') return 'seg-confirmed';
|
|
if (state === 'running') return 'seg-running';
|
|
if (state === 'awaiting_confirm') return 'seg-draft';
|
|
return '';
|
|
}
|
|
|
|
// Spec §2.1 allows the five avatar gradients as cover placeholders.
|
|
const PLACEHOLDER_GRADIENTS = [
|
|
'var(--avatar-1)',
|
|
'var(--avatar-2)',
|
|
'var(--avatar-3)',
|
|
'var(--avatar-4)',
|
|
'var(--avatar-5)',
|
|
];
|
|
const placeholder = $derived(PLACEHOLDER_GRADIENTS[project.id % PLACEHOLDER_GRADIENTS.length]);
|
|
|
|
const coverUrl = $derived(assetUrl(project.cover_path));
|
|
|
|
let coverFailed = $state(false);
|
|
|
|
// Cover tag reflects the real five-stage state (a1: 「分镜设计 · 进行中」):
|
|
// all confirmed → 已完成; otherwise the first unconfirmed stage + its state.
|
|
const cover = $derived.by(() => {
|
|
if (stats.stage_confirmed >= STAGE_SEGMENTS.length) {
|
|
return { cls: 'st-done', label: t('home.statusDone') };
|
|
}
|
|
const current = STAGE_SEGMENTS.find((k) => stats.stage_status?.[k] !== 'confirmed');
|
|
const state = current ? stats.stage_status?.[current] : undefined;
|
|
const stageName = current ? t(`workbench.stage.${current}`) : '';
|
|
if (state === 'running') {
|
|
return { cls: 'st-progress', label: `${stageName} · ${t('workbench.state.running')}` };
|
|
}
|
|
if (state === 'awaiting_confirm') {
|
|
return { cls: 'st-pending', label: `${stageName} · ${t('workbench.state.draft')}` };
|
|
}
|
|
if (stats.stage_confirmed > 0) {
|
|
return { cls: 'st-progress', label: `${stageName} · ${t('home.statusProgress')}` };
|
|
}
|
|
return { cls: 'st-draft', label: t('home.statusDraft') };
|
|
});
|
|
|
|
function relativeTime(iso: string): string {
|
|
const then = new Date(iso).getTime();
|
|
if (Number.isNaN(then)) return '';
|
|
const mins = Math.max(0, Math.round((Date.now() - then) / 60000));
|
|
if (mins < 1) return t('projectCard.timeJustNow');
|
|
if (mins < 60) return t('projectCard.timeM', { count: mins });
|
|
const hours = Math.round(mins / 60);
|
|
if (hours < 24) return t('projectCard.timeH', { count: hours });
|
|
const days = Math.round(hours / 24);
|
|
if (days < 30) return t('projectCard.timeD', { count: days });
|
|
const months = Math.round(days / 30);
|
|
if (months < 12) return t('projectCard.timeMo', { count: months });
|
|
return t('projectCard.timeY', { count: Math.round(months / 12) });
|
|
}
|
|
|
|
const updatedLabel = $derived(relativeTime(project.updated_at));
|
|
|
|
// ---- overflow menu (rename / delete), pattern from ProjectCard ----
|
|
let menuOpen = $state(false);
|
|
let menuEl = $state<HTMLDivElement | null>(null);
|
|
|
|
$effect(() => {
|
|
if (!menuOpen) return;
|
|
const onDocClick = (e: MouseEvent) => {
|
|
if (menuEl && !menuEl.contains(e.target as Node)) menuOpen = false;
|
|
};
|
|
const onKey = (e: KeyboardEvent) => {
|
|
if (e.key === 'Escape') menuOpen = false;
|
|
};
|
|
window.addEventListener('click', onDocClick);
|
|
window.addEventListener('keydown', onKey);
|
|
return () => {
|
|
window.removeEventListener('click', onDocClick);
|
|
window.removeEventListener('keydown', onKey);
|
|
};
|
|
});
|
|
|
|
let renameOpen = $state(false);
|
|
let renameValue = $state('');
|
|
|
|
function openRename() {
|
|
menuOpen = false;
|
|
renameValue = project.title;
|
|
renameOpen = true;
|
|
}
|
|
|
|
const renameMutation = createMutation({
|
|
mutationFn: (title: string) => projects.update(project.id, { title }),
|
|
onSuccess: () => {
|
|
client.invalidateQueries({ queryKey: ['projects'] });
|
|
toast.success(t('projectCard.renamedTo', { title: renameValue }));
|
|
},
|
|
onError: (err) => {
|
|
toast.error(err instanceof Error ? err.message : t('projectCard.renameFailed'));
|
|
},
|
|
});
|
|
|
|
function submitRename() {
|
|
const title = renameValue.trim();
|
|
renameOpen = false;
|
|
if (!title || title === project.title) return;
|
|
$renameMutation.mutate(title);
|
|
}
|
|
|
|
let deleteOpen = $state(false);
|
|
|
|
const deleteMutation = createMutation({
|
|
mutationFn: () => projects.delete(project.id),
|
|
onSuccess: () => {
|
|
client.invalidateQueries({ queryKey: ['projects'] });
|
|
toast.success(t('projectCard.deleted', { title: project.title }));
|
|
},
|
|
onError: (err) => {
|
|
toast.error(err instanceof Error ? err.message : t('projectCard.deleteFailed'));
|
|
},
|
|
});
|
|
</script>
|
|
|
|
<article class="a-card">
|
|
<button
|
|
type="button"
|
|
class="card-main"
|
|
aria-label={t('projectCard.open', { title: project.title })}
|
|
onclick={() => goto(`/workbench/${project.id}`)}
|
|
>
|
|
<span class="cover">
|
|
{#if coverUrl && !coverFailed}
|
|
<img
|
|
class="cover-img"
|
|
src={coverUrl}
|
|
alt=""
|
|
loading="lazy"
|
|
onerror={() => (coverFailed = true)}
|
|
/>
|
|
{:else}
|
|
<span class="cover-ph" style:background={placeholder} aria-hidden="true">
|
|
<Icon name="film" size={22} />
|
|
</span>
|
|
{/if}
|
|
<span class="status-tag {cover.cls}">{cover.label}</span>
|
|
</span>
|
|
<span class="body">
|
|
<span class="title-row">
|
|
<span class="title">{project.title}</span>
|
|
<span class="arrow" aria-hidden="true">→</span>
|
|
</span>
|
|
<span class="idea">{project.idea || t('home.noIdea')}</span>
|
|
<span class="stage-bar" aria-label={t('home.stageProgress')}>
|
|
{#each STAGE_SEGMENTS as key (key)}
|
|
<span class="seg {segClass(key)}" title={t(`workbench.stage.${key}`)}></span>
|
|
{/each}
|
|
<span class="seg-count mono">{stats.stage_confirmed}/5</span>
|
|
{#if stats.active_jobs > 0}
|
|
<span class="jobs-pill">{t('home.activeJobs', { n: stats.active_jobs })}</span>
|
|
{/if}
|
|
</span>
|
|
<span class="meta">
|
|
<span class="meta-stats mono">
|
|
{t('home.statScenes', { n: stats.scene_count })}
|
|
· {t('home.statCharacters', { n: stats.character_count })}
|
|
· {t('home.statAssets', {
|
|
ready: stats.asset_ready_count,
|
|
total: stats.asset_total_count,
|
|
})}
|
|
</span>
|
|
<span class="meta-time">{updatedLabel}</span>
|
|
</span>
|
|
</span>
|
|
</button>
|
|
|
|
<div class="menu-wrap" bind:this={menuEl}>
|
|
<button
|
|
type="button"
|
|
class="menu-btn"
|
|
aria-label={t('projectCard.actions', { title: project.title })}
|
|
aria-haspopup="menu"
|
|
aria-expanded={menuOpen}
|
|
onclick={() => (menuOpen = !menuOpen)}
|
|
>
|
|
⋯
|
|
</button>
|
|
{#if menuOpen}
|
|
<div class="menu" role="menu">
|
|
<button type="button" role="menuitem" class="menu-item" onclick={openRename}>
|
|
<Icon name="edit" size={14} />
|
|
{t('common.rename')}
|
|
</button>
|
|
<button
|
|
type="button"
|
|
role="menuitem"
|
|
class="menu-item danger"
|
|
onclick={() => {
|
|
menuOpen = false;
|
|
deleteOpen = true;
|
|
}}
|
|
>
|
|
<Icon name="trash" size={14} />
|
|
{t('common.delete')}
|
|
</button>
|
|
</div>
|
|
{/if}
|
|
</div>
|
|
</article>
|
|
|
|
<Modal bind:open={renameOpen} title={t('projectCard.renameTitle')}>
|
|
<form
|
|
onsubmit={(e) => {
|
|
e.preventDefault();
|
|
submitRename();
|
|
}}
|
|
>
|
|
<label class="field">
|
|
<span class="field-label">{t('common.title')}</span>
|
|
<input class="field-input" bind:value={renameValue} required />
|
|
</label>
|
|
</form>
|
|
{#snippet footer()}
|
|
<Button variant="ghost" onclick={() => (renameOpen = false)}>{t('common.cancel')}</Button>
|
|
<Button
|
|
variant="primary"
|
|
disabled={!renameValue.trim() || $renameMutation.isPending}
|
|
onclick={submitRename}
|
|
>
|
|
{t('common.rename')}
|
|
</Button>
|
|
{/snippet}
|
|
</Modal>
|
|
|
|
<ConfirmDialog
|
|
bind:open={deleteOpen}
|
|
title={t('projectCard.deleteTitle')}
|
|
message={t('projectCard.deleteMessage', { title: project.title })}
|
|
confirmLabel={t('common.delete')}
|
|
danger
|
|
onconfirm={() => $deleteMutation.mutate()}
|
|
/>
|
|
|
|
<style>
|
|
.a-card {
|
|
position: relative;
|
|
background: var(--surface);
|
|
border: 1px solid var(--border);
|
|
border-radius: 10px;
|
|
overflow: hidden;
|
|
transition: border-color 150ms cubic-bezier(0.16, 1, 0.3, 1);
|
|
}
|
|
.a-card:hover {
|
|
border-color: var(--border-strong);
|
|
}
|
|
.a-card:hover .arrow {
|
|
opacity: 1;
|
|
transform: translateX(0);
|
|
}
|
|
|
|
.card-main {
|
|
display: flex;
|
|
flex-direction: column;
|
|
width: 100%;
|
|
padding: 0;
|
|
border: none;
|
|
background: transparent;
|
|
color: inherit;
|
|
font: inherit;
|
|
text-align: left;
|
|
cursor: pointer;
|
|
}
|
|
.card-main:focus-visible {
|
|
outline: 2px solid var(--accent);
|
|
outline-offset: -2px;
|
|
}
|
|
|
|
.cover {
|
|
position: relative;
|
|
display: block;
|
|
height: 132px;
|
|
background: var(--surface-2);
|
|
overflow: hidden;
|
|
}
|
|
.cover-img {
|
|
position: absolute;
|
|
inset: 0;
|
|
width: 100%;
|
|
height: 100%;
|
|
object-fit: cover;
|
|
}
|
|
.cover-ph {
|
|
position: absolute;
|
|
inset: 0;
|
|
display: inline-flex;
|
|
align-items: center;
|
|
justify-content: center;
|
|
color: color-mix(in srgb, var(--accent-ink) 82%, transparent);
|
|
opacity: 0.9;
|
|
}
|
|
.status-tag {
|
|
position: absolute;
|
|
top: 8px;
|
|
right: 8px;
|
|
padding: 2px 9px;
|
|
border-radius: 999px;
|
|
font-size: 10.5px;
|
|
font-weight: 600;
|
|
background: var(--media-scrim);
|
|
border: 1px solid var(--border-strong);
|
|
backdrop-filter: blur(4px);
|
|
}
|
|
/* a1: dark capsule over the cover so it stays legible on any image;
|
|
the text carries the semantic color (§2.1). */
|
|
.st-draft {
|
|
color: var(--text-2);
|
|
}
|
|
.st-progress {
|
|
color: var(--run);
|
|
}
|
|
.st-pending {
|
|
color: var(--warn);
|
|
}
|
|
.st-done {
|
|
color: var(--success);
|
|
}
|
|
|
|
.body {
|
|
display: flex;
|
|
flex-direction: column;
|
|
gap: 6px;
|
|
padding: 14px 16px 15px;
|
|
}
|
|
.title-row {
|
|
display: flex;
|
|
align-items: center;
|
|
justify-content: space-between;
|
|
gap: 8px;
|
|
}
|
|
.title {
|
|
font-size: 14px;
|
|
font-weight: 600;
|
|
color: var(--text);
|
|
overflow: hidden;
|
|
text-overflow: ellipsis;
|
|
white-space: nowrap;
|
|
}
|
|
.arrow {
|
|
color: var(--accent);
|
|
font-size: 13px;
|
|
opacity: 0;
|
|
transform: translateX(-6px);
|
|
transition:
|
|
opacity 150ms cubic-bezier(0.16, 1, 0.3, 1),
|
|
transform 150ms cubic-bezier(0.16, 1, 0.3, 1);
|
|
}
|
|
.idea {
|
|
font-size: 12px;
|
|
color: var(--text-2);
|
|
line-height: 1.6;
|
|
display: -webkit-box;
|
|
-webkit-line-clamp: 2;
|
|
line-clamp: 2;
|
|
-webkit-box-orient: vertical;
|
|
overflow: hidden;
|
|
min-height: 2.2em;
|
|
}
|
|
|
|
/* Five-stage progress segments (real stage rows, HEL-614). */
|
|
.stage-bar {
|
|
display: flex;
|
|
align-items: center;
|
|
gap: 4px;
|
|
}
|
|
.seg {
|
|
width: 20px;
|
|
height: 5px;
|
|
border-radius: 2px;
|
|
background: var(--surface-3);
|
|
}
|
|
.seg-running {
|
|
background: var(--run);
|
|
}
|
|
.seg-draft {
|
|
background: var(--warn);
|
|
}
|
|
.seg-confirmed {
|
|
background: var(--success);
|
|
}
|
|
.seg-count {
|
|
margin-left: 5px;
|
|
font-size: 11px;
|
|
color: var(--text-3);
|
|
font-variant-numeric: tabular-nums;
|
|
}
|
|
.jobs-pill {
|
|
margin-left: auto;
|
|
padding: 1px 8px;
|
|
border-radius: 999px;
|
|
background: var(--run-soft);
|
|
color: var(--run);
|
|
font-size: 10px;
|
|
font-weight: 600;
|
|
font-variant-numeric: tabular-nums;
|
|
white-space: nowrap;
|
|
}
|
|
.meta {
|
|
display: flex;
|
|
align-items: center;
|
|
justify-content: space-between;
|
|
gap: 8px;
|
|
}
|
|
.meta-stats {
|
|
font-size: 11px;
|
|
color: var(--text-3);
|
|
overflow: hidden;
|
|
text-overflow: ellipsis;
|
|
white-space: nowrap;
|
|
}
|
|
.meta-time {
|
|
font-size: 11px;
|
|
color: var(--text-3);
|
|
flex-shrink: 0;
|
|
}
|
|
|
|
.menu-wrap {
|
|
position: absolute;
|
|
top: 8px;
|
|
left: 8px;
|
|
z-index: 3;
|
|
}
|
|
.menu-btn {
|
|
width: 28px;
|
|
height: 28px;
|
|
border: 1px solid transparent;
|
|
border-radius: 7px;
|
|
background: var(--media-scrim);
|
|
color: var(--text-2);
|
|
font-size: 15px;
|
|
line-height: 1;
|
|
cursor: pointer;
|
|
display: flex;
|
|
align-items: center;
|
|
justify-content: center;
|
|
opacity: 0;
|
|
transition: opacity 150ms;
|
|
}
|
|
.a-card:hover .menu-btn,
|
|
.menu-btn:focus-visible,
|
|
.menu-btn[aria-expanded='true'] {
|
|
opacity: 1;
|
|
}
|
|
.menu-btn:hover {
|
|
background: var(--surface-3);
|
|
color: var(--text);
|
|
}
|
|
.menu {
|
|
position: absolute;
|
|
top: 32px;
|
|
left: 0;
|
|
min-width: 132px;
|
|
background: var(--surface-2);
|
|
border: 1px solid var(--border-strong);
|
|
border-radius: 8px;
|
|
padding: 4px;
|
|
display: flex;
|
|
flex-direction: column;
|
|
}
|
|
.menu-item {
|
|
display: flex;
|
|
align-items: center;
|
|
gap: 8px;
|
|
width: 100%;
|
|
padding: 7px 9px;
|
|
border: none;
|
|
border-radius: 6px;
|
|
background: transparent;
|
|
color: var(--text);
|
|
font-size: 12.5px;
|
|
font-family: inherit;
|
|
cursor: pointer;
|
|
text-align: left;
|
|
}
|
|
.menu-item:hover {
|
|
background: var(--surface-3);
|
|
}
|
|
.menu-item.danger {
|
|
color: var(--error);
|
|
}
|
|
.menu-item.danger:hover {
|
|
background: var(--error-dim);
|
|
} .a-card :global(.field-input) {
|
|
background: var(--surface-2);
|
|
border-color: var(--border-strong);
|
|
color: var(--text);
|
|
}
|
|
</style>
|