Skip to content

armgit / peach

Public Imported from GitHub
0

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

fix(web): 整理提示不再跟着每次取数塌一下,该出现时是长出来的

longmeidaob724934cb1ad
diff --git a/frontend/src/islands.ts b/frontend/src/islands.ts
index 470022eaa..4d5fef5e0 100644
--- a/frontend/src/islands.ts
+++ b/frontend/src/islands.ts
@@ -135,6 +135,12 @@ export async function mountIsland<N extends IslandName>(
render(h(island.component, attrs), el);
}
+/** 这个容器上是不是已经挂着一个 island。
+ *
+ * 遗留层据此判断要不要重挂。`mountIsland` 开头就把容器卸干净,而卸载会把画过的
+ * 内容清掉:内容根本没变时,那一下只是一次白白的布局塌陷。 */
+export const islandMounted = (el: Element | null): boolean => !!el && mounted.has(el);
+
/** 卸载容器上的 island:中止在途取数并清空自己画过的内容。没挂过的容器是空操作。 */
export function unmountIsland(el: Element): void {
const mount = mounted.get(el);
diff --git a/frontend/test/islands.test.ts b/frontend/test/islands.test.ts
index 103ddd5d7..30cadd3ed 100644
--- a/frontend/test/islands.test.ts
+++ b/frontend/test/islands.test.ts
@@ -1,6 +1,6 @@
import { afterEach, describe, expect, it, vi } from 'vitest';
-import { islandNames, mountIsland, unmountIsland } from '../src/islands';
+import { islandMounted, islandNames, mountIsland, unmountIsland } from '../src/islands';
import { resetStores } from '../src/state';
import { deferredFetch, goal, legacyProps, payload, seedGoals } from './helpers';
@@ -115,6 +115,23 @@ describe('unmountIsland', () => {
expect(el.querySelector('[data-skeleton]')).not.toBeNull();
});
+ it('容器上挂没挂着,遗留层问得出来', async () => {
+ vi.stubGlobal('fetch', vi.fn(async () => ({
+ ok: true, status: 200, json: async () => payload([goal()]),
+ })));
+ const el = container();
+ expect(islandMounted(el)).toBe(false);
+ // 取数还没回来也算挂着:这段时间里再挂一次会把在途那次作废,白等一趟。
+ const mounting = mountIsland('quality-goals', el, legacyProps());
+ expect(islandMounted(el)).toBe(true);
+ await mounting;
+ expect(islandMounted(el)).toBe(true);
+ unmountIsland(el);
+ expect(islandMounted(el)).toBe(false);
+ // 遗留层拿到的可能是个空引用——那时页面上根本没有这个容器。
+ expect(islandMounted(null)).toBe(false);
+ });
+
it('卸载之后共享状态再变也不重画:订阅要跟着组件一起走', async () => {
vi.stubGlobal('fetch', vi.fn(async () => ({
ok: true, status: 200, json: async () => payload([goal({ id: 1, name: 'one.mp4' })]),
diff --git a/tests/test_web_ui.py b/tests/test_web_ui.py
index af1b6587e..f2e10a137 100644
--- a/tests/test_web_ui.py
+++ b/tests/test_web_ui.py
@@ -5984,6 +5984,29 @@ class WebUiSourceTests(unittest.TestCase):
"margin-bottom .22s cubic-bezier(0,0,.2,1)}", base)
self.assertIn("@media(prefers-reduced-motion:reduce){.combo{transition:none}}", base)
+ def test_the_processing_notice_stays_put_while_the_list_underneath_changes(self):
+ """整理提示讲的是库里那趟后台任务,换一条筛选不该让它塌一下再撑回来。
+
+ 它跟着每次取数卸了再挂:卸载会把画过的内容清掉,重挂又要一整趟请求才画得回来。
+ 实测点一枚标签,底下整块先往上跳 62px,二十来毫秒后落回原处——那一下比它要说
+ 的那句话显眼得多。目录页之间它一直挂着,自己在轮询库那边的进度;离开目录页才
+ 收起,那些页面本来就不该有它。
+
+ 真该出现的那一次仍是从无到有:要不要画得等 `/api/library-processing` 回话。
+ 所以照交集条那样长出来,高度从 0 走到 auto。
+ """
+ self.assertPageContains(" if(!isCatalogPath(path))unmountIsland($('#libraryProcessingNotice'));")
+ self.assertCode(
+ " if(reset&&isCatalogPath(location.pathname)&&!islandMounted($('#libraryProcessingNotice')))\n"
+ " void mountIsland('library-processing',$('#libraryProcessingNotice'),"
+ "{toast,mode:'notice'},{isCurrent:()=>surfaceCurrent(surface)});")
+ board = (Path(__file__).resolve().parents[1] / "web/board.css").read_text(encoding="utf-8")
+ self.assertIn("#libraryProcessingNotice{overflow:hidden;interpolate-size:allow-keywords;height:auto;",
+ board)
+ self.assertIn("#libraryProcessingNotice:empty{height:0}", board)
+ self.assertIn("@media(prefers-reduced-motion:reduce){#libraryProcessingNotice{transition:none}}",
+ board)
+
def test_untagged_detail_uses_home_tags_only_in_the_top_discovery_bar(self):
# 作品没有内容标签时,顶部发现栏回退首页口径;详情抽屉仍使用作品 scoped facets。
self.assertPageContains("if(context.type==='item'&&!topTags.length)")
diff --git a/web/app.js b/web/app.js
index 23bb8efe1..657899322 100644
--- a/web/app.js
+++ b/web/app.js
@@ -9,7 +9,7 @@ import { javDisplayName, javTitleHtml } from './js/jav-title.js';
import { matchRoute, routeLabel } from './js/routes.js';
import { initMiddleTruncate } from './js/middle-truncate.js';
import { tagLabel } from './js/tags.js';
-import { mountIsland, unmountIsland, createReviewSelection, wireReviewSelection, updateReviewSticky, groupReviewRows, paginationHtml, pageCount, clampPage, identityEvidenceHtml, reviewImageHtml, wireReviewPictures, preferredDirection } from './dist/peach-ui.js';
+import { mountIsland, unmountIsland, islandMounted, createReviewSelection, wireReviewSelection, updateReviewSticky, groupReviewRows, paginationHtml, pageCount, clampPage, identityEvidenceHtml, reviewImageHtml, wireReviewPictures, preferredDirection } from './dist/peach-ui.js';
import { catalogSuggestions, catalogEmptyHtml, emptyCatalogLayout, syncSidebarSurface, sidebarTagCounts, sidebarHasCatalogContent, cleanupSkeletonHtml, cloudLocations, cloudPreferenceLocations, tasteHistoryGuideHtml, wireTasteHistoryGuide, TASTE_GUIDE_KEY } from './dist/peach-ui.js';
import { javImageKind, normalizeJavImage, normalizeJavLayout, normalizeJavPreferences, syncJavImages, nativeImageFit, matchesFaceSource, entitySkeletonHtml } from './dist/peach-ui.js';
import {
@@ -352,7 +352,11 @@ let surfaceRequests=null;
const surfaceToken=path=>({epoch:surfaceEpoch,path,signal:surfaceRequests?.signal});
const surfaceCurrent=token=>token.epoch===surfaceEpoch&&surfacePath()===token.path;
const claimSurface=path=>{
- unmountIsland($('#libraryProcessingNotice'));
+ /* 那条横幅讲的是库里那趟后台任务的下场,跟当前看的是哪一份名单无关。跟着每次取数
+ 卸了再挂,换一条筛选就会让它塌一下再撑回来——实测那一下底下整块先往上跳 62px,
+ 二十来毫秒后落回原处,比它要说的那句话显眼得多。目录页之间它一直挂着,自己在轮询
+ 库那边的进度;离开目录页才收起,那些页面本来就不该有它。 */
+ if(!isCatalogPath(path))unmountIsland($('#libraryProcessingNotice'));
surfaceRequests?.abort();
surfaceRequests=new AbortController();
surfaceEpoch++;return surfaceToken(path)};
@@ -8222,7 +8226,9 @@ $('#scrim').onclick=()=>openDrawer(false);
async function load(reset){
const requestSeq=reset?++loadRequestSeq:loadRequestSeq;
const surface=reset?claimSurface(surfacePath()):surfaceToken(surfacePath());
- if(reset&&isCatalogPath(location.pathname))void mountIsland('library-processing',$('#libraryProcessingNotice'),{toast,mode:'notice'},{isCurrent:()=>surfaceCurrent(surface)});
+ // 已经挂着就让它接着跑:重挂要先清空容器,而它这一刻要说的话跟上一刻是同一句。
+ if(reset&&isCatalogPath(location.pathname)&&!islandMounted($('#libraryProcessingNotice')))
+ void mountIsland('library-processing',$('#libraryProcessingNotice'),{toast,mode:'notice'},{isCurrent:()=>surfaceCurrent(surface)});
if(!reset&&listLoading)return;
if(!reset)listLoading=true;
try{
diff --git a/web/board.css b/web/board.css
index 39f83a443..10caf9b26 100644
--- a/web/board.css
+++ b/web/board.css
@@ -378,7 +378,14 @@ body :is(#manageTitle,#manageCrumb,#manageLede){max-width:var(--board-content);w
/* 首页那条整理提示是正文列里的一条 Note,上下两条线是它自己的收口。少了这个空当,
两条线一边挨着身份行、一边挨着筛选浮层,看着像三块东西粘在一起。下面照浮层那个数
留一样宽(上面由 `.tiers` 收尾与 `main` 上沿凑够)。 */
+/* 要不要画这一条,得等 `/api/library-processing` 回话才知道,而它一出现就把底下整块
+ 推下六十来像素。跟交集条同一个处理:高度从 0 走到 auto,二百来毫秒,推的过程看得见
+ 就不叫跳。那趟任务跑完它自己会消失,缩回去同样是走的。 */
+#libraryProcessingNotice{overflow:hidden;interpolate-size:allow-keywords;height:auto;
+ transition:height .22s cubic-bezier(0,0,.2,1),margin-bottom .22s cubic-bezier(0,0,.2,1)}
+#libraryProcessingNotice:empty{height:0}
#libraryProcessingNotice:not(:empty){margin:0 0 22px}
+@media(prefers-reduced-motion:reduce){#libraryProcessingNotice{transition:none}}
.board-card-icon{display:inline-flex;align-items:center;justify-content:center;width:32px;height:32px;border:1px solid var(--line-soft);background:var(--surface);border-radius:10px;margin-right:10px;vertical-align:middle;color:var(--ink-2)}
.board-card-icon svg{width:17px;height:17px;fill:none;stroke:currentColor;stroke-width:2;stroke-linecap:round;stroke-linejoin:round}
.configfieldset{border:1px solid var(--line);border-radius:16px;box-shadow:0 1px 2px #00000003}
diff --git a/web/dist/peach-ui.js b/web/dist/peach-ui.js
index 1c328793c..99f4fe8f0 100644
--- a/web/dist/peach-ui.js
+++ b/web/dist/peach-ui.js
@@ -4472,7 +4472,7 @@ var ki = {
async function Mi(e, t, n, r = {}) {
let i = ki[e];
if (!i) throw Error(`未注册的 island:${String(e)}`);
- Ni(t);
+ Pi(t);
let a = {
controller: new AbortController(),
painted: !1
@@ -4503,9 +4503,10 @@ async function Mi(e, t, n, r = {}) {
};
Oe(ae(i.component, s), t);
}
-function Ni(e) {
+var Ni = (e) => !!e && ji.has(e);
+function Pi(e) {
let t = ji.get(e);
t && (t.controller.abort(), ji.delete(e), t.painted && Oe(null, e));
}
//#endregion
-export { yt as TASTE_GUIDE_KEY, _n as activityChartsHtml, mi as boardPageSkeleton, je as boundedPreference, vi as catalogEmptyHtml, _i as catalogSuggestions, li as clampPage, _t as cleanupSkeletonHtml, ht as cloudLocations, gt as cloudPreferenceLocations, $r as createReviewSelection, dn as creatorSankeyHtml, Ie as distributionChart, gi as emptyCatalogLayout, pi as entitySkeletonHtml, lt as followJobProgress, ni as groupReviewRows, Zr as identityEvidenceHtml, Tt as initBoardControls, Ai as islandNames, Di as javImageKind, Fe as jobProgressHtml, di as matchesFaceSource, Ct as mountBoardStatePreview, Mi as mountIsland, Ne as mountNumberSetting, fi as nativeImageFit, Ei as normalizeJavImage, wi as normalizeJavLayout, Ti as normalizeJavPreferences, ci as pageCount, ui as paginationHtml, ke as preferredDirection, Re as radarChart, mn as radialCardHtml, Le as rankedChart, Jr as refreshStore, Ci as resourceScanHtml, Xr as reviewImageHtml, yi as sidebarHasCatalogContent, bn as sidebarSectionHtml, xi as sidebarTagCounts, Pe as statCardBody, qr as storeNames, wt as syncBoardRange, Oi as syncJavImages, Me as syncNumberSetting, bi as syncSidebarSurface, vt as tasteHistoryGuideHtml, Cn as transitionTheme, Ni as unmountIsland, ei as updateReviewSticky, ct as watchJob, vn as wireActivityCharts, fn as wireCreatorSankey, At as wireExpandableRanks, kt as wireGrowingCharts, hn as wireRadialCards, Qr as wireReviewPictures, oi as wireReviewSelection, xn as wireSidebarGroups, bt as wireTasteHistoryGuide };
+export { yt as TASTE_GUIDE_KEY, _n as activityChartsHtml, mi as boardPageSkeleton, je as boundedPreference, vi as catalogEmptyHtml, _i as catalogSuggestions, li as clampPage, _t as cleanupSkeletonHtml, ht as cloudLocations, gt as cloudPreferenceLocations, $r as createReviewSelection, dn as creatorSankeyHtml, Ie as distributionChart, gi as emptyCatalogLayout, pi as entitySkeletonHtml, lt as followJobProgress, ni as groupReviewRows, Zr as identityEvidenceHtml, Tt as initBoardControls, Ni as islandMounted, Ai as islandNames, Di as javImageKind, Fe as jobProgressHtml, di as matchesFaceSource, Ct as mountBoardStatePreview, Mi as mountIsland, Ne as mountNumberSetting, fi as nativeImageFit, Ei as normalizeJavImage, wi as normalizeJavLayout, Ti as normalizeJavPreferences, ci as pageCount, ui as paginationHtml, ke as preferredDirection, Re as radarChart, mn as radialCardHtml, Le as rankedChart, Jr as refreshStore, Ci as resourceScanHtml, Xr as reviewImageHtml, yi as sidebarHasCatalogContent, bn as sidebarSectionHtml, xi as sidebarTagCounts, Pe as statCardBody, qr as storeNames, wt as syncBoardRange, Oi as syncJavImages, Me as syncNumberSetting, bi as syncSidebarSurface, vt as tasteHistoryGuideHtml, Cn as transitionTheme, Pi as unmountIsland, ei as updateReviewSticky, ct as watchJob, vn as wireActivityCharts, fn as wireCreatorSankey, At as wireExpandableRanks, kt as wireGrowingCharts, hn as wireRadialCards, Qr as wireReviewPictures, oi as wireReviewSelection, xn as wireSidebarGroups, bt as wireTasteHistoryGuide };