Skip to content

Commit

Permalink
SmartUrlInput [nfc]: Remove props that should just be constants
Browse files Browse the repository at this point in the history
These don't need to be configurable. In the next commit, we'll even
stop using two of these values:

- defaultOrganization: 'your-org'
- defaultDomain: 'zulipchat.com'
  • Loading branch information
chrisbobbe committed Mar 10, 2022
1 parent 5c742fe commit 77d578f
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 36 deletions.
39 changes: 6 additions & 33 deletions src/common/SmartUrlInput.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,6 @@ import type { ViewStyleProp } from 'react-native/Libraries/StyleSheet/StyleSheet
import type { AppNavigationProp } from '../nav/AppNavigator';
import { ThemeContext, createStyleSheet } from '../styles';
import { autocompleteRealmPieces, autocompleteRealm, fixRealmUrl } from '../utils/url';
import type { Protocol } from '../utils/url';
import ZulipText from './ZulipText';

const styles = createStyleSheet({
Expand All @@ -29,22 +28,6 @@ const styles = createStyleSheet({
});

type Props = $ReadOnly<{|
/**
* The protocol which will be used if the user doesn't specify one.
* Should almost certainly be "https://".
*/
defaultProtocol: Protocol,
/**
* The example organization name that will be displayed while the
* entry field is empty. Appears, briefly, as the initial (lowest-
* level) component of the realm's domain.
*/
defaultOrganization: string,
/**
* The default domain to which the user's input will be appended, if
* it appears not to contain an explicit domain.
*/
defaultDomain: string,
// TODO: Currently this type is acceptable because the only
// `navigation` prop we pass to a `SmartUrlInput` instance is the
// one from a component on AppNavigator.
Expand Down Expand Up @@ -99,15 +82,7 @@ function useRn19366Workaround(textInputRef) {
}

export default function SmartUrlInput(props: Props): Node {
const {
defaultProtocol,
defaultOrganization,
defaultDomain,
style,
onChangeText,
onSubmitEditing,
enablesReturnKeyAutomatically,
} = props;
const { style, onChangeText, onSubmitEditing, enablesReturnKeyAutomatically } = props;

// We should replace the fixme with
// `React$ElementRef<typeof TextInput>` when we can. Currently, that
Expand Down Expand Up @@ -140,12 +115,10 @@ export default function SmartUrlInput(props: Props): Node {
setValue(_value);

onChangeText(
fixRealmUrl(
autocompleteRealm(_value, { protocol: defaultProtocol, domain: defaultDomain }),
),
fixRealmUrl(autocompleteRealm(_value, { protocol: 'https://', domain: 'zulipchat.com' })),
);
},
[defaultDomain, defaultProtocol, onChangeText],
[onChangeText],
);

// When the "placeholder parts" are pressed, i.e., the parts of the URL
Expand Down Expand Up @@ -178,8 +151,8 @@ export default function SmartUrlInput(props: Props): Node {
);

const [prefix, , suffix] = autocompleteRealmPieces(value, {
domain: defaultDomain,
protocol: defaultProtocol,
domain: 'zulipchat.com',
protocol: 'https://',
});

return (
Expand All @@ -203,7 +176,7 @@ export default function SmartUrlInput(props: Props): Node {
enablesReturnKeyAutomatically={enablesReturnKeyAutomatically}
ref={textInputRef}
/>
{!value && renderPlaceholderPart(defaultOrganization)}
{!value && renderPlaceholderPart('your-org')}
{suffix !== null && renderPlaceholderPart(suffix)}
</View>
);
Expand Down
3 changes: 0 additions & 3 deletions src/start/RealmInputScreen.js
Original file line number Diff line number Diff line change
Expand Up @@ -90,9 +90,6 @@ export default class RealmInputScreen extends PureComponent<Props, State> {
<SmartUrlInput
style={styles.input}
navigation={navigation}
defaultProtocol="https://"
defaultOrganization="your-org"
defaultDomain="zulipchat.com"
onChangeText={this.handleRealmChange}
onSubmitEditing={this.tryRealm}
enablesReturnKeyAutomatically
Expand Down

0 comments on commit 77d578f

Please sign in to comment.