Skip to content

Badges · Modules

4 modules · 9 exports · 1 repository · 8 e2e tests · 3 routes

Who imports who · hover a node
Depends onBadges modulesUsed byBadgeListing1 exportBadgeOrigin3 exportsBadgeOwners4 exportsBadges.server1 exportRoutes3 filesRepositories1 fileComponents1 fileActions2 filesLoaders2 files

BadgeListing

app/features/badges/core/BadgeListing.ts

The badge list of /badges: narrowed down by the name searched for and split into the badges the viewer manages and every other badge.

Imports
no other modules
Used by
1 route

Functions & values

function

split

:15

The badges whose name contains search (ignoring case, an empty search matching all), split into the ones viewerId manages and the rest. Without a viewer every badge is in other.

export function split<T extends ListedBadge>(
	badges: T[],
	{ viewerId, search }: { viewerId: number | undefined; search: string },
)
Unit tests (3)
Routes/badges

BadgeOrigin

app/features/badges/core/BadgeOrigin.ts

Where a badge comes from: what it is awarded for (a tournament win, reaching an X Power or supporting on Patreon, told apart by its code) and who drew it.

Imports
no other modules
Used by
1 route1 repository1 component

Functions & values

function

awardedFor

:22

What the badge is awarded for, read from its code: patreon and patreon_plus are the supporter badges, codes starting with xp (Splatoon 2) or one of {@link SPLATOON_3_XP_BADGE_VALUES} (Splatoon 3) are X Power badges and every other badge is a tournament prize.

export function awardedFor(badge: Pick<Tables["Badge"], "code">): AwardedFor
Unit tests (1)
function

xpBadgeValue

:39

The Splatoon 3 X Power badge a peak X Power earns: the highest of {@link SPLATOON_3_XP_BADGE_VALUES} it reaches, null below the lowest one. A player holds only this one XP badge, not the ones under it.

export function xpBadgeValue(peakXp: number)
Unit tests (1)
function

legacyMakerName

:53

Who drew a legacy badge, one made before badges had an author (Badge.authorId being null): Dreamy drew the top Splatoon 3 XP badges, borzoic the rest.

export function legacyMakerName(badge: Pick<Tables["Badge"], "displayName">)
Unit tests (1)

BadgeOwners

app/features/badges/core/BadgeOwners.ts

Who owns a badge and how many times. A user can own several copies of a badge, one per win: in the edit dialog the owners are a count per user, sent to the server as a list with one user id per copy. Copies come either from a finalized tournament (tied to it, shown in its winners' feed) or from a manager granting them by hand.

Imports
no other modules
Used by
1 action2 routes1 repository

Functions & values

function

toOwnerIds

:19

The owners as a list of user ids, a user listed once per copy they own.

export function toOwnerIds(owners: CountedOwner[])
Unit tests (2)
function

total

:24

How many copies of the badge have been awarded in total.

export function total(owners: CountedOwner[])
Unit tests (1)
function

changes

:32

How the edited owners differ from the current ones, per user whose count changed: how many copies they are added or removed. A user new to the list is added all of their copies.

export function changes<T extends CountedOwner & { username: string }>(
	edited: T[],
	current: CountedOwner[],
)
Unit tests (3)
function

reconcile

:59

Splits new owners (one user id per copy) into the tournament wins kept and the copies granted by hand. A user's wins count first towards their new total, the rest of it being a manual grant. Lowering a total below the user's wins removes the most recent ones (highest tournament id).

export function reconcile({
	ownerIds,
	tournamentWins,
}: {
	ownerIds: number[];
	tournamentWins: TournamentWin[];
})
Unit tests (4)

Badges

serverapp/features/badges/core/Badges.server.ts

Badges in the forms of other features: which badges an event or a tournament organization can be given as its prizes.

Imports
no other modules
Used by
2 loaders1 action

Functions & values

function

attachable

:12

Badges an editor can attach: the ones any of managerIds manage plus those already attached, so an attached badge they no longer manage still renders and stays removable.

export async function attachable<T extends { id: number }>({
	managerIds,
	attached,
}: {
	managerIds: number[];
	attached: T[];
})
Unit tests (2)