feat: support for theme submitter badge plus multiuple badge handling

This commit is contained in:
AdenMGB committed 2026-10-30 19:40:48 +10:30
1 parent d467339e91
commit 1bd88ec81c
7 files changed
+151 -66

No files matched your search

+6
View File
@@ -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;
@@ -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(
@@ -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 = `<div class="bsplus-founder-badge-stack">${chips}</div>`;
const chip = slot.querySelector<HTMLButtonElement>(".bsplus-founder-badge");
if (!chip) return;
chip.setAttribute("aria-label", `${badge.label}, click for details`);
chip.addEventListener("click", () => openFounderBadgeModal(badge, signupNumber));
slot.querySelectorAll<HTMLButtonElement>(".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<void> {
@@ -45,23 +57,24 @@ async function syncTitlebarFounderBadge(): Promise<void> {
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();
@@ -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 */ `
<div class="whatsnewHeader bsplus-founder-badge-header">
<h1>${esc(badge.label)}</h1>
<p>${esc(tier.rankLabel)}</p>
<p>${esc(visual.rankLabel)}</p>
</div>
`).firstChild as HTMLElement;
const signupLine =
signupNumber != null
signupNumber != null && badge.key.startsWith("founder_")
? `<p class="bsplus-founder-badge-signup">Cloud user #${signupNumber.toLocaleString()}</p>`
: "";
const hero = stringToHTML(/* html */ `
<div class="whatsnewImgContainer">
<div class="bsplus-founder-badge-hero whatsnewImg" data-tier="${badge.key}" style="${tierBlobStyle(tier)}">
<div class="bsplus-founder-badge-hero whatsnewImg" data-tier="${badge.key}" style="${badgeBlobStyle(visual)}">
<div class="bsplus-founder-badge-hero__blobs" aria-hidden="true"></div>
<div class="bsplus-founder-badge-hero__vignette" aria-hidden="true"></div>
<div class="bsplus-founder-badge-hero__stage">
@@ -51,7 +51,7 @@ export function openFounderBadgeModal(
const text = stringToHTML(/* html */ `
<div class="whatsnewTextContainer bsplus-founder-badge-body" style="overflow-y: auto;">
<p>${esc(tier.description)}</p>
<p>${esc(visual.description)}</p>
<p>
Linked to your BetterSEQTA Cloud account at
<a href="${ACCOUNTS_URL}" target="_blank" rel="noopener noreferrer">accounts.betterseqta.org</a>.
+23
View File
@@ -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"]);
});
});
+70 -30
View File
@@ -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<string, BadgeVisual>([
...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<string, string> = {
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<string, string> = {
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 `<svg class="bsplus-founder-badge__icon" xmlns="http://www.w3.org/2000/svg" viewBox="0 0 24 24" fill="currentColor" width="${size}" height="${size}" aria-hidden="true"><path d="${path}"/></svg>`;
}
export function tierBlobStyle(tier: (typeof BADGE_TIERS)[number]): string {
function badgeBlobStyle(visual: Pick<BadgeVisual, "base" | "blobs">): 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 `<button type="button" class="bsplus-founder-badge${mods}" data-tier="${badge.key}" style="${tierBlobStyle(tier)}"><span class="bsplus-founder-badge__glass"><span class="bsplus-founder-badge__blobs" aria-hidden="true"></span><span class="bsplus-founder-badge__content">${icon}<span class="bsplus-founder-badge__label">${badge.label}</span></span></span></button>`;
return `<button type="button" class="bsplus-founder-badge${mods}" data-tier="${badge.key}" style="${badgeBlobStyle(visual)}"><span class="bsplus-founder-badge__glass"><span class="bsplus-founder-badge__blobs" aria-hidden="true"></span><span class="bsplus-founder-badge__content">${icon}<span class="bsplus-founder-badge__label">${badge.label || visual.label}</span></span></span></button>`;
}
export { badgeBlobStyle };
+1 -1
View File
@@ -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;
}