Skip to content

armgit / peach

Public Imported from GitHub
0

Peach: Local-first video metadata scraper and media manager.

fix(web): 关注管理七位数读数与单位同一行,骨架包裹层带上与页面同名的钩子

longmeidao9db35e1469aa
diff --git a/frontend/e2e/design-cards.test.ts b/frontend/e2e/design-cards.test.ts
index cc432faa3..0d9d2d721 100644
--- a/frontend/e2e/design-cards.test.ts
+++ b/frontend/e2e/design-cards.test.ts
@@ -963,12 +963,12 @@ describe('设计决定:作品卡、管理页与复核', () => {
const toolbar = '[data-skeleton] .ui-follow-skeleton-toolbar';
const skeleton = await controlFaces(page, {
检查全部: `${toolbar} > button:nth-of-type(1)`,
- 默认视图: `${toolbar} > [data-button-group] > button:first-child`,
- 表格视图: `${toolbar} > [data-button-group] > button:last-child`,
+ 默认视图: `${toolbar} [data-button-group] > button:first-child`,
+ 表格视图: `${toolbar} [data-button-group] > button:last-child`,
排序框: `${toolbar} button[aria-haspopup="listbox"]`,
- 方向键: `${toolbar} > button:nth-of-type(2)`,
- 全部收起: `${toolbar} > button:nth-of-type(3)`,
- 移除来源: '[data-skeleton] .follow-skeleton-source > span:last-child > button:last-child',
+ 方向键: `${toolbar} [data-follow-toolbar-controls] > button:nth-of-type(1)`,
+ 全部收起: `${toolbar} [data-follow-toolbar-controls] > button:nth-of-type(2)`,
+ 移除来源: '[data-skeleton] .follow-skeleton-source [data-follow-source-controls] > span:last-child > button:last-child',
});
const expected = await disabledTokens(page);
const waiting = await waitingActionFaces(page, '[data-skeleton] [data-skeleton-action]');
@@ -984,7 +984,7 @@ describe('设计决定:作品卡、管理页与复核', () => {
排序框: 'button[aria-label="关注列表排序"]',
方向键: 'button[aria-label^="按检查时间"]',
全部收起: 'button[aria-label="全部收起"]',
- 移除来源: '[data-source-divider] > div > span:last-child > button:last-child',
+ 移除来源: '[data-source-divider] [data-follow-source-controls] > span:last-child > button:last-child',
});
const waitsForData = new Set(['检查全部', '全部收起', '移除来源']);
for (const name of Object.keys(final)) {
diff --git a/frontend/e2e/design-manage.test.ts b/frontend/e2e/design-manage.test.ts
index 9cdd755af..c3bc7a8d5 100644
--- a/frontend/e2e/design-manage.test.ts
+++ b/frontend/e2e/design-manage.test.ts
@@ -607,7 +607,7 @@ describe('设计决定:数据管理、索引页与资料页头', () => {
{ path: '/follow', ready: '.followauthors .avskeleton',
targets: ['.followauthors .avskeleton', '.followworks .brandskeleton', '[data-skeleton^="cards/"] > div > *'] },
{ path: '/follow-manage', ready: '[data-skeleton="board/follow-manage"] .ui-follow-skeleton-toolbar',
- targets: ['[data-skeleton] .ui-follow-skeleton-toolbar > button:nth-of-type(2)',
+ targets: ['[data-skeleton] .ui-follow-skeleton-toolbar [data-follow-toolbar-controls] > button:nth-of-type(1)',
'[data-skeleton] .ui-follow-skeleton-toolbar > button:nth-of-type(1)'] },
];
for (const { path, ready, targets, prepare } of pages) {
@@ -754,7 +754,7 @@ describe('设计决定:数据管理、索引页与资料页头', () => {
}
for (const viewport of [DESKTOP, { ...MOBILE, name: 'narrow', width: 320 }]) {
- it(`七位数的读数留在卡里;长名字与长报错的来源行不越出行,桌面上操作键和名字同一行(${viewport.name})`, { timeout: 60_000 }, async () => {
+ it(`七位数的读数和单位留在卡里同一行;长名字与长报错的来源行不越出行,桌面上操作键和名字同一行(${viewport.name})`, { timeout: 60_000 }, async () => {
const long = 'ThisIsAVeryLongUsernameThatPatreonAllowsWithoutAnySpaces2024';
const opened = await openFollowManage(browser, viewport, {
counts: { new: 1284000, seen: 22000, saved: 0, ignored: 0 },
@@ -770,6 +770,10 @@ describe('设计决定:数据管理、索引页与资料页头', () => {
const readings = [...document.querySelectorAll('[data-follow-reading]')]
.filter((node) => [...node.children].some((part) => out(part, node.parentElement!)))
.map((node) => node.textContent);
+ const wrapped = [...document.querySelectorAll('[data-follow-reading]')].filter((node) => {
+ const [figure, unit] = [...node.children].map((part) => part.getBoundingClientRect());
+ return unit!.top >= figure!.bottom - 1;
+ }).map((node) => node.textContent);
const rows = [...document.querySelectorAll('[data-follow-source-row]')];
const spilled = rows
.filter((row) => row.scrollWidth > row.clientWidth + 1 || [...row.querySelectorAll('button, [role="switch"], input')]
@@ -782,12 +786,13 @@ describe('设计决定:数据管理、索引页与资料页头', () => {
const middle = (last.top + last.bottom) / 2;
return middle < name.top - 1 || middle > name.bottom + 1;
}).map((row) => row.textContent);
- return { readings, spilled, split, rows: rows.length,
+ return { readings, wrapped, spilled, split, rows: rows.length,
text: document.querySelector('[data-follow-reading]')?.parentElement?.parentElement?.textContent };
});
assert.ok(spill.text?.includes('1,284,000'), `读数没有用上七位数:${spill.text}`);
assert.equal(spill.rows, 5, '造的五条来源没有全部画出来');
assert.deepEqual(spill.readings, [], '读数越出了卡片');
+ assert.deepEqual(spill.wrapped, [], '七位数的读数把单位挤到了下一行');
assert.deepEqual(spill.spilled, [], '来源行的控件越出了行');
if (!viewport.mobile) assert.deepEqual(spill.split, [], '桌面上来源行的操作键掉到了名字下面');
assert.deepEqual(opened.problems, []);
diff --git a/frontend/src/board-skeleton.ts b/frontend/src/board-skeleton.ts
index 17e7f1433..b033d7f01 100644
--- a/frontend/src/board-skeleton.ts
+++ b/frontend/src/board-skeleton.ts
@@ -35,14 +35,14 @@ const followCheck = (label = '') => `<span class="group inline-flex items-center
interface FollowToolbar { table: boolean; sort: SortKey; dir: SortDir }
const followToolbar = ({ table, sort, dir }: FollowToolbar) => {
const name = SORT_OPTIONS.find(([key]) => key === sort)![1];
- return `<div class="flex flex-wrap items-center gap-2 follow-skeleton-toolbar"><span class="contents max-sm:flex max-sm:min-w-0 max-sm:flex-1 max-sm:flex-col"><h3 class="mr-auto text-title-2-medium text-text-primary">关注列表</h3><span class="text-body-2-regular text-text-secondary">${text('132px')}</span></span>${islandButton({ glyph: 'refresh-cw', label: '检查全部', compact: true, attrs: WAITING })}<span class="contents max-sm:flex max-sm:w-full max-sm:items-center max-sm:gap-2"><span data-button-group role="group">${islandButton({ variant: 'ghost', glyph: 'layout-grid', attrs: `aria-pressed="${!table}"` })}${islandButton({ variant: 'ghost', glyph: 'table', attrs: `aria-pressed="${table}"` })}</span>${islandSelect(name)}${islandButton({ variant: 'secondary', glyph: dir === 'asc' ? 'arrow-up' : 'arrow-down' })}${table ? '' : islandButton({ variant: 'secondary', glyph: 'chevron-up', label: '全部收起', compact: true, attrs: WAITING })}</span></div>`;
+ return `<div class="flex flex-wrap items-center gap-2 follow-skeleton-toolbar"><span class="contents max-sm:flex max-sm:min-w-0 max-sm:flex-1 max-sm:flex-col"><h3 class="mr-auto text-title-2-medium text-text-primary">关注列表</h3><span class="text-body-2-regular text-text-secondary">${text('132px')}</span></span>${islandButton({ glyph: 'refresh-cw', label: '检查全部', compact: true, attrs: WAITING })}<span data-follow-toolbar-controls class="contents max-sm:flex max-sm:w-full max-sm:items-center max-sm:gap-2"><span data-button-group role="group">${islandButton({ variant: 'ghost', glyph: 'layout-grid', attrs: `aria-pressed="${!table}"` })}${islandButton({ variant: 'ghost', glyph: 'table', attrs: `aria-pressed="${table}"` })}</span>${islandSelect(name)}${islandButton({ variant: 'secondary', glyph: dir === 'asc' ? 'arrow-up' : 'arrow-down' })}${table ? '' : islandButton({ variant: 'secondary', glyph: 'chevron-up', label: '全部收起', compact: true, attrs: WAITING })}</span></div>`;
};
/** 行尾那对动作键:检查这一条的更新、移除这一条,与 React `SourceRow` 同为小号次级纯图标键。 */
const followRowActions = () => `<span class="flex shrink-0 items-center gap-1">${islandButton({ variant: 'secondary', size: 'small', glyph: 'refresh-cw', attrs: WAITING })}${islandButton({ variant: 'secondary', size: 'small', glyph: 'trash', attrs: WAITING })}</span>`;
/** 一条来源:勾选、名字、站点图标、状态徽章、上次检查、动作,与 React `SourceRow` 同一串类名。 */
-const followRow = () => `<div class="flex min-h-16 flex-wrap items-center gap-3 px-2 py-3 max-sm:gap-x-2 follow-skeleton-source">${followCheck()}<span class="flex min-w-0 grow basis-0 flex-col gap-0.5"><span class="text-body-medium">${text('8em')}</span></span><span class="flex shrink-0 items-center gap-1.5">${block(14, 14)}</span>${block(48, 24)}<span class="contents max-sm:flex max-sm:w-full max-sm:flex-wrap max-sm:items-center max-sm:gap-1.5"><span class="shrink-0 text-body-2-regular whitespace-nowrap text-text-secondary max-sm:mr-auto max-sm:text-caption-1-regular">${text('113px')}</span>${followRowActions()}</span></div>`;
+const followRow = () => `<div class="flex min-h-16 flex-wrap items-center gap-3 px-2 py-3 max-sm:gap-x-2 follow-skeleton-source">${followCheck()}<span class="flex min-w-0 grow basis-0 flex-col gap-0.5"><span class="text-body-medium">${text('8em')}</span></span><span class="flex shrink-0 items-center gap-1.5">${block(14, 14)}</span>${block(48, 24)}<span data-follow-source-controls class="contents max-sm:flex max-sm:w-full max-sm:flex-wrap max-sm:items-center max-sm:gap-1.5"><span class="shrink-0 text-body-2-regular whitespace-nowrap text-text-secondary max-sm:mr-auto max-sm:text-caption-1-regular">${text('113px')}</span>${followRowActions()}</span></div>`;
/** 一位创作者一张 raised 卡:头行是头像、名字、检查、站点图标、全选、收起,底下是来源行。 */
-const followAuthor = (rows: number) => `<section class="min-w-0 bg-background-primary-default rounded-2xl shadow-card flex flex-col overflow-hidden p-2 follow-skeleton-author"><div class="flex flex-wrap items-center gap-3 px-2 py-2.5" data-follow-author-header data-open>${block(32, 32, true)}<b class="min-w-0 grow text-body-medium wrap-anywhere text-text-primary max-sm:basis-0">${text('92px')}</b>${islandButton({ variant: 'secondary', size: 'small', glyph: 'refresh-cw', attrs: WAITING })}<span class="contents max-sm:flex max-sm:w-full max-sm:items-center max-sm:gap-2"><span class="flex shrink-0 items-center gap-1 max-sm:mr-auto">${block(14, 14)}${block(14, 14)}</span>${islandButton({ variant: 'secondary', size: 'small', glyph: 'check-check', label: '全选', attrs: WAITING })}${islandButton({ variant: 'secondary', size: 'small', glyph: 'chevron-up', label: '收起', attrs: WAITING })}</span></div><div data-source-divider>${repeat(followRow(), rows)}</div></section>`;
+const followAuthor = (rows: number) => `<section class="min-w-0 bg-background-primary-default rounded-2xl shadow-card flex flex-col overflow-hidden p-2 follow-skeleton-author"><div class="flex flex-wrap items-center gap-3 px-2 py-2.5" data-follow-author-header data-open>${block(32, 32, true)}<b class="min-w-0 grow text-body-medium wrap-anywhere text-text-primary max-sm:basis-0">${text('92px')}</b>${islandButton({ variant: 'secondary', size: 'small', glyph: 'refresh-cw', attrs: WAITING })}<span data-follow-author-controls class="contents max-sm:flex max-sm:w-full max-sm:items-center max-sm:gap-2"><span class="flex shrink-0 items-center gap-1 max-sm:mr-auto">${block(14, 14)}${block(14, 14)}</span>${islandButton({ variant: 'secondary', size: 'small', glyph: 'check-check', label: '全选', attrs: WAITING })}${islandButton({ variant: 'secondary', size: 'small', glyph: 'chevron-up', label: '收起', attrs: WAITING })}</span></div><div data-source-divider>${repeat(followRow(), rows)}</div></section>`;
/** 表格骨架画多少行由每页条数决定,写死一个数会在别的页大小上多留或少留一屏。
* 偏好存在旧层那份 `peach.settings.v1` 里,直接读它:骨架跑在 island 挂载之前,
* 这时候页面自己的状态还不存在。 */
diff --git a/frontend/src/react/follow-manage/follow-manage-page.tsx b/frontend/src/react/follow-manage/follow-manage-page.tsx
index 79d3945fc..07ab80721 100644
--- a/frontend/src/react/follow-manage/follow-manage-page.tsx
+++ b/frontend/src/react/follow-manage/follow-manage-page.tsx
@@ -50,9 +50,9 @@ function Reading({ term, figure, unit }: { term: string; figure: number; unit: s
return (
<div className={cardClass({ padding: 'none', className: 'flex flex-col gap-3 px-6 py-5 max-sm:gap-2 max-sm:p-4' })}>
<span className="text-body-medium text-text-secondary">{term}</span>
- {/* 六位数以上换小一号字,单位放不下时落到下一行,读数不顶出卡片。 */}
+ {/* 六位数起小一号字、七位数起再小一号,六卡并排时读数和单位仍在一行;更长时单位落到下一行,不顶出卡片。 */}
<b data-follow-reading="" className={`flex min-w-0 flex-wrap items-baseline gap-x-1 tabular-nums text-text-primary ${
- figure >= 100000 ? 'text-title-3-medium' : 'text-title-1-medium'}`}>
+ figure >= 1000000 ? 'text-headline-medium' : figure >= 100000 ? 'text-title-3-medium' : 'text-title-1-medium'}`}>
<span className="min-w-0 wrap-anywhere">{figure.toLocaleString()}</span>
<small className="whitespace-nowrap text-body-2-regular text-text-secondary">{` ${unit}`}</small>
</b>
diff --git a/frontend/test/react/follow-manage.test.tsx b/frontend/test/react/follow-manage.test.tsx
index 2cc582419..de72d200e 100644
--- a/frontend/test/react/follow-manage.test.tsx
+++ b/frontend/test/react/follow-manage.test.tsx
@@ -568,12 +568,12 @@ it('还有未看时卡底给出计数和三颗动作键,没有未看就整条
expect(buttonNamed('全部忽略', quiet.host)).toBeNull();
});
-it('读数、列表头与卡底的计数都带千分位,六位数以上的读数换小一号字', async () => {
+it('读数、列表头与卡底的计数都带千分位,六位数起读数小一号字、七位数起再小一号', async () => {
const counts = { new: 1284000, seen: 22000, saved: 0, ignored: 0 };
const { host } = await open({ data: follow({ counts }) });
const readings = [...host.querySelectorAll('[data-follow-reading]')];
const big = readings.find((node) => node.textContent === '1,284,000 条')!;
- expect(big.className).toContain('text-title-3-medium');
+ expect(big.className).toContain('text-headline-medium');
expect(big.querySelector('small')?.className).toContain('whitespace-nowrap');
expect(readings.find((node) => node.textContent?.startsWith('0'))?.className).toContain('text-title-1-medium');
expect(host.textContent).toContain('4 个来源 · 1,284,000 条未看');