Files
notesnook/apps/mobile/src/components/AddTopicDialog/index.js

187 lines
5.2 KiB
JavaScript
Raw Normal View History

2020-01-18 18:14:17 +05:00
import React from 'react';
2020-01-18 01:04:33 +05:00
import {Modal, Text, TouchableOpacity, View} from 'react-native';
import {TextInput} from 'react-native-gesture-handler';
2019-12-09 13:17:40 +05:00
import Icon from 'react-native-vector-icons/Feather';
2020-01-18 01:04:33 +05:00
import {opacity, ph, pv, SIZE, WEIGHT} from '../../common/common';
2020-01-19 21:31:26 +05:00
2020-01-18 01:04:33 +05:00
import {getElevation, ToastEvent} from '../../utils/utils';
2019-12-09 13:17:40 +05:00
2020-01-18 18:14:17 +05:00
export class AddTopicDialog extends React.Component {
constructor(props) {
super(props);
this.state = {
visible: false,
titleFocused: false,
};
this.title;
}
2020-01-08 22:47:49 +05:00
2020-01-18 18:14:17 +05:00
addNewTopic = async () => {
if (!this.title)
2019-12-09 13:17:40 +05:00
return ToastEvent.show('Title is required', 'error', 3000, () => {}, '');
2020-01-18 18:14:17 +05:00
//db.addTopicToNotebook(toEdit.dateCreated, title);
2019-12-09 13:17:40 +05:00
ToastEvent.show('New topic added', 'success', 3000, () => {}, '');
close(true);
};
2020-01-18 18:14:17 +05:00
open() {
this.setState({
visible: true,
});
}
close() {
this.title = null;
this.setState({
visible: false,
});
}
render() {
2020-01-19 21:31:26 +05:00
const {visible, titleFocused} = this.state;
2020-01-18 18:14:17 +05:00
const {colors, toEdit} = this.props;
2020-01-08 22:47:49 +05:00
2020-01-18 18:14:17 +05:00
return (
<Modal
visible={visible}
animated
animationType="fade"
transparent={true}
onRequestClose={() => (refs = [])}>
2019-12-09 13:17:40 +05:00
<View
style={{
2020-01-18 18:14:17 +05:00
width: '100%',
height: '100%',
backgroundColor: 'rgba(0,0,0,0.3)',
justifyContent: 'center',
alignItems: 'center',
2019-12-09 13:17:40 +05:00
}}>
2020-01-18 18:14:17 +05:00
<TouchableOpacity
onPress={() => close()}
2019-12-09 13:17:40 +05:00
style={{
2020-01-18 18:14:17 +05:00
width: '100%',
height: '100%',
position: 'absolute',
2019-12-09 13:17:40 +05:00
}}
/>
<View
style={{
2020-01-18 18:14:17 +05:00
...getElevation(5),
width: '80%',
maxHeight: 350,
borderRadius: 5,
backgroundColor: colors.bg,
paddingHorizontal: ph,
paddingVertical: pv,
2019-12-09 13:17:40 +05:00
}}>
2020-01-18 18:14:17 +05:00
<View
2019-12-09 13:17:40 +05:00
style={{
2020-01-18 18:14:17 +05:00
flexDirection: 'row',
2019-12-09 13:17:40 +05:00
justifyContent: 'center',
alignItems: 'center',
}}>
2020-01-18 18:14:17 +05:00
<Icon name="book-open" color={colors.accent} size={SIZE.lg} />
2019-12-09 13:17:40 +05:00
<Text
style={{
2020-01-18 18:14:17 +05:00
color: colors.accent,
fontFamily: WEIGHT.bold,
marginLeft: 5,
fontSize: SIZE.md,
2019-12-09 13:17:40 +05:00
}}>
2020-01-18 18:14:17 +05:00
{toEdit ? 'Edit Topic' : 'Add New Topic'}
2019-12-09 13:17:40 +05:00
</Text>
2020-01-18 18:14:17 +05:00
</View>
2019-12-09 13:17:40 +05:00
2020-01-18 18:14:17 +05:00
<TextInput
2019-12-09 13:17:40 +05:00
style={{
2020-01-18 18:14:17 +05:00
padding: pv,
borderWidth: 1.5,
borderColor: titleFocused ? colors.accent : colors.nav,
2019-12-09 13:17:40 +05:00
paddingHorizontal: ph,
borderRadius: 5,
2020-01-18 18:14:17 +05:00
fontSize: SIZE.sm,
fontFamily: WEIGHT.regular,
color: colors.pri,
marginTop: 20,
}}
onFocus={() => {
this.setState({
titleFocused: true,
});
}}
onBlur={() => {
this.setState({
titleFocused: true,
});
}}
defaultValue={toEdit ? toEdit.title : null}
onChangeText={value => {
this.title = value;
}}
placeholder="Enter title of topic"
placeholderTextColor={colors.icon}
/>
<View
style={{
justifyContent: 'space-around',
2019-12-09 13:17:40 +05:00
alignItems: 'center',
2020-01-18 18:14:17 +05:00
flexDirection: 'row',
marginTop: 20,
2019-12-09 13:17:40 +05:00
}}>
2020-01-18 18:14:17 +05:00
<TouchableOpacity
activeOpacity={opacity}
onPress={async () => await this.addNewTopic()}
2019-12-09 13:17:40 +05:00
style={{
2020-01-18 18:14:17 +05:00
paddingVertical: pv,
paddingHorizontal: ph,
borderRadius: 5,
width: '45%',
justifyContent: 'center',
alignItems: 'center',
borderColor: colors.accent,
backgroundColor: colors.accent,
borderWidth: 1,
2019-12-09 13:17:40 +05:00
}}>
2020-01-18 18:14:17 +05:00
<Text
style={{
fontFamily: WEIGHT.medium,
color: 'white',
fontSize: SIZE.sm,
}}>
Add
</Text>
</TouchableOpacity>
<TouchableOpacity
activeOpacity={opacity}
onPress={() => this.close()}
style={{
paddingVertical: pv,
paddingHorizontal: ph,
borderRadius: 5,
width: '45%',
justifyContent: 'center',
alignItems: 'center',
backgroundColor: colors.nav,
}}>
<Text
style={{
fontFamily: WEIGHT.medium,
color: colors.icon,
fontSize: SIZE.sm,
}}>
Cancel
</Text>
</TouchableOpacity>
</View>
2019-12-09 13:17:40 +05:00
</View>
</View>
2020-01-18 18:14:17 +05:00
</Modal>
);
}
}