Peach: Local-first video metadata scraper and media manager.
fix(web): 垃圾文件页的计数行竖排成两块面,等待态画它自己那条
longmeidaof3d362a950fc
diff --git a/frontend/e2e/design.test.ts b/frontend/e2e/design.test.tsindex 2791dfd8c..036275309 100644--- a/frontend/e2e/design.test.ts+++ b/frontend/e2e/design.test.ts@@ -166,6 +166,20 @@ async function openProcessing(return opened;}+/** 1280 的桌面视口比 `--board-content` 还窄,量不出「网格铺满、标题居中」这类差别。 */+const WIDE = { name: 'wide', width: 1600, height: 900, mobile: false };++/** 垃圾文件页。计数行由页面自己画,演示库里一条候选都没有时它照样在。 */+async function openJunk(browser: Browser): Promise<Visit> {+ const opened = await visit(browser, '/junk-files', WIDE);+ await expectBody(opened.page, '/junk-files', [+ opened.page.locator('#count .collection-summary'),+ opened.page.locator('#count .junkfilters'),+ ]);+ await settle(opened.page);+ return opened;+}+/** 打开目录并等到读数与卡片一起替下首屏骨架。 */async function openCatalog(browser: Browser): Promise<Visit> {const opened = await visit(browser, '/', DESKTOP);@@ -1011,4 +1025,68 @@ describe('设计决定', () => {await opened.close();}});++ it('垃圾文件的计数行是两块看得见、跟标题同宽的面', { timeout: 60_000 }, async () => {+ const opened = await openJunk(browser);+ try {+ /* 三件事一起量,它们是同一条:这一行装着摘要和分类切换两块整宽的面,横排时后者+ 被挤成 0 宽;两块面和网格只要有一支不受 --board-content 约束,宽屏上标题就缩在+ 中间、卡片顶着两边;浅色下 primary 就是页面底色,不换一档这两块面整个消失。 */+ const box = await opened.page.evaluate(() => {+ // 浅色是两块面最容易消失的那一档:深色下 primary 本来就比页面亮一级。+ document.documentElement.dataset.theme = 'light';+ document.documentElement.classList.remove('dark');+ const span = (selector: string) => {+ const rect = document.querySelector(selector)!.getBoundingClientRect();+ return { left: Math.round(rect.left), width: Math.round(rect.width) };+ };+ const face = (selector: string) =>+ getComputedStyle(document.querySelector(selector)!).backgroundColor;+ return {+ title: span('#manageTitle'),+ summary: span('#count .collection-summary'),+ filters: span('#count .junkfilters'),+ grid: span('#grid'),+ summaryFace: face('#count .collection-summary'),+ filtersFace: face('#count .junkfilters'),+ page: getComputedStyle(document.body).backgroundColor,+ };+ });+ assert.ok(box.filters.width > 0, '分类切换被摘要挤成 0 宽,整条在宽屏上看不见');+ for (const [label, measured] of [['摘要', box.summary], ['分类切换', box.filters],+ ['网格', box.grid]] as const) {+ assert.deepEqual(measured, box.title,+ `${label}和标题不同宽:${measured.left}+${measured.width} 对 ${box.title.left}+${box.title.width}`);+ }+ assert.notEqual(box.summaryFace, box.page, '摘要那块面和页面底色同色,整块看不见');+ assert.notEqual(box.filtersFace, box.page, '分类切换那块面和页面底色同色,整块看不见');+ assert.deepEqual(opened.problems, []);+ } finally {+ await opened.close();+ }+ });++ it('垃圾文件等数据时画的仍是它自己那条计数行', { timeout: 60_000 }, async () => {+ const opened = await visit(browser, '/junk-files', WIDE);+ try {+ /* 把等待态停在屏幕上:让这一页唯一那次取数挂着不回。等的只有读数,分类切换由+ URL 决定、此刻就画得出最终样子;画成目录那条的话,等待期间摆着一排这一页根本+ 没有的换批与排序键,数据到货整行再换成另一种东西。 */+ await opened.page.route('**/api/ads?**', () => {});+ await opened.page.reload({ waitUntil: 'load' });+ await opened.page.locator('#count .junkfilters').waitFor({ timeout: 15_000 });+ const row = await opened.page.locator('#count').evaluate((node) => ({+ busy: node.getAttribute('aria-busy'),+ filters: node.querySelectorAll('.junkfilters a').length,+ placeholder: node.querySelectorAll('.collection-summary .countskeleton').length,+ sorts: node.querySelectorAll('.sorts').length,+ }));+ assert.equal(row.busy, 'true', '等待态没有对辅助技术公开');+ assert.ok(row.filters > 0, '等待期间这一行没有分类切换');+ assert.equal(row.placeholder, 1, '占位没有落在读数那一格');+ assert.equal(row.sorts, 0, '等待期间摆着这一页没有的排序键');+ } finally {+ await opened.close();+ }+ });});diff --git a/frontend/src/legacy/ui.d.ts b/frontend/src/legacy/ui.d.tsindex 8938b1f2e..e8c3010a5 100644--- a/frontend/src/legacy/ui.d.ts+++ b/frontend/src/legacy/ui.d.ts@@ -12,7 +12,7 @@ export declare function emptyStateHtml(options?: { className?: string; actions?: string },): string;-export declare function collectionSummaryHtml(label: string, value: string, detail?: string): string;+export declare function collectionSummaryHtml(label: string, value: string, detail?: string, options?: { pending?: boolean }): string;export declare function badgeHtml(text: string): string;export declare function checkboxHtml(inputAttrs?: string): string;export declare function loadingDotsHtml(label?: string, options?: { className?: string }): string;diff --git a/tests/test_web_ui.py b/tests/test_web_ui.pyindex 065b94a6c..29bbcf61d 100644--- a/tests/test_web_ui.py+++ b/tests/test_web_ui.py@@ -3077,14 +3077,16 @@ class WebUiSourceTests(unittest.TestCase):筛选条完全由当前 state 决定,这次请求不会改变它,所以没有可占位的东西:连它一起清空的话,刚点下的那一枚会在等数据的整段时间里失去高亮,看着像- 没点上;`.count:empty` 还会把整行折叠,网格跟着往上跳一截。+ 没点上;`.count:empty` 还会把整行折叠,网格跟着往上跳一截。垃圾文件那一屏的+ 计数行是另一条控件,走它自己的 `junkNavigationHtml`。"""self.assertPageContains("const countSortsHtml=()=>!state?'':")# 加载态与最终态取同一份筛选条,两边不可能画得不一样。self.assertPageContains("count.innerHTML=state&&state.state==='trash'?''\n"+ " :junk?junkNavigationHtml(null)\n"" :`<span class=\"mono\"><span class=\"countskeleton\"></span></span>`+countSortsHtml();\n"- " wireCountRow();")+ " if(junk)wireJunkNavigation();else wireCountRow();")self.assertPageContains(" +(trash?'':countSortsHtml());")# 读数那一格换值时按位错峰长出来,接事件仍在同一次重画的末尾。self.assertPageContains(" popCount(readout,lastCountReadout);\n }\n wireCountRow();")@@ -5817,6 +5819,46 @@ class WebUiSourceTests(unittest.TestCase):self.assertPageLacks("loadingDotsHtml('正在读取垃圾文件…')")self.assertPageLacks("junkloading")+ def test_junk_wait_state_draws_this_page_own_count_row(self):+ """等待期间的计数行画的是垃圾文件自己那条,不是目录的排序。++ `peach-web-ui` 的判据:骨架复用最终容器的结构,能同步得到的筛选控件立即显示。+ 分类有哪几项、此刻选中哪一项、看的是待判断还是已排除,全由 URL 决定;随这次请求+ 变的只有摘要里那个数字和各类的计数徽标,占位就只盖它们。照目录那条画的话,等待+ 期间摆着一排这一页根本没有的换批与排序键,数据到货整行再换成另一种东西。+ """+ loading = self.app_js.split("function renderCatalogLoading(", 1)[1].split("\n}", 1)[0]+ self.assertIn("junkNavigationHtml(null)", loading)+ self.assertIn("if(junk)wireJunkNavigation();else wireCountRow();", loading)+ # 这一行自己的版式类平时由 load() 写,深链冷启动时骨架排在它前面。+ self.assertIn("count.classList.toggle('junkcount',junk)", loading)+ self.assertIn("count.classList.toggle('manage-static',junk)", loading)+ # 等待与到货是同一份结构、同一份接线,不是两份互相追赶的模板。+ self.assertPageContains("$('#count').innerHTML=junkNavigationHtml(data);")+ self.assertPageContains("{pending:!data}")+ self.assertPageContains(+ "const figure=pending?'<span class=\"countskeleton\"></span>':esc(value);")++ def test_junk_count_row_stacks_two_visible_faces_as_wide_as_the_title(self):+ """垃圾文件的计数行是上下两块整宽的面,跟标题、面包屑和网格同宽。++ 摘要和分类切换各自都是一块 `width:100%` 的面。这一行按目录那条横排的话,摘要+ `flex:none` 占满整行,分类切换 `min-width:0` 被压成 0 宽、内容滚进看不见的地方,+ 宽屏上那条分类整个消失。宽度同理:它是数据管理的子页,标题与区块切换条都收在+ `--board-content` 里,只有网格那一支铺满内容区时,同一页会有两条对不上的左边界。+ 浅色下 `primary` 就是页面底色,这两块不描边的面于是整个看不见——跟重复文件那两块+ 面同一条判据。+ """+ board = (Path(__file__).resolve().parents[1] / "web/board.css").read_text(encoding="utf-8")+ self.assertIn('body[data-surface="/junk-files"] #count{flex-direction:column;'+ 'align-items:stretch;gap:16px;padding-inline:0}', board)+ self.assertIn('body[data-surface="/junk-files"] :is(#count,#grid,#loadSentinel)'+ '{width:100%;max-width:var(--board-content);margin-inline:auto}', board)+ self.assertIn('html:not(.dark) .collection-summary'+ '{background:var(--color-background-secondary-default)}', board)+ self.assertIn('html:not(.dark) body[data-surface="/junk-files"] .junkfilters'+ '{background:var(--color-background-secondary-default)}', board)+def test_category_switchers_are_geist_secondary_tabs_not_a_segmented_control(self):"""复核分类和垃圾文件分类共用一套外观:带描边的 Geist Tabs secondary 几何。diff --git a/web/app.js b/web/app.jsindex 488568ec7..490c7fa39 100644--- a/web/app.js+++ b/web/app.js@@ -270,10 +270,17 @@ function renderCatalogLoading(label='正在读取作品'){const count=$('#count');count.setAttribute('aria-busy','true');count.setAttribute('aria-label',label);+ /* 垃圾文件那一屏的计数行是自己的:一块摘要面加一条分类切换,没有排序也没有换批。+ 照目录那条画的话,等待期间摆着一排这一页根本没有的排序键,数据到货整行再换成+ 另一种东西。版式类平时由 load() 写,深链冷启动时骨架排在它前面,这里一并带上。 */+ const junk=decodeURIComponent(location.pathname)==='/junk-files';+ count.classList.toggle('manage-static',junk);+ count.classList.toggle('junkcount',junk);// 回收站的计数挂在说明行上,这一行只剩「清空回收站」,没有会变的数字可占位。count.innerHTML=state&&state.state==='trash'?''+ :junk?junkNavigationHtml(null):`<span class="mono"><span class="countskeleton"></span></span>`+countSortsHtml();- wireCountRow();+ if(junk)wireJunkNavigation();else wireCountRow();/* 骨架一铺上去就得把底部那颗 Loading Dots 收掉。骨架说的是「等下会出现几张什么形状的卡」,dots 说的是「上面已经有内容,还在往下接」;两段同时在场时一屏里铺着两种等待动画,而实际只有一次请求在跑。哨兵的可见性由数据落地后的@@ -3494,22 +3501,34 @@ function wireJunkCards(root){});});}-function renderJunkNavigation(data){- const countFor=key=>key?Number(data.counts?.[key]||0):Number(data.all_total||0);- const dismissedTotal=Number(data.dismissed_total||0);+/* 计数行的最终样子。分类有哪几项、此刻选中哪一项、看的是待判断还是已排除,全由+ URL 决定,等数据的这段时间就能画成最终样子;随这次请求变的只有摘要里那个数字和+ 各类的计数徽标,`data` 为空时它们让位给占位,别的原地不动。 */+function junkNavigationHtml(data){+ const countFor=key=>key?Number(data?.counts?.[key]||0):Number(data?.all_total||0);+ const dismissedTotal=Number(data?.dismissed_total||0);const categoryLinks=JUNK_KIND_OPTIONS.map(([key,label,glyph])=>{- const current=key===junkKind,count=countFor(key);+ const current=key===junkKind,count=data?countFor(key):0;/* 同一套 Geist Tabs 徽标口径:计数为 0 时整枚去掉。这一条仍用 <a>,因为分类要落到URL 上——规范里 Tabs 的行为条款本身就要求当前项可深链、可刷新恢复。 */return `<a href="${junkPath(key,junkView)}" data-junk-kind-link="${esc(key)}"${current?' aria-current="page"':''}>${icon(glyph)}${esc(label)}${count?` <span class="n mono" data-count-badge="junk:${esc(key)}">${count.toLocaleString()}</span>`:''}</a>`;}).join('');- $('#count').removeAttribute('aria-busy');- $('#count').innerHTML=`<div class="junksummary" aria-live="polite">${collectionSummaryHtml(junkView==='dismissed'?'已排除':'待判断',`${Number(data.total||0).toLocaleString()} 个`)}</div>+ return `<div class="junksummary" aria-live="polite">${collectionSummaryHtml(junkView==='dismissed'?'已排除':'待判断',+ data?`${Number(data.total||0).toLocaleString()} 个`:'','',{pending:!data})}</div><nav class="junkfilters" aria-label="垃圾文件分类">${categoryLinks}<i aria-hidden="true"></i><a href="${junkPath('',junkView==='dismissed'?'pending':'dismissed')}" data-junk-view-link="${junkView==='dismissed'?'pending':'dismissed'}"${junkView==='dismissed'?' aria-current="page"':''}>${icon(junkView==='dismissed'?'rotate-ccw':'eye-off')}${junkView==='dismissed'?'返回待判断':'已排除'}${dismissedTotal?` <span class="n mono" data-count-badge="junk:dismissed">${dismissedTotal.toLocaleString()}</span>`:''}</a></nav>`;+}+function renderJunkNavigation(data){+ $('#count').removeAttribute('aria-busy');+ $('#count').innerHTML=junkNavigationHtml(data);// 判过一批之后各类的待处理数就变了,弹的是变了的那几枚,没动的那几类原地不动。popBadges($('#count'),'junk');+ wireJunkNavigation();+}+/* 等待态与到货后是同一条分类切换,接线也就只有这一份:骨架里点分类会换到那一类+ 继续等,跟数据已经到了时点它是同一件事。 */+function wireJunkNavigation(){$('#count').querySelectorAll('[data-junk-kind-link],[data-junk-view-link]').forEach(link=>link.onclick=event=>{if(event.button!==0||event.metaKey||event.ctrlKey||event.shiftKey||event.altKey)return;event.preventDefault();diff --git a/web/board.css b/web/board.cssindex 4eb1764f3..fd2feb193 100644--- a/web/board.css+++ b/web/board.css@@ -1653,6 +1653,11 @@ body .review .reviewcontrols{position:static;z-index:auto;padding-block:0;displa.collection-summary span{font:var(--board-body);color:var(--color-text-secondary)}.collection-summary strong{font:var(--board-title);color:var(--color-text-primary);font-variant-numeric:tabular-nums}.collection-summary p{margin:0;color:var(--color-text-secondary);font:var(--board-body)}+/* 浅色下 primary 就是页面底色,这块不描边的面于是整个消失,读起来是数字直接落在页面上。+ 深色下 primary 比页面亮一档,本来就分得开——跟重复文件那两块面同一条判据。 */+html:not(.dark) .collection-summary{background:var(--color-background-secondary-default)}+/* 数字回来前占它的位置:跟着 --board-title 的 32px 走,行高 44px 容得下,数字到货不改行高。 */+.collection-summary strong .countskeleton{width:96px;height:32px}body[data-surface="/review"] .review-workspace{display:grid;grid-template-columns:minmax(0,1fr) 184px;column-gap:24px;align-items:start}body[data-surface="/review"] .review-workspace>.reviewcontrols{grid-column:2;grid-row:1 / span 4;position:sticky;top:var(--topH);padding:16px 8px;background:var(--color-background-primary-default);border-radius:var(--surface-radius)}body[data-surface="/review"] .review-category-title{font:var(--board-caption);color:var(--muted);margin:0 12px 12px}@@ -1698,15 +1703,24 @@ body[data-surface="/quality-goals"] .qualityitem{display:grid;grid-template-colubody[data-surface="/quality-goals"] .qualitycover{position:relative;display:grid;place-items:center;grid-row:1 / span 2;width:150px;aspect-ratio:16/10;border-radius:var(--control-radius);background:var(--color-background-tertiary-default)}.qualitybody{padding:4px 4px 0;min-width:0}.qualityactions{display:flex;justify-content:flex-end;padding:8px 4px 0;background:transparent}+/* 垃圾文件的计数行装着两块整宽的面:上面是「待判断 N 个」那块摘要,下面是分类切换。+ 这一行仍按目录页的横排走的话,`width:100%` 的摘要把后面那条挤到 0 宽,而它自己+ `min-width:0` 又带横向滚动,于是宽屏上分类切换整条看不见,只剩一块摘要贴着网格。 */+body[data-surface="/junk-files"] #count{flex-direction:column;align-items:stretch;gap:16px;padding-inline:0}body[data-surface="/junk-files"] .junksummary{width:100%}body[data-surface="/junk-files"] .collection-summary{margin:0}body[data-surface="/junk-files"] .junkfilters{width:100%;padding:12px;gap:8px;border-radius:var(--surface-radius);background:var(--color-background-primary-default)}+/* 它是数据管理的子页:摘要、分类条、网格和加载哨兵跟标题、面包屑、区块切换条同宽。+ 只有网格那一支铺满内容区时,宽屏上标题居中缩在中间、卡片顶着两边,同一页有两条+ 对不上的左边界。 */+body[data-surface="/junk-files"] :is(#count,#grid,#loadSentinel){width:100%;max-width:var(--board-content);margin-inline:auto}body:is([data-surface="/junk-files"],[data-surface="/trash"]) .gridstack>.grid{grid-template-columns:repeat(auto-fill,minmax(min(100%,280px),1fr));gap:20px}body:is([data-surface="/junk-files"],[data-surface="/trash"]) .gridstack .card{border:1px solid var(--line-soft);border-radius:var(--surface-radius);background:var(--color-background-primary-default);overflow:hidden;gap:0}body[data-surface="/trash"] .gridstack .card .pic{border-radius:0}body[data-surface="/trash"] .gridstack .card>.meta{padding:16px 20px}body[data-surface="/trash"] #manageLede{padding:20px 24px;background:var(--color-background-primary-default);border-radius:var(--surface-radius);gap:16px;flex-wrap:wrap}body[data-surface="/trash"] #manageLede>span{font:var(--board-heading)}+html:not(.dark) body[data-surface="/junk-files"] .junkfilters{background:var(--color-background-secondary-default)}body[data-surface="/junk-files"] .junkmeta{padding:20px}body[data-surface="/junk-files"] .junkactions{padding:12px;background:var(--color-background-secondary-default);flex-wrap:wrap}@media(max-width:900px){diff --git a/web/js/ui-components.js b/web/js/ui-components.jsindex c2b42ac38..8ded08f81 100644--- a/web/js/ui-components.js+++ b/web/js/ui-components.js@@ -361,9 +361,12 @@ function noteDetailsHtml({label='',items=[],footnote=''}={}){<ul>${items.map(line).join('')}</ul>${footnote?`<p>${esc(footnote)}</p>`:''}</details>`;}-/** 数据管理子页的结果标题,只接收当前查询得到的读数。 */-export function collectionSummaryHtml(label,value,detail=''){- return `<header class="collection-summary"><div><span>${esc(label)}</span><strong>${esc(value)}</strong></div>${detail?`<p>${esc(detail)}</p>`:''}</header>`;+/** 数据管理子页的结果标题,只接收当前查询得到的读数。+ `pending` 是这次请求还没回来:标题那一句同步就有,等的只有读数,占位也就只盖读数+ 那一格,宽高定死,数字回来时这块面不改高度。 */+export function collectionSummaryHtml(label,value,detail='',{pending=false}={}){+ const figure=pending?'<span class="countskeleton"></span>':esc(value);+ return `<header class="collection-summary"><div><span>${esc(label)}</span><strong>${figure}</strong></div>${detail?`<p>${esc(detail)}</p>`:''}</header>`;}/* Inline, persistent context beside the field/card/section it describes.