2020-09-11 17:10:16 +00:00
|
|
|
import React, { useState } from 'react';
|
2021-09-13 20:41:05 +00:00
|
|
|
import { FlatList, StyleSheet, View } from 'react-native';
|
2020-09-11 17:10:16 +00:00
|
|
|
import PropTypes from 'prop-types';
|
|
|
|
|
|
|
|
import TextInput from '../../../containers/TextInput';
|
2020-10-30 13:59:44 +00:00
|
|
|
import * as List from '../../../containers/List';
|
2020-09-11 17:10:16 +00:00
|
|
|
import { themes } from '../../../constants/colors';
|
2021-01-20 17:56:10 +00:00
|
|
|
import I18n from '../../../i18n';
|
2021-09-13 20:41:05 +00:00
|
|
|
import Item from './Item';
|
2020-09-11 17:10:16 +00:00
|
|
|
|
|
|
|
const styles = StyleSheet.create({
|
|
|
|
container: {
|
2021-09-23 14:17:53 +00:00
|
|
|
zIndex: 1
|
2020-09-11 17:10:16 +00:00
|
|
|
},
|
|
|
|
inputContainer: {
|
|
|
|
marginTop: 0,
|
|
|
|
marginBottom: 0
|
|
|
|
},
|
|
|
|
serverHistory: {
|
|
|
|
maxHeight: 180,
|
|
|
|
width: '100%',
|
|
|
|
top: '100%',
|
|
|
|
zIndex: 1,
|
|
|
|
position: 'absolute',
|
|
|
|
borderWidth: StyleSheet.hairlineWidth,
|
|
|
|
borderRadius: 2,
|
|
|
|
borderTopWidth: 0
|
|
|
|
}
|
|
|
|
});
|
|
|
|
|
2021-09-13 20:41:05 +00:00
|
|
|
const ServerInput = ({ text, theme, serversHistory, onChangeText, onSubmit, onDelete, onPressServerHistory }) => {
|
2020-09-11 17:10:16 +00:00
|
|
|
const [focused, setFocused] = useState(false);
|
|
|
|
return (
|
|
|
|
<View style={styles.container}>
|
|
|
|
<TextInput
|
2021-01-20 17:56:10 +00:00
|
|
|
label={I18n.t('Enter_workspace_URL')}
|
|
|
|
placeholder={I18n.t('Workspace_URL_Example')}
|
2020-09-11 17:10:16 +00:00
|
|
|
containerStyle={styles.inputContainer}
|
|
|
|
value={text}
|
|
|
|
returnKeyType='send'
|
|
|
|
onChangeText={onChangeText}
|
|
|
|
testID='new-server-view-input'
|
|
|
|
onSubmitEditing={onSubmit}
|
|
|
|
clearButtonMode='while-editing'
|
|
|
|
keyboardType='url'
|
|
|
|
textContentType='URL'
|
|
|
|
theme={theme}
|
|
|
|
onFocus={() => setFocused(true)}
|
|
|
|
onBlur={() => setFocused(false)}
|
|
|
|
/>
|
2021-09-13 20:41:05 +00:00
|
|
|
{focused && serversHistory?.length ? (
|
|
|
|
<View
|
|
|
|
style={[
|
|
|
|
styles.serverHistory,
|
|
|
|
{ backgroundColor: themes[theme].backgroundColor, borderColor: themes[theme].separatorColor }
|
|
|
|
]}>
|
|
|
|
<FlatList
|
|
|
|
data={serversHistory}
|
|
|
|
renderItem={({ item }) => (
|
|
|
|
<Item item={item} theme={theme} onPress={() => onPressServerHistory(item)} onDelete={onDelete} />
|
|
|
|
)}
|
|
|
|
ItemSeparatorComponent={List.Separator}
|
|
|
|
keyExtractor={item => item.id}
|
|
|
|
/>
|
|
|
|
</View>
|
|
|
|
) : null}
|
2020-09-11 17:10:16 +00:00
|
|
|
</View>
|
|
|
|
);
|
|
|
|
};
|
|
|
|
|
|
|
|
ServerInput.propTypes = {
|
|
|
|
text: PropTypes.string,
|
|
|
|
theme: PropTypes.string,
|
|
|
|
serversHistory: PropTypes.array,
|
|
|
|
onChangeText: PropTypes.func,
|
|
|
|
onSubmit: PropTypes.func,
|
|
|
|
onDelete: PropTypes.func,
|
|
|
|
onPressServerHistory: PropTypes.func
|
|
|
|
};
|
|
|
|
|
|
|
|
export default ServerInput;
|