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 10, 2022
1 parent 50b5a5a commit 87d4cf4
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 @@ -32,8 +32,8 @@ export default function RealmInputScreen(props: Props): Node {

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

const tryRealm = useCallback(async () => {
const parsedRealm = tryParseUrl(realmInputValue);
const tryRealm = useCallback(async (unparsedUrl: string) => {
const parsedRealm = tryParseUrl(unparsedUrl);
if (!parsedRealm) {
setError('Please enter a valid URL');
return;
Expand All @@ -57,7 +57,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 @@ -80,7 +84,7 @@ export default function RealmInputScreen(props: Props): Node {
navigation={navigation}
onChangeText={setRealmInputValue}
value={realmInputValue}
onSubmitEditing={tryRealm}
onSubmitEditing={handleInputSubmit}
enablesReturnKeyAutomatically
/>
{error !== null ? (
Expand All @@ -92,7 +96,7 @@ export default function RealmInputScreen(props: Props): Node {
style={styles.button}
text="Enter"
progress={progress}
onPress={tryRealm}
onPress={handleInputSubmit}
disabled={tryParseUrl(realmInputValue) === undefined}
/>
</Screen>
Expand Down

0 comments on commit 87d4cf4

Please sign in to comment.