Files
otunes/apps/mobile/app/server.tsx
T
joshuafhiggins 9da758b196 perf: optimize app rendering and data loading (#18)
- Virtualize mobile lists and defer queue loading
- Split playback state from actions to reduce rerenders
- Skip invalid or unnecessary Convex queries

Reviewed-on: #18
2026-09-05 16:35:37 -04:00

118 lines
3.2 KiB
TypeScript

import { useRouter } from "expo-router"
import { useEffect, 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 { config, isLoading, setServerHostname } = useServerConfig()
const [hostname, setHostname] = useState("")
const [error, setError] = useState<string | null>(null)
const [submitting, setSubmitting] = useState(false)
useEffect(() => {
if (config?.hostname) {
setHostname(config.hostname)
}
}, [config?.hostname])
async function handleContinue() {
setError(null)
setSubmitting(true)
try {
const ok = await setServerHostname(hostname)
if (!ok) {
setError(
"Enter a valid server address, e.g. music.example.com, localhost:3000"
)
return
}
router.replace("/signin")
} catch {
setError(
"Could not save the server address. Check device storage and try again."
)
} finally {
setSubmitting(false)
}
}
if (isLoading) {
return null
}
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 },
})