Skip to content

armgit / peach

Public Imported from GitHub
0

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

fix(feed): 人物页新作那一行只等一遍,订阅图标没订时呼吸并带说明

longmeidao614873769236
diff --git a/frontend/e2e/design.test.ts b/frontend/e2e/design.test.ts
index f62ac4c98..50aad3fd8 100644
--- a/frontend/e2e/design.test.ts
+++ b/frontend/e2e/design.test.ts
@@ -1254,12 +1254,29 @@ describe('设计决定', () => {
const toggle = opened.page.getByRole('switch', { name: '订阅新作' });
assert.equal(await toggle.count(), 1, '资料卡上没有订阅新作开关');
assert.equal(await toggle.isChecked(), false);
+ const feed = opened.page.locator('.entryfeed');
+ await opened.page.emulateMedia({ reducedMotion: 'no-preference' });
+ assert.equal(await feed.evaluate((element) => getComputedStyle(element).animationName),
+ 'entryfeed-breathe', '没订的那枚图标不呼吸,一枚墨色小图标没人注意到');
+ const tip = opened.page.locator('#entityFeedTip');
+ assert.equal(await tip.isVisible(), false);
+ await feed.hover();
+ assert.equal(await tip.isVisible(), true, '悬停没有说明这枚图标是干嘛的');
+ assert.match(await tip.innerText(), /JavDB/);
+ const placed = await tip.evaluate((element) => {
+ const box = element.getBoundingClientRect();
+ return box.left >= 0 && box.right <= innerWidth && box.bottom <= innerHeight;
+ });
+ assert.ok(placed, '说明浮层越出了视口');
+ await toggle.focus();
+ await opened.page.keyboard.press('Escape');
+ assert.equal(await tip.isVisible(), false, 'Escape 收不起说明浮层');
} finally {
await opened.close();
}
});
- it('订阅了的人物页先按真卡轮廓占住新作那一行,数据到了行高不变', { timeout: 60_000 }, async () => {
+ it('订阅了的人物页先按真卡轮廓占住新作那一行,数据到了行高不变、封面不再等第二遍', { timeout: 60_000 }, async () => {
const name = '七沢みあ';
const opened = await visit(browser, '/', DESKTOP);
try {
@@ -1275,10 +1292,15 @@ describe('设计决定', () => {
await held;
await route.fulfill({ json: { ok: true, more: false, items: [{
id: 1, code: 'ABC-001', title: '标题', link: 'https://javdb.com/v/x', cover_url: null,
- has_cover: false, cover_frame: null, poster_box: null, release_date: '2026-09-01',
+ has_cover: true, cover_frame: null, poster_box: null, release_date: '2026-09-01',
studio: '厂牌', performers: name, source_name: '', read: false, ignored: false,
scrape_error: null }] } });
});
+ // 封面比数据晚到一截:骨架要等它,而不是先换上真卡、再在封面格里微光一遍。
+ await opened.page.route(/\/cover\?code=ABC-001/, async (route) => {
+ await new Promise((resolve) => setTimeout(resolve, 400));
+ await route.fulfill({ contentType: 'image/png', body: Buffer.from(PIXEL, 'base64') });
+ });
await opened.page.goto(new URL(`/performers/${encodeURIComponent(name)}`,
opened.page.url()).href, { waitUntil: 'load' });
const row = opened.page.locator('[data-feed-new]');
@@ -1287,9 +1309,11 @@ describe('设计决定', () => {
release();
await row.locator('[data-feed-id]').waitFor({ timeout: 15_000 });
const after = await row.evaluate((element) => ({
- height: element.getBoundingClientRect().height, busy: element.getAttribute('aria-busy') }));
+ height: element.getBoundingClientRect().height, busy: element.getAttribute('aria-busy'),
+ waiting: element.querySelectorAll('[data-feed-id] .pic.imgwait').length }));
assert.equal(after.height, before, '占位行和到货的那一行不一样高,下面的作品网格会跳');
assert.equal(after.busy, null);
+ assert.equal(after.waiting, 0, '骨架退场后封面格里又微光了一遍');
assert.deepEqual(opened.problems, []);
} finally {
await opened.close();
diff --git a/web/app.js b/web/app.js
index 60759e4e9..16ab6a9af 100644
--- a/web/app.js
+++ b/web/app.js
@@ -4764,6 +4764,20 @@ function feedNewCardHtml(item){
不占的话,那一行在资料卡和作品之间凭空插进来,把下面整个作品网格往下推一截。
封面格直接挂 `imgwait`,微光与真卡等封面时同一种订阅橙。 */
const FEED_SKELETON_CARDS=8;
+const FEED_COVER_WAIT=1500;
+/* 把一段 HTML 里头 `count` 张图先取进缓存,最多等 `ms` 毫秒。插进页面时它们已经
+ `complete`,`watchPendingImages` 不再给它们挂微光。 */
+function preloadImages(html,count,ms){
+ const probe=document.createElement('template');
+ probe.innerHTML=html;
+ const loads=[...probe.content.querySelectorAll('img[src]')].slice(0,count).map(source=>{
+ const img=new Image();
+ img.referrerPolicy=source.getAttribute('referrerpolicy')||'';
+ img.src=source.getAttribute('src');
+ return img.decode().catch(()=>{});
+ });
+ return Promise.race([Promise.all(loads),new Promise(resolve=>setTimeout(resolve,ms))]);
+}
const feedNewSkeletonHtml=()=>`<div class="feednewrow srow" aria-hidden="true">${
`<article class="card feednewcard feednewskeleton"><div class="pic imgwait" style="--card-ratio:${COVER_FRONT_RATIO}"></div>
<div class="meta"><div class="mtext"><span class="t"><span class="skeleton"></span></span>
@@ -4781,10 +4795,17 @@ async function renderFeedNew(host,entityId){
// 取数期间人已经离开了这一页:首页那一行不画到管理区上,人物页那一行的容器已经换掉。
if(!host.isConnected||host.id==='feedNew'&&!isCatalogPath(location.pathname))return;
const items=data&&!data.error?(data.items||[]):[];
+ const html=`<div class="feednewrow srow">${items.map(feedNewCardHtml).join('')}</div>`;
+ // 骨架还占着时,先把头几张封面取到手再整行换掉:否则骨架退场、真卡进来,封面格里
+ // 又是一轮微光,同一行等了两遍。慢的那几张不等满,到点照换,剩下的留给卡片自己的等待态。
+ if(items.length&&host.getAttribute('aria-busy')==='true'){
+ await preloadImages(html,FEED_SKELETON_CARDS,FEED_COVER_WAIT);
+ if(!host.isConnected||host.id==='feedNew'&&!isCatalogPath(location.pathname))return;
+ }
host.removeAttribute('aria-busy');
if(!items.length){host.hidden=true;host.innerHTML='';return}
host.hidden=false;
- host.innerHTML=`<div class="feednewrow srow">${items.map(feedNewCardHtml).join('')}</div>`;
+ host.innerHTML=html;
host.querySelectorAll('[data-feed-action]').forEach(button=>button.onclick=async()=>{
const card=button.closest('[data-feed-id]');
const action=button.dataset.feedAction;
@@ -4816,10 +4837,18 @@ function syncFeedAutoScroll(){
开或关。打开时服务端当场在后台拉一轮,拉完这里把未入库的新作那一行重画一次;
等的上限是那一轮自己的时长量级,页面换走了就不再等。 */
const ENTITY_FEED_WAIT_TRIES=40;
+const entityFeedTip=on=>on
+ ?'已订阅新作:库里还没有的新片排在资料卡下面。再点一下取消订阅。'
+ :'订阅新作:定时去 JavDB 查这位有没有出新片,库里还没有的排在资料卡下面。';
function wireEntityFeed(entityId){
const toggle=$('#index').querySelector('[data-entity-feed]');
if(!toggle||!entityId)return;
const onPage=()=>$('#index').contains(toggle);
+ const label=toggle.closest('.entryfeed'),tip=label.querySelector('.entryfeedtip');
+ // Escape 只收起这一次;指针离开或焦点移走后,下一次悬停照常出现。
+ toggle.addEventListener('keydown',event=>{if(event.key==='Escape')label.dataset.tipDismissed=''});
+ const restore=()=>delete label.dataset.tipDismissed;
+ label.addEventListener('pointerleave',restore);toggle.addEventListener('blur',restore);
const write=async on=>{
setActionBusy(toggle);
try{
@@ -4830,7 +4859,7 @@ function wireEntityFeed(entityId){
}catch(error){
toggle.checked=!on;actionFailure(on?'订阅新作':'取消订阅新作',error);
return false;
- }finally{setActionBusy(toggle,false)}
+ }finally{setActionBusy(toggle,false);tip.textContent=entityFeedTip(toggle.checked)}
};
const refreshAfterCheck=async()=>{
for(let tries=0;tries<ENTITY_FEED_WAIT_TRIES&&onPage();tries+=1){
@@ -8181,8 +8210,9 @@ async function openEntity(kind,name,push=true){
`<a class="entrymark" href="${esc(x.url)}" target="_blank" rel="noreferrer" title="${esc(x.label)}">${
x.mark?icon(x.mark):'<span class="missavmark"><span>MISS</span><span>AV</span></span>'
}${x.ordinal?`<span class="entryordinal">${esc(x.ordinal)}</span>`:''}<span class="sr-only">${esc(x.label)}</span></a>`
- ).join('')+(d.feed?`<label class="entryfeed" title="订阅新作">${icon('rss')}<input type="checkbox"
- class="sr-only" role="switch" aria-label="订阅新作" data-entity-feed ${d.feed.following?'checked':''}></label>`:'');
+ ).join('')+(d.feed?`<label class="entryfeed">${icon('rss')}<input type="checkbox"
+ class="sr-only" role="switch" aria-label="订阅新作" aria-describedby="entityFeedTip" data-entity-feed ${d.feed.following?'checked':''}><span
+ class="entryfeedtip" role="tooltip" id="entityFeedTip">${entityFeedTip(d.feed.following)}</span></label>`:'');
const tags=(d.tags||[]).map(x=>filterChipHtml(tagLabel(x.k),{attr:'data-entity-tag',value:x.k,selected:tagPressed(filters.tag,x.k),count:x.n.toLocaleString()})).join('');
/* 事务所名下的这批人不摆在这排小圆头像里:那是「同台艺人」,一条附注;名册是这一页
的正文,占的是下面那整块。所以同一份 `related_performers` 在事务所页走另一条路。 */
diff --git a/web/css/07-entity.css b/web/css/07-entity.css
index 94fd6c21d..bbf7e49ce 100644
--- a/web/css/07-entity.css
+++ b/web/css/07-entity.css
@@ -101,6 +101,18 @@
.entryfeed:has(:focus-visible){outline:2px solid var(--tungsten);outline-offset:2px}
.entryfeed:has([aria-busy="true"]){cursor:progress;opacity:.6}
.entryfeed svg{width:22px;height:22px;stroke:currentColor;fill:none;stroke-width:2}
+/* 没订的时候那枚图标在墨色和订阅橙之间慢慢呼吸:一枚墨色小图标排在两枚彩色标识后面,
+ 不提醒就没人知道它能点。只动颜色,重绘只落在这 22px 上;订上就停在橙色。 */
+@keyframes entryfeed-breathe{0%,100%{color:var(--ink)}50%{color:var(--feed-mark)}}
+.entryfeed:not(:has(:checked)){animation:entryfeed-breathe 2.4s ease-in-out infinite}
+.entryfeed:not(:has(:checked)):is(:hover,:has(:focus-visible)){animation:none;color:var(--feed-mark)}
+/* 图标的说明走 Tooltip(Geist 实测:最宽 250px、8px 圆角、内边距 8/6px、13px 字、
+ 1.3 行高),不复制箭头与淡入。悬停和键盘聚焦都出,Escape 收起。 */
+.entryfeedtip{position:absolute;z-index:var(--layer-tooltip);top:calc(100% + 8px);left:0;
+ display:none;width:max-content;max-width:250px;padding:6px 8px;border-radius:var(--surface-radius);
+ background:var(--ink);color:var(--ground);font-size:var(--fs-sm);font-weight:400;line-height:1.3;
+ white-space:normal;pointer-events:none}
+.entryfeed:is(:hover,:has(:focus-visible)):not([data-tip-dismissed])>.entryfeedtip{display:block}
/* 两枚标识按字母的高度对齐,不按外框:JavDB 那枚里 `Jav` 三个字母占 viewBox 高的
71/111,高 22px 时是 14.1px;MISSAV 是排出来的字,衬线体的大写字母高约 0.71em,
`--fs-xl` 时是 14.2px。外框对齐的话 MISSAV 的字母比 `Jav` 高出两成,一眼看过去它大一号。