Files
musicshare/apps/mobile/src/components/setup/ServiceSignInSetup.tsx
T
chrisandClaude Opus 5.5 804493aee0 Create-account links for Last.fm and ListenBrainz, and Link Spotify for ListenBrainz
ListenBrainz accounts are MusicBrainz accounts, so its sign-up link goes to MusicBrainz.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
2026-10-15 12:02:40 -04:00

72 lines
2.4 KiB
TypeScript
Raw Blame History

This file contains ambiguous Unicode characters
This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
import { useState } from 'react';
import { mutate } from 'swr';
import { SERVICE_LABELS } from '@musicshare/shared';
import { SignInError, openSignupPage, signInWithService } from '@/lib/connect';
import { Button } from '../ui';
import { ErrorText, SetupActions, SetupHeader, type SetupProps } from './common';
type Provider = 'plex' | 'lastfm';
/**
* Sign in to Plex, or to Last.fm for apps that can send plays there.
* (Spotify has its own SpotifySetup: via Last.fm or ListenBrainz.)
*/
export function ServiceSignInSetup({
service,
appName,
onDone,
skipLabel,
}: SetupProps & { service: Provider; appName?: string }) {
const [done, setDone] = useState(false);
const [busy, setBusy] = useState(false);
const [error, setError] = useState<string | null>(null);
const run = async () => {
setBusy(true);
setError(null);
try {
if ((await signInWithService(service)) === 'connected') {
await mutate('/connections');
setDone(true);
}
} catch (err) {
setError(err instanceof SignInError ? err.message : `Couldn't connect ${SERVICE_LABELS[service]}. Try again.`);
}
setBusy(false);
};
if (done) {
return (
<>
<SetupHeader
title="You're all set"
subtitle={`Play something on ${appName ?? SERVICE_LABELS[service]} and your friends will see it.`}
/>
<SetupActions primary="Continue" onPrimary={onDone} />
</>
);
}
if (service === 'lastfm') {
return (
<>
<SetupHeader
title="Connect Last.fm"
subtitle={`${appName ?? 'Your app'} doesn’t let other iPhone apps see what’s playing. If it can send plays to Last.fm (TIDAL can, in its settings), sign in to Last.fm and we’ll share them.`}
/>
<ErrorText>{error}</ErrorText>
<SetupActions primary="Sign in with Last.fm" loading={busy} onPrimary={run} onSkip={onDone} skipLabel={skipLabel} />
<Button small title="New to Last.fm? Create an account" onPress={() => openSignupPage('lastfm')} />
</>
);
}
return (
<>
<SetupHeader title="Share what you’re playing" subtitle={`Sign in to ${SERVICE_LABELS[service]} and your friends see what you play.`} />
<ErrorText>{error}</ErrorText>
<SetupActions primary={`Connect ${SERVICE_LABELS[service]}`} loading={busy} onPrimary={run} onSkip={onDone} skipLabel={skipLabel} />
</>
);
}