Skip to content

Commit

Permalink
RealmInputScreen [nfc]: Have tryRealm take an arg for what realm to…
Browse files Browse the repository at this point in the history
… try
  • Loading branch information
chrisbobbe committed Mar 29, 2022
1 parent 4452fad commit 9548970
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 6 deletions.
2 changes: 1 addition & 1 deletion src/common/SmartUrlInput.js
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ type Props = $ReadOnly<{|
style?: ViewStyleProp,
onChangeText: (value: string) => void,
value: string,
onSubmitEditing: () => Promise<void>,
onSubmitEditing: () => void,
enablesReturnKeyAutomatically: boolean,
|}>;

Expand Down
14 changes: 9 additions & 5 deletions src/start/RealmInputScreen.js
Original file line number Diff line number Diff line change
Expand Up @@ -40,8 +40,8 @@ export default function RealmInputScreen(props: Props): Node {

const [error, setError] = useState<string | null>(null);

const tryRealm = useCallback(async () => {
const parsedRealm = urlFromInputValue(realmInputValue);
const tryRealm = useCallback(async unparsedUrl => {
const parsedRealm = urlFromInputValue(unparsedUrl);
if (!parsedRealm) {
setError('Please enter a valid URL');
return;
Expand All @@ -65,7 +65,11 @@ export default function RealmInputScreen(props: Props): Node {
} finally {
setProgress(false);
}
}, [realmInputValue]);
}, []);

const handleInputSubmit = useCallback(() => {
tryRealm(realmInputValue);
}, [tryRealm, realmInputValue]);

const styles = {
input: { marginTop: 16, marginBottom: 8 },
Expand All @@ -88,7 +92,7 @@ export default function RealmInputScreen(props: Props): Node {
navigation={navigation}
onChangeText={setRealmInputValue}
value={realmInputValue}
onSubmitEditing={tryRealm}
onSubmitEditing={handleInputSubmit}
enablesReturnKeyAutomatically
/>
{error !== null ? (
Expand All @@ -100,7 +104,7 @@ export default function RealmInputScreen(props: Props): Node {
style={styles.button}
text="Enter"
progress={progress}
onPress={tryRealm}
onPress={handleInputSubmit}
disabled={urlFromInputValue(realmInputValue) === undefined}
/>
</Screen>
Expand Down

0 comments on commit 9548970

Please sign in to comment.