Skip to content

Commit 95e6b65

Browse files
committed
RealmInputScreen: Offer nicer experience for copied URL
Related: #5228
1 parent 9548970 commit 95e6b65

File tree

2 files changed

+34
-0
lines changed

2 files changed

+34
-0
lines changed

src/start/RealmInputScreen.js

Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22
import React, { useState, useCallback } from 'react';
33
import type { Node } from 'react';
44
import { Keyboard } from 'react-native';
5+
import Clipboard from '@react-native-clipboard/clipboard';
56

67
import type { RouteProp } from '../react-navigation';
78
import type { AppNavigationProp } from '../nav/AppNavigator';
@@ -15,6 +16,7 @@ import ZulipButton from '../common/ZulipButton';
1516
import { tryParseUrl } from '../utils/url';
1617
import * as api from '../api';
1718
import { navigateToAuth } from '../actions';
19+
import { useClipboardHasURL } from '../@react-native-clipboard/clipboard';
1820

1921
type Props = $ReadOnly<{|
2022
navigation: AppNavigationProp<'realm-input'>,
@@ -77,6 +79,24 @@ export default function RealmInputScreen(props: Props): Node {
7779
button: { marginTop: 8 },
7880
};
7981

82+
const tryCopiedUrl = useCallback(async () => {
83+
// The copied string might not be a valid realm URL:
84+
// - It might not be a URL because useClipboardHasURL is subject to
85+
// races (and Clipboard.getString is itself async).
86+
// - It might not be a valid Zulip realm that the client can connect to.
87+
//
88+
// So…
89+
const url = await Clipboard.getString();
90+
91+
// …let the user see what string is being tried and edit it if it fails…
92+
setRealmInputValue(url);
93+
94+
// …and run it through our usual validation.
95+
await tryRealm(url);
96+
}, [tryRealm]);
97+
98+
const clipboardHasURL = useClipboardHasURL();
99+
80100
return (
81101
<Screen
82102
title="Welcome"
@@ -107,6 +127,19 @@ export default function RealmInputScreen(props: Props): Node {
107127
onPress={handleInputSubmit}
108128
disabled={urlFromInputValue(realmInputValue) === undefined}
109129
/>
130+
{clipboardHasURL === true && (
131+
// Recognize when the user has copied a URL, and let them use it
132+
// without making them enter it into the input.
133+
//
134+
// TODO(?): Instead, use a FAB that persists while
135+
// clipboardHasURL !== true && !progress
136+
<ZulipButton
137+
style={styles.button}
138+
text="Use copied URL"
139+
progress={progress}
140+
onPress={tryCopiedUrl}
141+
/>
142+
)}
110143
</Screen>
111144
);
112145
}

static/translations/messages_en.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -48,6 +48,7 @@
4848
"Welcome": "Welcome",
4949
"Enter your Zulip server URL:": "Enter your Zulip server URL:",
5050
"e.g. zulip.example.com": "e.g. zulip.example.com",
51+
"Use copied URL": "Use copied URL",
5152
"Subscriptions": "Subscriptions",
5253
"Search": "Search",
5354
"Log in": "Log in",

0 commit comments

Comments
 (0)