Add Expo mobile app for iOS and Android

Native tabs for feed, friend search, profile and settings, with feature
parity with the web app. Sessions are stored in SecureStore, realtime
disconnects in the background, and Spotify/Plex sign-in returns to the app
via the URL scheme.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01MzFywujuH9TiuXbr9vjoX8
This commit is contained in:
2026-10-03 09:59:02 -04:00
co-authored by Claude Opus 5.5
parent 5004beb10d
commit 0ee9ae3135
41 changed files with 1702 additions and 0 deletions
+29
View File
@@ -0,0 +1,29 @@
import { NativeTabs } from 'expo-router/unstable-native-tabs';
import { colors } from '@/lib/theme';
export default function TabsLayout() {
return (
<NativeTabs
backgroundColor={colors.bg}
indicatorColor={colors.surface2}
labelStyle={{ selected: { color: colors.text } }}
tintColor={colors.accent}>
<NativeTabs.Trigger name="index">
<NativeTabs.Trigger.Label>Feed</NativeTabs.Trigger.Label>
<NativeTabs.Trigger.Icon sf={{ default: 'music.note.list', selected: 'music.note.list' }} md="queue_music" />
</NativeTabs.Trigger>
<NativeTabs.Trigger name="search">
<NativeTabs.Trigger.Label>Friends</NativeTabs.Trigger.Label>
<NativeTabs.Trigger.Icon sf="person.2" md="group" />
</NativeTabs.Trigger>
<NativeTabs.Trigger name="profile">
<NativeTabs.Trigger.Label>Profile</NativeTabs.Trigger.Label>
<NativeTabs.Trigger.Icon sf={{ default: 'person.crop.circle', selected: 'person.crop.circle.fill' }} md="account_circle" />
</NativeTabs.Trigger>
<NativeTabs.Trigger name="settings">
<NativeTabs.Trigger.Label>Settings</NativeTabs.Trigger.Label>
<NativeTabs.Trigger.Icon sf={{ default: 'gearshape', selected: 'gearshape.fill' }} md="settings" />
</NativeTabs.Trigger>
</NativeTabs>
);
}
+92
View File
@@ -0,0 +1,92 @@
import { router } from 'expo-router';
import { useState } from 'react';
import { FlatList, RefreshControl, StyleSheet, View } from 'react-native';
import { SafeAreaView } from 'react-native-safe-area-context';
import useSWR from 'swr';
import { sortFeed, type FeedItemDTO } from '@musicshare/shared';
import { NowPlayingCard } from '@/components/NowPlayingCard';
import { Body, Button, Card, Title } from '@/components/ui';
import { api } from '@/lib/api';
import { showError } from '@/lib/errors';
import { useRealtime } from '@/lib/useRealtime';
import { useSession } from '@/lib/session';
import { colors, space } from '@/lib/theme';
export default function FeedScreen() {
const { me } = useSession();
const { data: feed, mutate, isLoading } = useSWR<FeedItemDTO[]>('/feed');
const [refreshing, setRefreshing] = useState(false);
useRealtime(true, (msg) => {
if (msg.type !== 'now_playing' || msg.data.user.id === me?.id) return;
mutate(
(current = []) => {
const existing = current.find((n) => n.user.id === msg.data.user.id);
return sortFeed([{ ...msg.data, pinnedAt: existing?.pinnedAt ?? null }, ...current.filter((n) => n !== existing)]);
},
{ revalidate: false },
);
});
const togglePin = async (item: FeedItemDTO) => {
const pinnedAt = item.pinnedAt ? null : new Date().toISOString();
const previous = feed;
mutate(sortFeed((feed ?? []).map((n) => (n.user.id === item.user.id ? { ...n, pinnedAt } : n))), { revalidate: false });
try {
await (pinnedAt ? api.pin(item.user.username) : api.unpin(item.user.username));
} catch (err) {
mutate(previous, { revalidate: false });
showError(err, "Couldn't pin");
}
};
const refresh = async () => {
setRefreshing(true);
await mutate().catch(() => {});
setRefreshing(false);
};
return (
<SafeAreaView style={styles.safe} edges={['top']}>
<FlatList
data={feed ?? []}
keyExtractor={(item) => item.user.id}
contentContainerStyle={styles.list}
refreshControl={<RefreshControl refreshing={refreshing} onRefresh={refresh} tintColor={colors.muted} />}
ListHeaderComponent={
<View style={styles.header}>
<Title>Friends listening</Title>
{!me?.preferredService && (
<Card>
<Body>Pick your streaming service so songs open in the right app.</Body>
<Button small title="Choose service" onPress={() => router.push('/settings')} style={{ alignSelf: 'flex-start' }} />
</Card>
)}
</View>
}
ListEmptyComponent={
isLoading ? null : (
<Card>
<Body muted>Nothing yet. Follow some friends and their music will show up here live.</Body>
<Button small variant="primary" title="Find friends" onPress={() => router.push('/search')} style={{ alignSelf: 'flex-start' }} />
</Card>
)
}
renderItem={({ item }) => (
<NowPlayingCard
np={item}
preferred={me?.preferredService}
pinned={Boolean(item.pinnedAt)}
onTogglePin={() => togglePin(item)}
/>
)}
/>
</SafeAreaView>
);
}
const styles = StyleSheet.create({
safe: { flex: 1, backgroundColor: colors.bg },
list: { padding: space.lg, gap: space.md, paddingBottom: space.xl * 3 },
header: { gap: space.md, marginBottom: space.xs },
});
+7
View File
@@ -0,0 +1,7 @@
import { ProfileView } from '@/components/ProfileView';
import { useSession } from '@/lib/session';
export default function MyProfileScreen() {
const { me } = useSession();
return me ? <ProfileView username={me.username} /> : null;
}
+59
View File
@@ -0,0 +1,59 @@
import { router } from 'expo-router';
import { useState } from 'react';
import { FlatList, Pressable, StyleSheet, Text, View } from 'react-native';
import { SafeAreaView } from 'react-native-safe-area-context';
import useSWR from 'swr';
import type { UserSummaryDTO } from '@musicshare/shared';
import { Avatar } from '@/components/Avatar';
import { Body, Field, Title } from '@/components/ui';
import { useDebounced } from '@/lib/useDebounced';
import { colors, space } from '@/lib/theme';
export default function SearchScreen() {
const [q, setQ] = useState('');
const query = useDebounced(q.trim(), 250);
const { data } = useSWR<UserSummaryDTO[]>(query.length >= 2 ? `/users/search?q=${encodeURIComponent(query)}` : null);
return (
<SafeAreaView style={styles.safe} edges={['top']}>
<FlatList
data={query.length >= 2 ? (data ?? []) : []}
keyExtractor={(u) => u.id}
keyboardShouldPersistTaps="handled"
contentContainerStyle={styles.list}
ListHeaderComponent={
<View style={{ gap: space.md }}>
<Title>Find friends</Title>
<Field
placeholder="Search by name or username"
value={q}
onChangeText={setQ}
autoCapitalize="none"
autoCorrect={false}
returnKeyType="search"
clearButtonMode="while-editing"
/>
</View>
}
ListEmptyComponent={query.length >= 2 && data ? <Body muted>No one found.</Body> : null}
renderItem={({ item }) => (
<Pressable style={styles.row} onPress={() => router.push(`/u/${item.username}`)} accessibilityRole="link">
<Avatar user={item} size={40} />
<View>
<Text style={styles.name}>{item.displayName ?? item.username}</Text>
<Text style={styles.handle}>@{item.username}</Text>
</View>
</Pressable>
)}
/>
</SafeAreaView>
);
}
const styles = StyleSheet.create({
safe: { flex: 1, backgroundColor: colors.bg },
list: { padding: space.lg, gap: space.sm },
row: { flexDirection: 'row', alignItems: 'center', gap: space.md, paddingVertical: space.sm },
name: { color: colors.text, fontWeight: '700', fontSize: 15 },
handle: { color: colors.muted, fontSize: 13 },
});
+400
View File
@@ -0,0 +1,400 @@
import * as Linking from 'expo-linking';
import * as WebBrowser from 'expo-web-browser';
import { Image } from 'expo-image';
import { useState } from 'react';
import { Alert, Pressable, StyleSheet, Text, View } from 'react-native';
import useSWR from 'swr';
import {
SERVICE_LABELS,
STREAMING_SERVICES,
timeAgo,
type ConnectionDTO,
type NowPlayingProvider,
type TrackSearchResultDTO,
} from '@musicshare/shared';
import { Screen } from '@/components/Screen';
import { Body, Button, Card, Chip, Field, Heading, Row, Title } from '@/components/ui';
import { api } from '@/lib/api';
import { showError } from '@/lib/errors';
import { useDebounced } from '@/lib/useDebounced';
import { useSession } from '@/lib/session';
import { colors, radius, space } from '@/lib/theme';
export default function SettingsScreen() {
return (
<Screen>
<Title>Settings</Title>
<ProfileSection />
<PreferredService />
<Connections />
<FeaturedPicker />
<Account />
</Screen>
);
}
function ProfileSection() {
const { me, setMe } = useSession();
const [displayName, setDisplayName] = useState(me?.displayName ?? '');
const [bio, setBio] = useState(me?.bio ?? '');
const [busy, setBusy] = useState(false);
const save = async () => {
setBusy(true);
try {
setMe(await api.updateMe({ displayName: displayName.trim() || null, bio: bio.trim() || null }));
} catch (err) {
showError(err);
}
setBusy(false);
};
return (
<Card>
<Heading>Profile</Heading>
<Field label="Display name" value={displayName} onChangeText={setDisplayName} maxLength={64} />
<Field label="Bio" value={bio} onChangeText={setBio} maxLength={280} multiline style={{ minHeight: 64 }} />
<Button title="Save" variant="primary" loading={busy} onPress={save} style={{ alignSelf: 'flex-start' }} />
</Card>
);
}
function PreferredService() {
const { me, setMe } = useSession();
const choose = async (service: (typeof STREAMING_SERVICES)[number]) => {
try {
setMe(await api.updateMe({ preferredService: service }));
} catch (err) {
showError(err);
}
};
return (
<Card>
<Heading>Open songs in</Heading>
<Row>
{STREAMING_SERVICES.map((s) => (
<Chip key={s} label={SERVICE_LABELS[s]} selected={me?.preferredService === s} onPress={() => choose(s)} />
))}
</Row>
</Card>
);
}
function Connections() {
const { data: connections = [], mutate } = useSWR<ConnectionDTO[]>('/connections');
const byProvider = new Map(connections.map((c) => [c.provider, c]));
const run = async (fn: () => Promise<unknown>) => {
try {
await fn();
} catch (err) {
showError(err);
}
await mutate();
};
const connectOAuth = (provider: 'spotify' | 'plex') =>
run(async () => {
// Deep link back into the app; in Expo Go this is an exp:// URL, in builds musicshare://
const returnTo = Linking.createURL('settings');
const { url } = await api.authorizeUrl(provider, { client: 'mobile', returnTo });
const result = await WebBrowser.openAuthSessionAsync(url, returnTo);
if (result.type === 'success') {
const error = Linking.parse(result.url).queryParams?.error;
if (typeof error === 'string') Alert.alert(`Couldn't connect ${SERVICE_LABELS[provider]}`, error);
}
});
const disconnect = (provider: NowPlayingProvider) =>
Alert.alert(`Disconnect ${SERVICE_LABELS[provider]}?`, 'Friends will stop seeing what you play there.', [
{ text: 'Cancel', style: 'cancel' },
{ text: 'Disconnect', style: 'destructive', onPress: () => run(() => api.disconnect(provider)) },
]);
const status = (p: NowPlayingProvider, fallback: string) => {
const c = byProvider.get(p);
if (!c) return <Body muted style={styles.small}>{fallback}</Body>;
if (c.status === 'error') return <Body style={[styles.small, { color: colors.danger }]}>Needs reconnecting: {c.lastError}</Body>;
return (
<Body muted style={styles.small}>
Connected as {c.displayName ?? c.externalUserId}
{c.lastPolledAt ? ` · checked ${timeAgo(c.lastPolledAt)}` : ''}
</Body>
);
};
const isActive = (p: NowPlayingProvider) => byProvider.get(p)?.status === 'active';
return (
<Card>
<Heading>Music services</Heading>
<Body muted style={styles.small}>
Connect where you listen. Friends see what you&apos;re playing in real time.
</Body>
{(['spotify', 'plex'] as const).map((p) => (
<View key={p} style={[styles.connectionColumn, styles.connection]}>
<View style={{ flex: 1 }}>
<Text style={styles.provider}>{SERVICE_LABELS[p]}</Text>
{status(p, p === 'plex' ? 'Music you play from your Plex servers' : 'Live from your Spotify account')}
</View>
{isActive(p) ? (
<Button small title="Disconnect" onPress={() => disconnect(p)} />
) : (
<Button small variant="primary" title={byProvider.has(p) ? 'Reconnect' : 'Connect'} onPress={() => connectOAuth(p)} />
)}
</View>
))}
{(['lastfm', 'listenbrainz'] as const).map((p) => (
<UsernameConnection
key={p}
provider={p}
status={status(p, p === 'lastfm' ? 'Anything that scrobbles: YouTube Music, Tidal, Deezer…' : 'Open-source scrobbling')}
active={byProvider.has(p)}
onConnect={(username) => run(() => api.connectUsername(p, username))}
onDisconnect={() => disconnect(p)}
/>
))}
<JellyfinConnection
status={status('jellyfin', 'Sign in to your Jellyfin server. Your password isn’t stored.')}
active={isActive('jellyfin')}
onConnect={(input) => run(() => api.connectJellyfin(input))}
onDisconnect={() => disconnect('jellyfin')}
/>
{connections.some((c) => c.webhookUrl) && (
<Body muted style={styles.small}>
Instant updates for Plex/Jellyfin can be set up from Settings on the web.
</Body>
)}
</Card>
);
}
function UsernameConnection({
provider,
status,
active,
onConnect,
onDisconnect,
}: {
provider: 'lastfm' | 'listenbrainz';
status: React.ReactNode;
active: boolean;
onConnect: (username: string) => Promise<void>;
onDisconnect: () => void;
}) {
const [username, setUsername] = useState('');
const [busy, setBusy] = useState(false);
return (
<View style={styles.connectionColumn}>
<View style={styles.connection}>
<View style={{ flex: 1 }}>
<Text style={styles.provider}>{SERVICE_LABELS[provider]}</Text>
{status}
</View>
{active && <Button small title="Disconnect" onPress={onDisconnect} />}
</View>
{!active && (
<Row style={{ flexWrap: 'nowrap' }}>
<View style={{ flex: 1 }}>
<Field placeholder="Username" value={username} onChangeText={setUsername} autoCapitalize="none" autoCorrect={false} />
</View>
<Button
small
variant="primary"
title="Connect"
loading={busy}
disabled={!username.trim()}
onPress={async () => {
setBusy(true);
await onConnect(username.trim());
setBusy(false);
}}
/>
</Row>
)}
</View>
);
}
function JellyfinConnection({
status,
active,
onConnect,
onDisconnect,
}: {
status: React.ReactNode;
active: boolean;
onConnect: (input: { serverUrl: string; username: string; password: string }) => Promise<void>;
onDisconnect: () => void;
}) {
const [serverUrl, setServerUrl] = useState('');
const [username, setUsername] = useState('');
const [password, setPassword] = useState('');
const [busy, setBusy] = useState(false);
return (
<View style={styles.connectionColumn}>
<View style={styles.connection}>
<View style={{ flex: 1 }}>
<Text style={styles.provider}>Jellyfin</Text>
{status}
</View>
{active && <Button small title="Disconnect" onPress={onDisconnect} />}
</View>
{!active && (
<View style={{ gap: space.sm }}>
<Field
placeholder="https://jellyfin.example.com"
value={serverUrl}
onChangeText={setServerUrl}
autoCapitalize="none"
autoCorrect={false}
keyboardType="url"
/>
<Field placeholder="Username" value={username} onChangeText={setUsername} autoCapitalize="none" autoCorrect={false} />
<Field placeholder="Password" value={password} onChangeText={setPassword} secureTextEntry />
<Button
small
variant="primary"
title="Connect"
loading={busy}
disabled={!serverUrl.trim() || !username.trim()}
style={{ alignSelf: 'flex-start' }}
onPress={async () => {
setBusy(true);
await onConnect({ serverUrl: serverUrl.trim(), username: username.trim(), password });
setPassword('');
setBusy(false);
}}
/>
</View>
)}
</View>
);
}
function FeaturedPicker() {
const [q, setQ] = useState('');
const [selected, setSelected] = useState<TrackSearchResultDTO | null>(null);
const [comment, setComment] = useState('');
const [saved, setSaved] = useState(false);
const [busy, setBusy] = useState(false);
const query = useDebounced(q.trim(), 300);
const { data: results } = useSWR<TrackSearchResultDTO[]>(
query.length >= 2 && !selected ? `/tracks/search?q=${encodeURIComponent(query)}` : null,
);
const save = async () => {
if (!selected) return;
setBusy(true);
try {
await api.setFeatured({ deezerId: selected.deezerId, comment: comment.trim() || null });
setSaved(true);
} catch (err) {
showError(err);
}
setBusy(false);
};
return (
<Card>
<Heading>Featured song</Heading>
<Body muted style={styles.small}>
Pin a song to your profile, with an optional note about why.
</Body>
{selected ? (
<>
<View style={styles.result}>
{selected.artworkUrl && <Image source={selected.artworkUrl} style={styles.thumb} />}
<View style={{ flex: 1 }}>
<Text style={styles.provider} numberOfLines={1}>
{selected.title}
</Text>
<Body muted style={styles.small}>
{selected.artist}
</Body>
</View>
<Button small title="Change" onPress={() => (setSelected(null), setSaved(false))} />
</View>
<Field
placeholder="Say something about it (optional)"
value={comment}
onChangeText={setComment}
maxLength={280}
multiline
style={{ minHeight: 64 }}
/>
<Button
variant="primary"
title={saved ? 'Featured ✓' : 'Feature this song'}
loading={busy}
onPress={save}
style={{ alignSelf: 'flex-start' }}
/>
</>
) : (
<>
<Field placeholder="Search for a song" value={q} onChangeText={setQ} autoCorrect={false} returnKeyType="search" />
{results?.map((r) => (
<Pressable key={r.deezerId} style={styles.result} onPress={() => setSelected(r)} accessibilityRole="button">
{r.artworkUrl && <Image source={r.artworkUrl} style={styles.thumb} />}
<Text style={styles.resultText} numberOfLines={1}>
{r.title} <Text style={{ color: colors.muted }}>· {r.artist}</Text>
</Text>
</Pressable>
))}
</>
)}
</Card>
);
}
function Account() {
const { me, signOut } = useSession();
const confirmDelete = () =>
Alert.alert('Delete your account?', 'This permanently removes your profile, follows and connected services.', [
{ text: 'Cancel', style: 'cancel' },
{
text: 'Delete',
style: 'destructive',
onPress: async () => {
try {
await api.deleteAccount();
await signOut();
} catch (err) {
showError(err);
}
},
},
]);
return (
<Card>
<Heading>Account</Heading>
<Body muted style={styles.small}>
Signed in as @{me?.username} · {me?.plan === 'free' ? 'Free plan' : 'Plus'}
</Body>
<Row>
<Button small title="Log out" onPress={signOut} />
<Button small variant="danger" title="Delete account" onPress={confirmDelete} />
</Row>
</Card>
);
}
const styles = StyleSheet.create({
small: { fontSize: 13 },
provider: { color: colors.text, fontWeight: '700', fontSize: 15 },
connection: { flexDirection: 'row', alignItems: 'center', gap: space.md },
connectionColumn: {
gap: space.sm,
borderTopWidth: StyleSheet.hairlineWidth,
borderTopColor: colors.border,
paddingTop: space.md,
},
result: { flexDirection: 'row', alignItems: 'center', gap: space.md, paddingVertical: space.xs },
resultText: { color: colors.text, flex: 1, fontSize: 14 },
thumb: { width: 40, height: 40, borderRadius: radius.sm },
});