From 28d8c6dabd05c0261a8039ffba12939b38c38818 Mon Sep 17 00:00:00 2001 From: austinried <4966622+austinried@users.noreply.github.com> Date: Mon, 23 Aug 2021 11:23:14 +0900 Subject: [PATCH] small address input format helper --- app/screens/ServerView.tsx | 15 +++++++++++++++ 1 file changed, 15 insertions(+) diff --git a/app/screens/ServerView.tsx b/app/screens/ServerView.tsx index 5fcd9de..3cf2ac5 100644 --- a/app/screens/ServerView.tsx +++ b/app/screens/ServerView.tsx @@ -126,6 +126,20 @@ const ServerView: React.FC<{ return !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 ( @@ -138,6 +152,7 @@ const ServerView: React.FC<{ placeholder="http://demo.navidrome.org" value={address} onChangeText={setAddress} + onBlur={formatAddress} /> Username