From 1bd88ec81cf76290b36bcf5feb9f6afde2a722a1 Mon Sep 17 00:00:00 2001 From: Aden Linday Date: Fri, 30 Oct 2026 19:40:48 +1030 Subject: [PATCH] feat: support for theme submitter badge plus multiuple badge handling --- src/css/injected.scss | 6 ++ .../pages/settings/sections/account.svelte | 4 +- .../founderBadge/mountTitlebarFounderBadge.ts | 62 +++++++---- .../ui/founderBadge/openFounderBadgeModal.ts | 20 ++-- src/seqta/utils/founderBadges.test.ts | 23 ++++ src/seqta/utils/founderBadges.ts | 100 ++++++++++++------ src/types/storage.ts | 2 +- 7 files changed, 151 insertions(+), 66 deletions(-) create mode 100644 src/seqta/utils/founderBadges.test.ts diff --git a/src/css/injected.scss b/src/css/injected.scss index 74d4a9a5..040f993e 100644 --- a/src/css/injected.scss +++ b/src/css/injected.scss @@ -3895,6 +3895,12 @@ div.day-empty { width: 100%; margin-top: 4px; } +.bsplus-founder-badge-stack { + display: flex; + flex-direction: column; + gap: 4px; + width: 100%; +} .userInfoHouseWrap .bsplus-founder-badge-slot[hidden], .bsplus-founder-badge-slot[hidden] { display: none; diff --git a/src/interface/pages/settings/sections/account.svelte b/src/interface/pages/settings/sections/account.svelte index 6c127d7f..f74e10c8 100644 --- a/src/interface/pages/settings/sections/account.svelte +++ b/src/interface/pages/settings/sections/account.svelte @@ -25,8 +25,8 @@ }); const founderBadgeSetting = { - title: "Titlebar founder badge", - description: "Show your Cloud founder badge in the SEQTA titlebar", + title: "Titlebar Cloud badges", + description: "Show your Cloud badges in the SEQTA titlebar", } as const; const showCloudCardHeader = $derived( diff --git a/src/seqta/ui/founderBadge/mountTitlebarFounderBadge.ts b/src/seqta/ui/founderBadge/mountTitlebarFounderBadge.ts index af38f2f2..47b7f441 100644 --- a/src/seqta/ui/founderBadge/mountTitlebarFounderBadge.ts +++ b/src/seqta/ui/founderBadge/mountTitlebarFounderBadge.ts @@ -2,18 +2,19 @@ import { cloudAuth } from "@/seqta/utils/CloudAuth"; import { refreshCloudUserFromServer } from "@/seqta/utils/cloudPfpSync"; import { settingsState } from "@/seqta/utils/listeners/SettingsState"; import { + badgesForTitlebar, founderBadgeChipHtml, - pickPrimaryFounderBadge, - type FounderBadgeItem, + type BadgeItem, } from "@/seqta/utils/founderBadges"; import { openFounderBadgeModal } from "@/seqta/ui/founderBadge/openFounderBadgeModal"; let subscribed = false; let refreshPending = false; +let profileSyncedThisSession = false; -function renderBadgeChip( +function renderTitlebarBadges( slot: HTMLElement, - badge: FounderBadgeItem, + badges: BadgeItem[], signupNumber?: number | null, ): void { const house = slot @@ -25,14 +26,25 @@ function renderBadgeChip( return; } + const chips = badges + .map((b) => founderBadgeChipHtml(b, { titlebar: true })) + .filter(Boolean) + .join(""); + if (!chips) { + slot.replaceChildren(); + slot.hidden = true; + return; + } + slot.hidden = false; - slot.innerHTML = founderBadgeChipHtml(badge, { titlebar: true }); + slot.innerHTML = `
${chips}
`; - const chip = slot.querySelector(".bsplus-founder-badge"); - if (!chip) return; - - chip.setAttribute("aria-label", `${badge.label}, click for details`); - chip.addEventListener("click", () => openFounderBadgeModal(badge, signupNumber)); + slot.querySelectorAll(".bsplus-founder-badge").forEach((chip) => { + const badge = badges.find((b) => b.key === chip.dataset.tier); + if (!badge) return; + chip.setAttribute("aria-label", `${badge.label}, click for details`); + chip.addEventListener("click", () => openFounderBadgeModal(badge, signupNumber)); + }); } async function syncTitlebarFounderBadge(): Promise { @@ -45,23 +57,24 @@ async function syncTitlebarFounderBadge(): Promise { if (settingsState.showTitlebarFounderBadge === false || !cloudAuth.state.isLoggedIn) return; let user = cloudAuth.state.user; - if (user && user.signup_number == null && !user.badges?.length) { - if (!refreshPending) { - refreshPending = true; - try { - await refreshCloudUserFromServer(); - user = cloudAuth.state.user; - } finally { - refreshPending = false; - } + const needsProfileSync = + !profileSyncedThisSession || (user?.signup_number == null && !user?.badges?.length); + if (needsProfileSync && !refreshPending) { + refreshPending = true; + try { + await refreshCloudUserFromServer(); + user = cloudAuth.state.user; + profileSyncedThisSession = true; + } finally { + refreshPending = false; } } - const badge = pickPrimaryFounderBadge(user?.badges ?? [], user?.signup_number); - if (!badge) return; + const badges = badgesForTitlebar(user?.badges ?? [], user?.signup_number); + if (badges.length === 0) return; for (const slot of slots) { - renderBadgeChip(slot, badge, user?.signup_number); + renderTitlebarBadges(slot, badges, user?.signup_number); } } @@ -72,7 +85,10 @@ export function refreshTitlebarFounderBadge(): void { export function ensureTitlebarFounderBadgeMounted(): void { if (!subscribed) { subscribed = true; - cloudAuth.subscribe(() => void syncTitlebarFounderBadge()); + cloudAuth.subscribe((state) => { + if (!state.isLoggedIn) profileSyncedThisSession = false; + void syncTitlebarFounderBadge(); + }); settingsState.register("showTitlebarFounderBadge", () => void syncTitlebarFounderBadge()); } void syncTitlebarFounderBadge(); diff --git a/src/seqta/ui/founderBadge/openFounderBadgeModal.ts b/src/seqta/ui/founderBadge/openFounderBadgeModal.ts index 039c2c94..91e8a4c6 100644 --- a/src/seqta/ui/founderBadge/openFounderBadgeModal.ts +++ b/src/seqta/ui/founderBadge/openFounderBadgeModal.ts @@ -2,10 +2,10 @@ import stringToHTML from "@/seqta/utils/stringToHTML"; import { closePopup, openPopup } from "@/seqta/utils/Openers/PopupManager"; import { openFounderBadgeSettings } from "@/seqta/ui/founderBadge/openFounderBadgeSettings"; import { + badgeBlobStyle, + badgeVisualForKey, founderBadgeChipHtml, - tierBlobStyle, - tierForBadgeKey, - type FounderBadgeItem, + type BadgeItem, } from "@/seqta/utils/founderBadges"; const ACCOUNTS_URL = "https://accounts.betterseqta.org"; @@ -19,27 +19,27 @@ function esc(value: string): string { } export function openFounderBadgeModal( - badge: FounderBadgeItem, + badge: BadgeItem, signupNumber?: number | null, ): void { - const tier = tierForBadgeKey(badge.key); - if (!tier) return; + const visual = badgeVisualForKey(badge.key, badge.label); + if (!visual) return; const header = stringToHTML(/* html */ `

${esc(badge.label)}

-

${esc(tier.rankLabel)}

+

${esc(visual.rankLabel)}

`).firstChild as HTMLElement; const signupLine = - signupNumber != null + signupNumber != null && badge.key.startsWith("founder_") ? `` : ""; const hero = stringToHTML(/* html */ `
-
+
@@ -51,7 +51,7 @@ export function openFounderBadgeModal( const text = stringToHTML(/* html */ `
-

${esc(tier.description)}

+

${esc(visual.description)}

Linked to your BetterSEQTA Cloud account at accounts.betterseqta.org. diff --git a/src/seqta/utils/founderBadges.test.ts b/src/seqta/utils/founderBadges.test.ts new file mode 100644 index 00000000..a0a6b5a5 --- /dev/null +++ b/src/seqta/utils/founderBadges.test.ts @@ -0,0 +1,23 @@ +import { badgesForTitlebar } from "./founderBadges"; + +describe("badgesForTitlebar", () => { + it("shows one founder plus achievements from API lists", () => { + expect( + badgesForTitlebar( + [ + { key: "founder_1000", label: "Thousand Club" }, + { key: "theme_submitter", label: "Theme Submitter" }, + ], + 842, + ).map((b) => b.key), + ).toEqual(["founder_1000", "theme_submitter"]); + }); + + it("derives founder from signup_number when the API omits the founder row", () => { + expect( + badgesForTitlebar([{ key: "theme_submitter", label: "Theme Submitter" }], 42).map( + (b) => b.key, + ), + ).toEqual(["founder_50", "theme_submitter"]); + }); +}); diff --git a/src/seqta/utils/founderBadges.ts b/src/seqta/utils/founderBadges.ts index 98da3005..69fe9bf3 100644 --- a/src/seqta/utils/founderBadges.ts +++ b/src/seqta/utils/founderBadges.ts @@ -1,4 +1,4 @@ -/** Founder badge tiers — keep in sync with betterseqta-accounts/utils/badges.ts */ +/** Keep in sync with betterseqta-accounts `utils/badges.ts` / `utils/badgeVisuals.ts`. */ export const BADGE_TIERS = [ { @@ -83,38 +83,57 @@ export const BADGE_TIERS = [ }, ] as const; +export const ACHIEVEMENT_BADGES = [ + { + key: "theme_submitter", + label: "Theme Submitter", + rankLabel: "Community", + description: + "Submitted a custom theme that was accepted into the BetterSEQTA theme gallery.", + base: "#5b21b6", + blobs: ["rgba(139,92,246,0.52)", "rgba(124,58,237,0.46)", "rgba(196,181,253,0.4)"], + icon: "swatch", + }, +] as const; + export type BadgeKey = (typeof BADGE_TIERS)[number]["key"]; -export type FounderBadgeItem = { +export type BadgeItem = { key: string; label: string; awarded_at?: number; }; +type BadgeVisual = (typeof BADGE_TIERS)[number] | (typeof ACHIEVEMENT_BADGES)[number]; + const TIER_BY_KEY = new Map(BADGE_TIERS.map((t) => [t.key, t])); +const VISUAL_BY_KEY = new Map([ + ...BADGE_TIERS.map((t) => [t.key, t] as const), + ...ACHIEVEMENT_BADGES.map((b) => [b.key, b] as const), +]); -export function tierForBadgeKey(key: string) { - return TIER_BY_KEY.get(key as BadgeKey); -} +const UNKNOWN_ACHIEVEMENT_VISUAL = { + rankLabel: "Achievement", + description: "Earned on your BetterSEQTA Cloud account.", + base: "#334155", + blobs: ["rgba(100,116,139,0.5)", "rgba(71,85,105,0.44)", "rgba(148,163,184,0.38)"], + icon: "sparkles", +} as const; -export function primaryFounderBadgeKey(signupNumber: number): BadgeKey | null { - const tier = BADGE_TIERS.find((t) => signupNumber <= t.threshold); - return tier?.key ?? null; -} - -export function pickPrimaryFounderBadge( - badges: FounderBadgeItem[], +function primaryFounderBadge( + badges: BadgeItem[], signupNumber?: number | null, -): FounderBadgeItem | null { +): BadgeItem | null { + const fromApi = badges.find((b) => b.key.startsWith("founder_")); + if (fromApi) return fromApi; + if (signupNumber != null) { - const key = primaryFounderBadgeKey(signupNumber); - if (!key) return null; - return badges.find((b) => b.key === key) ?? { key, label: TIER_BY_KEY.get(key)?.label ?? key }; + const tier = BADGE_TIERS.find((t) => signupNumber <= t.threshold); + if (!tier) return null; + return badges.find((b) => b.key === tier.key) ?? { key: tier.key, label: tier.label }; } - if (badges.length === 0) return null; - - let best: FounderBadgeItem | null = null; + let best: BadgeItem | null = null; let bestThreshold = Infinity; for (const badge of badges) { const tier = TIER_BY_KEY.get(badge.key as BadgeKey); @@ -126,6 +145,23 @@ export function pickPrimaryFounderBadge( return best; } +/** Founder pill (at most one) then achievement pills — matches Accounts display rules. */ +export function badgesForTitlebar( + badges: BadgeItem[], + signupNumber?: number | null, +): BadgeItem[] { + const founder = primaryFounderBadge(badges, signupNumber); + const achievements = badges.filter((b) => !b.key.startsWith("founder_")); + return founder ? [founder, ...achievements] : achievements; +} + +export function badgeVisualForKey(key: string, labelFallback = key): BadgeVisual | null { + const known = VISUAL_BY_KEY.get(key); + if (known) return known; + if (key.startsWith("founder_")) return null; + return { key, label: labelFallback, ...UNKNOWN_ACHIEVEMENT_VISUAL }; +} + const ICON_PATHS: Record = { sparkles: "M9.813 15.904L9 18.75l-.813-2.846a4.5 4.5 0 00-3.09-3.09L2.25 12l2.846-.813a4.5 4.5 0 003.09-3.09L9 5.25l.813 2.846a4.5 4.5 0 003.09 3.09L15.75 12l-2.846.813a4.5 4.5 0 00-3.09 3.09zM18.259 8.715L18 9.75l-.259-1.035a3.375 3.375 0 00-2.455-2.456L14.25 6l1.036-.259a3.375 3.375 0 002.455-2.456L18 2.25l.259 1.035a3.375 3.375 0 002.456 2.456L21.75 6l-1.035.259a3.375 3.375 0 00-2.456 2.456zM16.894 20.567L16.5 21.75l-.394-1.183a2.25 2.25 0 00-1.423-1.423L13.5 18.75l1.183-.394a2.25 2.25 0 001.423-1.423l.394-1.183.394 1.183a2.25 2.25 0 001.423 1.423l1.183.394-1.183.394a2.25 2.25 0 00-1.423 1.423z", @@ -133,33 +169,37 @@ const ICON_PATHS: Record = { trophy: "M16.5 18.75h-9m9 0a3 3 0 013 3h-15a3 3 0 013-3m9 0v-3.375c0-.621-.503-1.125-1.125-1.125h-.871M7.5 18.75v-3.375c0-.621.504-1.125 1.125-1.125h.872m5.007 0H9.497m5.007 0a7.454 7.454 0 01-.982-3.172M9.497 14.25a7.454 7.454 0 00.981-3.172M5.25 4.236c-.982.143-1.954.317-2.916.52A6.003 6.003 0 007.73 9.728M5.25 4.236V4.5c0 2.108.966 3.99 2.48 5.228M5.25 4.236V2.721C7.456 2.41 9.71 2.25 12 2.25c2.291 0 4.545.16 6.75.47v1.516M7.73 9.728a6.726 6.726 0 002.748 1.35m8.272-6.842V4.5c0 2.108-.966 3.99-2.48 5.228m2.48-5.492a46.32 46.32 0 012.916.52 6.003 6.003 0 01-5.395 4.972m0 0a6.726 6.726 0 01-2.749 1.35m0 0a6.726 6.726 0 01-3.128 0m3.128 0a6.726 6.726 0 01-3.128 0", fire: "M15.362 5.214A8.252 8.252 0 0112 21 8.25 8.25 0 016.038 7.048 8.287 8.287 0 009 9.6a8.983 8.983 0 013.361-6.867 8.21 8.21 0 003 2.48zM12 18a3.75 3.75 0 00.495-7.467 5.99 5.99 0 00-1.925 3.546 5.974 5.974 0 01-2.133-1A3.75 3.75 0 0012 18z", + swatch: + "M4.098 19.902a3.75 3.75 0 005.304 0l6.401-6.402M6.75 21A3.75 3.75 0 013 17.25V4.125C3 3.504 3.504 3 4.125 3h5.25c.621 0 1.125.504 1.125 1.125v4.072M6.75 21a3.75 3.75 0 003.75-3.75V8.197M6.75 21h13.125c.621 0 1.125-.504 1.125-1.125v-5.25c0-.621-.504-1.125-1.125-1.125h-4.072M10.5 8.197l2.88-2.88c.438-.439 1.15-.439 1.59 0l3.712 3.713c.44.44.44 1.152 0 1.59l-2.879 2.88M6.75 17.25h.008v.008H6.75v-.008z", }; -export function badgeIconSvg(icon: string, size = 15): string { +function badgeIconSvg(icon: string, size = 15): string { const path = ICON_PATHS[icon] ?? ICON_PATHS.sparkles; return ``; } -export function tierBlobStyle(tier: (typeof BADGE_TIERS)[number]): string { +function badgeBlobStyle(visual: Pick): string { return [ - `--badge-base:${tier.base}`, - `--badge-blob-a:${tier.blobs[0]}`, - `--badge-blob-b:${tier.blobs[1]}`, - `--badge-blob-c:${tier.blobs[2]}`, + `--badge-base:${visual.base}`, + `--badge-blob-a:${visual.blobs[0]}`, + `--badge-blob-b:${visual.blobs[1]}`, + `--badge-blob-c:${visual.blobs[2]}`, ].join(";"); } export function founderBadgeChipHtml( - badge: FounderBadgeItem, + badge: BadgeItem, options?: { hero?: boolean; titlebar?: boolean }, ): string { - const tier = tierForBadgeKey(badge.key); - if (!tier) return ""; + const visual = badgeVisualForKey(badge.key, badge.label); + if (!visual) return ""; const hero = options?.hero ?? false; const titlebar = options?.titlebar ?? false; const mods = `${hero ? " bsplus-founder-badge--hero" : ""}${titlebar ? " bsplus-founder-badge--titlebar" : ""}`; - const icon = titlebar ? "" : badgeIconSvg(tier.icon, hero ? 20 : 15); + const icon = titlebar ? "" : badgeIconSvg(visual.icon, hero ? 20 : 15); - return ``; + return ``; } + +export { badgeBlobStyle }; diff --git a/src/types/storage.ts b/src/types/storage.ts index 673d5df4..05ece3e0 100644 --- a/src/types/storage.ts +++ b/src/types/storage.ts @@ -108,7 +108,7 @@ export interface SettingsState { // BetterSEQTA Cloud (accounts.betterseqta.org) — stored via CloudAuth, not settingsState /** When not `false`, automatic cloud settings sync is enabled (default-on). */ autoCloudSettingsSync?: boolean; - /** When not `false`, show the Cloud founder badge in the SEQTA titlebar (default-on). */ + /** When not `false`, show Cloud badges in the SEQTA titlebar (default-on). */ showTitlebarFounderBadge?: boolean; }