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 Apr 5, 2022
1 parent b8dda35 commit d63ea54
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 @@ -67,7 +67,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 @@ -90,7 +94,7 @@ export default function RealmInputScreen(props: Props): Node {
navigation={navigation}
onChangeText={setRealmInputValue}
value={realmInputValue}
onSubmitEditing={tryRealm}
onSubmitEditing={handleInputSubmit}
enablesReturnKeyAutomatically
/>
{error !== null ? (
Expand All @@ -102,7 +106,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 d63ea54

Please sign in to comment.