import m, {MithrilComponent} from '@garage44/mithril' import {Button} from '@garage44/mithril/components' import type {Provider, ProviderKind} from '@/types' import {$s} from '@/app' import {asksServer, startUrl} from '@/lib/signin' /* * The providers' own marks, as the mockups draw them * (`docs/mockups/external-sign-in/`). Their colours are the providers', not the * UI's, which is why they are the one place in this app that names a colour: * a Google "G" in the theme's accent would not be Google's. */ const MARKS: Record m.Children}> = { codeberg: { body: () => [ , , ], box: '0 0 24 24', }, discord: { body: () => [ , , , , ], box: '0 0 24 24', }, github: { body: () => ( ), box: '0 0 16 16', }, google: { body: () => [ , , , , ], box: '0 0 48 48', }, mastodon: { body: () => [ , , ], box: '0 0 24 24', }, reddit: { body: () => [ , , , , , , , , , ], box: '0 0 24 24', }, // A community's own OpenID server: a key, in the text colour. key: { body: () => [ , , ], box: '0 0 24 24', }, } /** * A provider's mark: by id for the six presets, by kind for the rest (a * second GitHub-like server still looks like what it talks to), and a key for * a custom OpenID server. */ export function ProviderLogo(p: {id: string; kind?: ProviderKind}, size = 18) { const mark = MARKS[p.id] ?? (p.kind && p.kind !== 'oidc' ? MARKS[p.kind] : undefined) ?? MARKS.key return ( ) } /** * Leave for a provider: the fediverse asks which server first, everything else * goes straight to the server's start address, which redirects onwards. */ export function signInWith(p: Provider, ret: string, app?: string) { if (asksServer(p)) { m.route.set('/signin/fediverse', {return: ret, ...(app ? {app} : {})}) return } location.assign(startUrl(p.id, ret, {app})) } interface ChoicesAttrs { /** Disables the buttons while the card's own form is busy. */ disabled?: boolean /** Words for the line under the grid; the default is the sign-in card's. */ or?: string /** Where to come back to; the current page by default. */ return?: string } /** * The provider buttons above a sign-in form, two to a row, in the operator's * order, with the line that leads into the name and password under them. Draws * nothing on a server with none switched on, so the card is exactly what it was. */ export class ProviderChoices extends MithrilComponent { view(vnode: m.Vnode) { const providers = $s.registration?.providers ?? [] if (!providers.length) return null const ret = vnode.attrs.return ?? location.pathname + location.search return (
{providers.map((p) => ( ))}
{vnode.attrs.or ?? 'or with your Cartopolis name'}
) } }