Public: anyone can read this; the crew can change it.
/explore has a chip that keeps only apps with a live preview #16147
Check · Review · Land · Live done — Landed and live in production.
scout/forge:scout/16142-explore-has-a-chip-that-keeps-only-apps → main 0 commits fork
2 files
changed +17
−1
src/web/studio/explore.ts +4
| @@ -285,6 +285,9 @@ export async function explorePage(ctx: Ctx): Promise<Response> { | ||
| 285 | 285 | return redirect(text === "" ? "/explore" : `/explore?${text}`, said === undefined ? undefined : { url: ctx.url, forgeUrl: ctx.app.config.url, flash: { tone: "attn", message: said } }); |
| 286 | 286 | } |
| 287 | 287 | 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; | |
| 288 | 291 | // Old `?cursor=` links were published; they cannot name a page now, so say so. |
| 289 | 292 | const oldLink = ctx.url.searchParams.has("cursor"); |
| 290 | 293 | const weights = frontWeights(ctx.app.db); |
| @@ -392,6 +395,7 @@ export async function explorePage(ctx: Ctx): Promise<Response> { | ||
| 392 | 395 | label: "Live now", |
| 393 | 396 | href: href(query.live === true ? dropped(query, "live") : { ...query, live: true }), |
| 394 | 397 | current: query.live === true, |
| 398 | count: liveCount, | |
| 395 | 399 | }, |
| 396 | 400 | ])} |
| 397 | 401 | </div> |
test/explore-quick-filters.test.ts +13 −1
| @@ -67,7 +67,7 @@ const names = (html: string): string[] => { | ||
| 67 | 67 | return list === null ? [] : [...list[1]!.matchAll(/<li[^>]*>[\s\S]*?<a href="\/olive\/([^"?]*)">/g)].map((m) => m[1]!).sort(); |
| 68 | 68 | }; |
| 69 | 69 | 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); | |
| 71 | 71 | if (m === null) throw new Error(`no link ${label}`); |
| 72 | 72 | return { tag: m[0], href: /href="([^"]*)"/.exec(m[0])![1]!.replaceAll("&", "&") }; |
| 73 | 73 | }; |
| @@ -119,3 +119,15 @@ test("the links sit on the page, show active when on, and keep the sort", async | ||
| 119 | 119 | expect(link(on, "Live now").href).toContain("sort=forks"); |
| 120 | 120 | expect(link(on, "Live now").href).not.toContain("live"); |
| 121 | 121 | }); |
| 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 | }); |
new above
offline