Public: anyone can read this; the crew can change it.

/explore has a chip that keeps only apps with a live preview #16147

Merged opened this

Check · Review · Land · Live done — Landed and live in production.

Merged

scout/forge:scout/16142-explore-has-a-chip-that-keeps-only-apps → main 0 commits fork

  • Merged. scout/16142-explore-has-a-chip-that-keeps-only-apps was merged into main as 1f34565.

Review

Sign in to review this change.
2 files changed +17 −1
src/web/studio/explore.ts +4
@@ -285,6 +285,9 @@ export async function explorePage(ctx: Ctx): Promise<Response> {
285285 return redirect(text === "" ? "/explore" : `/explore?${text}`, said === undefined ? undefined : { url: ctx.url, forgeUrl: ctx.app.config.url, flash: { tone: "attn", message: said } });
286286 }
287287 const rows = shown.items;
288 // The chip says how many it keeps: the list's own total when on, else the same ranking with it
289 // on.
290 const liveCount = query.live === true ? shown.total : (await explorePageAt(ctx.app, ctx.auth.user, { ...query, live: true }, 1, 1, true)).total;
288291 // Old `?cursor=` links were published; they cannot name a page now, so say so.
289292 const oldLink = ctx.url.searchParams.has("cursor");
290293 const weights = frontWeights(ctx.app.db);
@@ -392,6 +395,7 @@ export async function explorePage(ctx: Ctx): Promise<Response> {
392395 label: "Live now",
393396 href: href(query.live === true ? dropped(query, "live") : { ...query, live: true }),
394397 current: query.live === true,
398 count: liveCount,
395399 },
396400 ])}
397401 </div>
test/explore-quick-filters.test.ts +13 −1
@@ -67,7 +67,7 @@ const names = (html: string): string[] => {
6767 return list === null ? [] : [...list[1]!.matchAll(/<li[^>]*>[\s\S]*?<a href="\/olive\/([^"?]*)">/g)].map((m) => m[1]!).sort();
6868 };
6969 const link = (html: string, label: string): { tag: string; href: string } => {
70 const m = new RegExp(`<a\\s[^>]*>\\s*${label}\\s*</a`).exec(html);
70 const m = new RegExp(`<a\\s[^>]*>\\s*${label}\\s*(?:<[^>]*>\\s*\\d+\\s*</[^>]*>\\s*)?</a`).exec(html);
7171 if (m === null) throw new Error(`no link ${label}`);
7272 return { tag: m[0], href: /href="([^"]*)"/.exec(m[0])![1]!.replaceAll("&amp;", "&") };
7373 };
@@ -119,3 +119,15 @@ test("the links sit on the page, show active when on, and keep the sort", async
119119 expect(link(on, "Live now").href).toContain("sort=forks");
120120 expect(link(on, "Live now").href).not.toContain("live");
121121 });
122
123 test("the Live now chip carries a count that matches the list it opens (#16142)", async () => {
124 const pill = (html: string) => /Live now\s*<[^>]*>\s*(\d+)\s*</.exec(html)?.[1];
125 const bare = (await get("?kind=app")).html;
126 const on = await get(link(bare, "Live now").href.replace("/explore", ""));
127 expect(pill(bare)).toBe(String(names(on.html).length));
128 expect(pill(bare)).toBe("2");
129 // On, the chip still says what the list holds.
130 expect(pill(on.html)).toBe("2");
131 // It follows the other filters: live and changed this week is one app.
132 expect(pill((await get("?kind=app&week=1")).html)).toBe("1");
133 });

↑↓ navigate ↵ open ⌘↵ its app esc close

Keyboard shortcuts

Docs