Files
eric b77a8cadb2
Some checks failed
Upstream Sync / Sync latest commits from upstream repo (push) Has been cancelled
'init'
2026-03-24 14:46:41 -05:00

99 lines
3.2 KiB
TypeScript
Raw Permalink 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 { useCallback, useEffect, useState } from 'react'
import { View, Text, ScrollView, StyleSheet, RefreshControl } from 'react-native'
import { SafeAreaView } from 'react-native-safe-area-context'
import { useBind } from '@/context/BindContext'
import { apiFetch } from '@/lib/api'
import { theme } from '@/constants/theme'
export default function NetworkScreen() {
const { bind } = useBind()
const [raw, setRaw] = useState<string>('')
const [err, setErr] = useState('')
const [refreshing, setRefreshing] = useState(false)
const load = useCallback(async () => {
if (!bind) {
setErr('未绑定')
setRaw('')
return
}
setErr('')
try {
const r = await apiFetch(bind, '/network_status')
if (!r.ok) throw new Error(String(r.status))
const j = await r.json()
setRaw(JSON.stringify(j, null, 2))
} catch (e) {
setErr(e instanceof Error ? e.message : String(e))
setRaw('')
}
}, [bind])
useEffect(() => {
void load()
}, [load])
const onRefresh = useCallback(async () => {
setRefreshing(true)
await load()
setRefreshing(false)
}, [load])
return (
<SafeAreaView style={styles.safe} edges={['bottom']}>
<ScrollView
contentContainerStyle={styles.scroll}
refreshControl={<RefreshControl refreshing={refreshing} onRefresh={() => void onRefresh()} />}
>
<Text style={styles.h1}></Text>
<Text style={styles.lead}>Google / EasyTier </Text>
{bind && (
<View style={styles.et}>
<Text style={styles.etTitle}>EasyTier</Text>
<Text style={styles.mono}> {bind.easytier.networkName}</Text>
<Text style={styles.mutedSmall}>
peer PC 访 {bind.baseUrl}
</Text>
</View>
)}
{err ? <Text style={styles.err}>{err}</Text> : null}
{raw ? <Text style={styles.pre}>{raw}</Text> : !err && bind ? <Text style={styles.muted}></Text> : null}
</ScrollView>
</SafeAreaView>
)
}
const styles = StyleSheet.create({
safe: { flex: 1, backgroundColor: theme.bg },
scroll: { padding: 20, paddingBottom: 40 },
h1: { fontSize: 22, fontWeight: '700', color: theme.text, marginBottom: 8 },
lead: { fontSize: 14, color: theme.muted, marginBottom: 16, lineHeight: 22 },
et: {
padding: 14,
borderRadius: 12,
backgroundColor: 'rgba(124,92,255,0.08)',
borderWidth: 1,
borderColor: 'rgba(124,92,255,0.25)',
marginBottom: 16,
},
etTitle: { fontSize: 14, fontWeight: '600', color: theme.text, marginBottom: 8 },
mono: { fontFamily: 'monospace', fontSize: 12, color: theme.accent },
mutedSmall: { fontSize: 12, color: theme.muted, marginTop: 8, lineHeight: 18 },
pre: {
fontFamily: 'monospace',
fontSize: 11,
color: '#c8cdd5',
lineHeight: 18,
backgroundColor: theme.bgCard,
padding: 12,
borderRadius: 10,
borderWidth: 1,
borderColor: theme.border,
},
err: { color: theme.danger, marginBottom: 12 },
muted: { color: theme.muted },
})