- Replace mobile placeholder with Expo Router app (tabs, playback, auth, library) - Move Convex backend to @otunes/convex for web and mobile reuse - Update web app imports and API routes to use shared package
81 lines
2.7 KiB
TypeScript
81 lines
2.7 KiB
TypeScript
import { useRouter } from "expo-router"
|
|
import { useState } from "react"
|
|
import { KeyboardAvoidingView, Platform, StyleSheet, Text, View } from "react-native"
|
|
import { SafeAreaView } from "react-native-safe-area-context"
|
|
|
|
import { Button, Card, Input } from "@/components/ui/primitives"
|
|
import { useServerConfig } from "@/contexts/server-config"
|
|
import { spacing, useThemeColors } from "@/lib/theme"
|
|
|
|
export default function ServerScreen() {
|
|
const router = useRouter()
|
|
const colors = useThemeColors()
|
|
const { setServerHostname } = useServerConfig()
|
|
const [hostname, setHostname] = useState("")
|
|
const [error, setError] = useState<string | null>(null)
|
|
const [submitting, setSubmitting] = useState(false)
|
|
|
|
async function handleContinue() {
|
|
setError(null)
|
|
setSubmitting(true)
|
|
const ok = await setServerHostname(hostname)
|
|
setSubmitting(false)
|
|
if (!ok) {
|
|
setError("Enter a valid server address, e.g. music.example.com or localhost:3000")
|
|
return
|
|
}
|
|
router.replace("/signin")
|
|
}
|
|
|
|
return (
|
|
<SafeAreaView style={[styles.safe, { backgroundColor: colors.background }]}>
|
|
<KeyboardAvoidingView
|
|
behavior={Platform.OS === "ios" ? "padding" : undefined}
|
|
style={styles.container}
|
|
>
|
|
<View style={styles.hero}>
|
|
<Text style={[styles.brand, { color: colors.foreground }]}>oTunes</Text>
|
|
<Text style={[styles.subtitle, { color: colors.mutedForeground }]}>
|
|
Connect to your oTunes server to start listening.
|
|
</Text>
|
|
</View>
|
|
|
|
<Card>
|
|
<Text style={[styles.label, { color: colors.foreground }]}>Server address</Text>
|
|
<Input
|
|
value={hostname}
|
|
onChangeText={setHostname}
|
|
placeholder="music.example.com"
|
|
autoCapitalize="none"
|
|
autoCorrect={false}
|
|
keyboardType="url"
|
|
returnKeyType="go"
|
|
onSubmitEditing={() => void handleContinue()}
|
|
/>
|
|
<Text style={[styles.hint, { color: colors.mutedForeground }]}>
|
|
Convex will connect to convex.{"{your hostname}"}
|
|
</Text>
|
|
{error ? <Text style={[styles.error, { color: colors.destructive }]}>{error}</Text> : null}
|
|
<Button title="Continue" loading={submitting} onPress={() => void handleContinue()} />
|
|
</Card>
|
|
</KeyboardAvoidingView>
|
|
</SafeAreaView>
|
|
)
|
|
}
|
|
|
|
const styles = StyleSheet.create({
|
|
safe: { flex: 1 },
|
|
container: {
|
|
flex: 1,
|
|
justifyContent: "center",
|
|
padding: spacing.xl,
|
|
gap: spacing.xl,
|
|
},
|
|
hero: { gap: spacing.sm },
|
|
brand: { fontSize: 32, fontWeight: "800" },
|
|
subtitle: { fontSize: 16, lineHeight: 22 },
|
|
label: { fontSize: 14, fontWeight: "600" },
|
|
hint: { fontSize: 13 },
|
|
error: { fontSize: 14 },
|
|
})
|