small address input format helper

This commit is contained in:
austinried 2021-08-23 11:23:14 +09:00
parent 5879694c8c
commit 28d8c6dabd

View File

@ -126,6 +126,20 @@ const ServerView: React.FC<{
return !validate() || testing || removing || saving return !validate() || testing || removing || saving
}, [validate, testing, removing, saving]) }, [validate, testing, removing, saving])
const formatAddress = useCallback(() => {
let addressFormatted = address.trim()
if (addressFormatted.endsWith('/')) {
addressFormatted = addressFormatted.substr(0, addressFormatted.length - 1)
}
if (addressFormatted.length > 0 && !addressFormatted.includes(':/')) {
addressFormatted = `http://${addressFormatted}`
}
setAddress(addressFormatted)
}, [address])
return ( return (
<GradientScrollView style={styles.scroll} contentContainerStyle={styles.scrollContentContainer}> <GradientScrollView style={styles.scroll} contentContainerStyle={styles.scrollContentContainer}>
<View style={styles.content}> <View style={styles.content}>
@ -138,6 +152,7 @@ const ServerView: React.FC<{
placeholder="http://demo.navidrome.org" placeholder="http://demo.navidrome.org"
value={address} value={address}
onChangeText={setAddress} onChangeText={setAddress}
onBlur={formatAddress}
/> />
<Text style={styles.inputTitle}>Username</Text> <Text style={styles.inputTitle}>Username</Text>
<TextInput <TextInput