// Store art: every rendered screenshot, feature graphic and app preview of the app folder per variant, language and // size (`shots gallery --json`, offline), store check issues outlined. Images load one by one as they scroll into view // (`project.render`, a data: URL each: the window loads no files itself). Re-render (dry run, dialog, real run), write // the review page, open it or the folder. import { type KeyboardEvent, useCallback, useEffect, useMemo, useRef, useState } from 'react'; import { api, errorText, type Project, type RenderImage, type RendersResult, type RenderTile, type ToolResult } from '../../api'; import { t } from '../../i18n'; import { ago, bytes, num } from '../../lib/format'; import { artRows, langIssues } from '../../lib/views'; import { useData, useRead, useWrite } from '../../store'; import { Icon } from '../../ui/icons'; import { Card, Chip, Empty, ErrorNotice, Kpi, Seg, Skeleton } from '../../ui/kit'; import { WriteButton } from '../../ui/WriteButton'; // loaded images by project + file + render time, three at a time const cache = new Map(); const waiting: (() => Promise)[] = []; let active = 0; function pump() { while (active < 3 && waiting.length) { const job = waiting.shift()!; active++; job().finally(() => { active--; pump(); }); } } function loadRender(projectId: string, file: string, stamp: string): Promise { const key = `${projectId}|${file}|${stamp}`; if (cache.has(key)) return Promise.resolve(cache.get(key)!); return new Promise(resolve => { waiting.push(async () => { try { const r = await api.call('project.render', projectId, { args: { file } }); cache.set(key, r.data?.dataUrl ?? null); } catch { cache.set(key, null); } resolve(cache.get(key) ?? null); }); pump(); }); } function Thumb({ projectId, tile, stamp, onOpen }: { projectId: string; tile: RenderTile; stamp: string; onOpen: () => void }) { const ref = useRef(null); const file = tile.kind === 'video' ? tile.poster : tile.src; const [src, setSrc] = useState(file ? cache.get(`${projectId}|${file}|${stamp}`) : null); useEffect(() => { if (!file || src !== undefined) return; const el = ref.current; if (!el) return; let alive = true; const io = new IntersectionObserver(es => { if (!es.some(x => x.isIntersecting)) return; io.disconnect(); loadRender(projectId, file, stamp).then(u => { if (alive) setSrc(u); }); }, { rootMargin: '300px' }); io.observe(el); return () => { alive = false; io.disconnect(); }; }, [projectId, file, stamp, src]); const lvl = tile.issues.some(i => i.level === 'error') ? 'err' : tile.issues.length ? 'warn' : ''; return (
{tile.name}{tile.w}×{tile.h}{tile.bytes ? ` · ${bytes(tile.bytes)}` : ''}
{tile.issues.length > 0 &&
    {tile.issues.slice(0, 2).map((i, k) =>
  • {i.msg}
  • )}
}
); } function Lightbox({ projectId, tiles, index, stamp, onClose, onMove }: { projectId: string; tiles: RenderTile[]; index: number; stamp: string; onClose: () => void; onMove: (i: number) => void }) { const tile = tiles[index]!; const file = tile.kind === 'video' ? tile.poster : tile.src; const [src, setSrc] = useState(null); const root = useRef(null); useEffect(() => { setSrc(null); if (file) loadRender(projectId, file, stamp).then(setSrc); }, [projectId, file, stamp]); useEffect(() => { root.current?.focus(); }, []); const onKey = (e: KeyboardEvent) => { if (e.key === 'Escape') { e.preventDefault(); onClose(); } if (e.key === 'ArrowRight') { e.preventDefault(); onMove((index + 1) % tiles.length); } if (e.key === 'ArrowLeft') { e.preventDefault(); onMove((index - 1 + tiles.length) % tiles.length); } }; return (
{ if (e.target === e.currentTarget) onClose(); }}>
{src ? {tile.name} : }
{tile.src}
{tile.w}×{tile.h} · {bytes(tile.bytes)} · {num(index + 1)} / {num(tiles.length)}
{tile.issues.map((i, k) =>
{i.msg}
)}
); } export function ArtTab({ project }: { project: Project }) { const d = useData(); const r = useRead(project.id, 'project.renders', { network: false }); const w = useWrite(project.id); const [variant, setVariant] = useState(''); const [lang, setLang] = useState(''); const [onlyIssues, setOnlyIssues] = useState(false); const [open, setOpen] = useState<{ tiles: RenderTile[]; i: number } | null>(null); const data = r.data; const v = data?.variants.find(x => x.id === variant) ?? data?.variants[0]; const langs = v?.langs.map(l => l.lang) ?? []; const lg = langs.includes(lang) ? lang : langs[0] ?? ''; const rows = useMemo(() => (data ? artRows(data, { variant: v?.id ?? '', lang: lg, onlyIssues }) : []), [data, v, lg, onlyIssues]); const counts = useMemo(() => (data ? langIssues(data, v?.id ?? '') : {}), [data, v]); const dir = data?.dir ?? 'store/renders'; const reveal = useCallback((rel: string, openIt = false) => { api.reveal(project.id, rel, openIt).catch(e => d.toast({ kind: 'info', title: t('art.notThere'), detail: errorText(e) })); }, [project.id, d]); const stamp = data?.generated ?? ''; if (!data) return r.error ? : ; const total = data.totals.images + data.totals.videos; const toolbar = ( <> {t('art.writePage')} {t('art.render', { lang: lg || t('act.allLangs') })} ); return ( <>
{dir}} actions={toolbar} pad={false}>
{data.variants.length > 1 && [x.id, x.id ? t('gr.variant', { id: x.id }) : t('art.base')] as [string, string])} />}
{langs.map(l => ( ))}
{!total ? ( {t('art.emptyText')} ) : !rows.length ? {t('art.noIssuesText')} : (
{rows.map(row => (
i.level === 'error') ? ' bad' : ''}`} key={row.size}>

{row.label}{lg}/{row.size}{row.store === 'apple' ? 'App Store' : 'Google Play'}{t('art.count', { count: row.tiles.length })}

{row.issues.length > 0 &&
    {row.issues.map((i, k) =>
  • {i.msg}
  • )}
}
row.tiles[0].h ? '260px' : '150px' }}> {row.tiles.map((tile, i) => setOpen({ tiles: row.tiles, i })} />)}
))}
)}
{t('art.foot', { when: ago(r.at) })}
{open && setOpen(null)} onMove={i => setOpen(o => (o ? { ...o, i } : o))} />} ); }