2020-03-21 10:03:11 +05:00
|
|
|
import React from 'react';
|
2019-12-03 18:12:50 +05:00
|
|
|
import {
|
2020-01-18 01:04:33 +05:00
|
|
|
KeyboardAvoidingView,
|
|
|
|
|
Modal,
|
|
|
|
|
Platform,
|
2019-12-03 18:12:50 +05:00
|
|
|
Text,
|
|
|
|
|
TouchableOpacity,
|
2020-01-18 01:04:33 +05:00
|
|
|
View,
|
2019-12-03 18:12:50 +05:00
|
|
|
} from 'react-native';
|
|
|
|
|
import {FlatList, TextInput} from 'react-native-gesture-handler';
|
2020-02-11 20:33:36 +05:00
|
|
|
import Icon from 'react-native-vector-icons/MaterialCommunityIcons';
|
2020-01-18 01:04:33 +05:00
|
|
|
import {opacity, ph, pv, SIZE, WEIGHT} from '../../common/common';
|
2020-01-24 23:13:09 +05:00
|
|
|
import {ACTIONS} from '../../provider/actions';
|
2020-03-21 10:03:11 +05:00
|
|
|
import {db, DDS, getElevation, ToastEvent} from '../../utils/utils';
|
2020-03-14 13:37:07 +05:00
|
|
|
import {updateEvent} from '../DialogManager/recievers';
|
2020-03-15 09:27:10 +05:00
|
|
|
import {Toast} from '../Toast';
|
2019-12-03 18:12:50 +05:00
|
|
|
|
2019-12-06 11:09:45 +05:00
|
|
|
let refs = [];
|
2019-12-03 18:12:50 +05:00
|
|
|
|
2020-01-18 18:14:08 +05:00
|
|
|
export class AddNotebookDialog extends React.Component {
|
|
|
|
|
constructor(props) {
|
|
|
|
|
super(props);
|
|
|
|
|
this.state = {
|
|
|
|
|
visible: false,
|
2020-01-20 15:32:32 +05:00
|
|
|
topics: [],
|
2020-01-18 18:14:08 +05:00
|
|
|
description: null,
|
|
|
|
|
titleFocused: false,
|
|
|
|
|
descFocused: false,
|
2020-01-20 15:32:32 +05:00
|
|
|
count: 0,
|
|
|
|
|
topicInputFoused: false,
|
2020-01-18 18:14:08 +05:00
|
|
|
};
|
2020-01-20 15:32:32 +05:00
|
|
|
this.title = null;
|
|
|
|
|
this.description = null;
|
2020-01-18 18:14:08 +05:00
|
|
|
this.listRef;
|
|
|
|
|
this.prevItem = null;
|
|
|
|
|
this.prevIndex = null;
|
|
|
|
|
this.currentSelectedInput = null;
|
2020-02-06 13:08:35 +05:00
|
|
|
this.id = null;
|
2020-01-18 18:14:08 +05:00
|
|
|
this.backPressCount = 0;
|
2020-01-20 15:32:32 +05:00
|
|
|
this.currentInputValue = null;
|
2020-02-02 23:50:55 +05:00
|
|
|
this.titleRef;
|
|
|
|
|
this.descriptionRef;
|
2020-01-18 18:14:08 +05:00
|
|
|
}
|
|
|
|
|
|
2020-01-20 15:32:32 +05:00
|
|
|
open = () => {
|
2020-01-18 18:14:08 +05:00
|
|
|
refs = [];
|
|
|
|
|
let {toEdit} = this.props;
|
2020-02-02 23:50:55 +05:00
|
|
|
|
2020-01-20 15:32:32 +05:00
|
|
|
if (toEdit && toEdit.type === 'notebook') {
|
2020-01-18 18:14:08 +05:00
|
|
|
let topicsList = [];
|
|
|
|
|
toEdit.topics.forEach(item => {
|
|
|
|
|
if (item.title !== 'General') {
|
|
|
|
|
topicsList.push(item.title);
|
|
|
|
|
}
|
|
|
|
|
});
|
2020-02-06 13:08:35 +05:00
|
|
|
this.id = toEdit.id;
|
2020-01-20 15:32:32 +05:00
|
|
|
this.title = toEdit.title;
|
|
|
|
|
this.description = toEdit.description;
|
2020-01-18 18:14:08 +05:00
|
|
|
|
|
|
|
|
this.setState({
|
|
|
|
|
topics: [...topicsList],
|
2020-01-20 15:32:32 +05:00
|
|
|
|
|
|
|
|
visible: true,
|
|
|
|
|
});
|
|
|
|
|
} else {
|
|
|
|
|
this.setState({
|
2020-01-18 18:14:08 +05:00
|
|
|
visible: true,
|
|
|
|
|
});
|
|
|
|
|
}
|
2020-01-20 15:32:32 +05:00
|
|
|
};
|
|
|
|
|
|
|
|
|
|
close = () => {
|
2020-01-18 18:14:08 +05:00
|
|
|
refs = [];
|
|
|
|
|
this.prevIndex = null;
|
|
|
|
|
this.prevItem = null;
|
|
|
|
|
this.currentSelectedInput = null;
|
2020-01-20 15:32:32 +05:00
|
|
|
this.title = null;
|
|
|
|
|
this.description = null;
|
2020-02-06 13:08:35 +05:00
|
|
|
this.id = null;
|
2020-01-18 18:14:08 +05:00
|
|
|
this.setState({
|
|
|
|
|
visible: false,
|
2020-01-20 15:32:32 +05:00
|
|
|
topics: [],
|
|
|
|
|
descFocused: false,
|
|
|
|
|
titleFocused: false,
|
2020-01-18 18:14:08 +05:00
|
|
|
});
|
2019-12-03 18:12:50 +05:00
|
|
|
};
|
2019-12-14 21:52:14 +05:00
|
|
|
|
2020-01-18 18:14:08 +05:00
|
|
|
onDelete = index => {
|
2020-01-20 15:32:32 +05:00
|
|
|
let {topics} = this.state;
|
2019-12-14 21:52:14 +05:00
|
|
|
let prevTopics = topics;
|
|
|
|
|
refs = [];
|
|
|
|
|
prevTopics.splice(index, 1);
|
|
|
|
|
let nextTopics = [...prevTopics];
|
2020-01-20 15:32:32 +05:00
|
|
|
if (this.prevIndex === index) {
|
|
|
|
|
this.prevIndex = null;
|
|
|
|
|
this.prevItem = null;
|
|
|
|
|
this.currentInputValue = null;
|
|
|
|
|
this.topicInputRef.setNativeProps({
|
|
|
|
|
text: null,
|
|
|
|
|
});
|
|
|
|
|
}
|
2020-01-18 18:14:08 +05:00
|
|
|
this.setState({
|
|
|
|
|
topics: nextTopics,
|
|
|
|
|
});
|
2019-12-03 18:12:50 +05:00
|
|
|
};
|
|
|
|
|
|
2020-01-18 18:14:08 +05:00
|
|
|
addNewNotebook = async () => {
|
2020-03-02 15:20:22 +05:00
|
|
|
setTimeout(async () => {
|
|
|
|
|
let {topics} = this.state;
|
|
|
|
|
let {toEdit} = this.props;
|
2020-03-15 09:27:10 +05:00
|
|
|
if (!this.title || this.title.trim().length === 0)
|
|
|
|
|
return ToastEvent.show('Title is required', 'error', 'local');
|
2020-03-01 12:23:35 +05:00
|
|
|
|
2020-03-02 15:20:22 +05:00
|
|
|
let id = toEdit && toEdit.id ? toEdit.id : null;
|
2020-01-10 18:45:08 +05:00
|
|
|
|
2020-03-03 11:45:06 +05:00
|
|
|
let t = [...topics];
|
|
|
|
|
if (
|
|
|
|
|
this.currentInputValue &&
|
|
|
|
|
this.currentInputValue.trim().length !== 0
|
|
|
|
|
) {
|
|
|
|
|
t.push(this.currentInputValue);
|
2020-03-17 09:51:37 +05:00
|
|
|
this.currentInputValue = null;
|
2020-03-03 11:45:06 +05:00
|
|
|
}
|
2020-03-02 15:20:22 +05:00
|
|
|
if (id) {
|
|
|
|
|
await db.notebooks.add({
|
|
|
|
|
title: this.title,
|
|
|
|
|
description: this.description,
|
|
|
|
|
id: id,
|
|
|
|
|
});
|
|
|
|
|
|
2020-03-03 11:45:06 +05:00
|
|
|
await db.notebooks.notebook(id).topics.add(...t);
|
2020-03-02 15:20:22 +05:00
|
|
|
} else {
|
|
|
|
|
await db.notebooks.add({
|
|
|
|
|
title: this.title,
|
|
|
|
|
description: this.description,
|
2020-03-03 11:45:06 +05:00
|
|
|
topics: t,
|
2020-03-02 15:20:22 +05:00
|
|
|
id: id,
|
|
|
|
|
});
|
|
|
|
|
}
|
|
|
|
|
this.close();
|
|
|
|
|
updateEvent({type: ACTIONS.NOTEBOOKS});
|
2020-03-17 10:04:58 +05:00
|
|
|
updateEvent({type: ACTIONS.PINNED});
|
2020-02-06 13:08:35 +05:00
|
|
|
|
2020-03-15 12:08:15 +05:00
|
|
|
ToastEvent.show('New notebook added', 'success', 'local');
|
2020-03-02 15:20:22 +05:00
|
|
|
}, 100);
|
2019-12-06 11:09:45 +05:00
|
|
|
};
|
|
|
|
|
|
2020-01-20 15:32:32 +05:00
|
|
|
onSubmit = () => {
|
2020-02-02 16:18:52 +05:00
|
|
|
let {topics} = this.state;
|
2020-03-15 09:27:10 +05:00
|
|
|
if (!this.currentInputValue || this.currentInputValue.trim().length === 0)
|
2020-01-20 15:32:32 +05:00
|
|
|
return;
|
|
|
|
|
|
|
|
|
|
let prevTopics = [...topics];
|
|
|
|
|
if (this.prevItem === null) {
|
|
|
|
|
prevTopics.push(this.currentInputValue);
|
|
|
|
|
this.setState({
|
|
|
|
|
topics: prevTopics,
|
|
|
|
|
});
|
|
|
|
|
this.topicInputRef.setNativeProps({
|
|
|
|
|
text: null,
|
|
|
|
|
});
|
2020-01-06 19:03:21 +05:00
|
|
|
|
2020-01-20 15:32:32 +05:00
|
|
|
setTimeout(() => {
|
|
|
|
|
this.listRef.scrollToEnd({animated: true});
|
|
|
|
|
}, 30);
|
2020-03-01 12:23:35 +05:00
|
|
|
this.currentInputValue = null;
|
2020-01-20 15:32:32 +05:00
|
|
|
} else {
|
|
|
|
|
prevTopics[this.prevIndex] = this.currentInputValue;
|
|
|
|
|
this.setState({
|
|
|
|
|
topics: prevTopics,
|
|
|
|
|
});
|
|
|
|
|
this.currentInputValue = null;
|
|
|
|
|
if (prevTopics[this.prevIndex + 1]) {
|
|
|
|
|
this.prevIndex = this.prevIndex + 1;
|
|
|
|
|
this.prevItem = prevTopics[this.prevIndex];
|
|
|
|
|
this.currentInputValue = this.prevItem;
|
|
|
|
|
this.topicInputRef.setNativeProps({
|
|
|
|
|
text: null,
|
|
|
|
|
});
|
|
|
|
|
this.topicInputRef.setNativeProps({
|
|
|
|
|
text: prevTopics[this.prevIndex],
|
|
|
|
|
});
|
|
|
|
|
} else {
|
|
|
|
|
this.prevItem = null;
|
|
|
|
|
this.prevIndex = null;
|
|
|
|
|
this.currentInputValue = null;
|
|
|
|
|
this.topicInputRef.setNativeProps({
|
|
|
|
|
text: null,
|
|
|
|
|
});
|
|
|
|
|
setTimeout(() => {
|
|
|
|
|
this.listRef.scrollToEnd({animated: true});
|
|
|
|
|
}, 30);
|
2020-01-06 19:03:21 +05:00
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
};
|
|
|
|
|
|
2020-01-18 18:14:08 +05:00
|
|
|
render() {
|
|
|
|
|
const {colors, toEdit} = this.props;
|
|
|
|
|
const {
|
|
|
|
|
titleFocused,
|
|
|
|
|
descFocused,
|
|
|
|
|
topics,
|
|
|
|
|
visible,
|
2020-01-20 15:32:32 +05:00
|
|
|
topicInputFoused,
|
2020-01-18 18:14:08 +05:00
|
|
|
} = this.state;
|
|
|
|
|
return (
|
|
|
|
|
<Modal
|
|
|
|
|
visible={visible}
|
|
|
|
|
transparent={true}
|
|
|
|
|
animated
|
|
|
|
|
animationType="fade"
|
2020-03-02 12:10:13 +05:00
|
|
|
onShow={() => {
|
2020-03-02 12:12:23 +05:00
|
|
|
this.titleRef.focus();
|
2020-03-02 12:10:13 +05:00
|
|
|
}}
|
2020-01-20 15:32:32 +05:00
|
|
|
onRequestClose={this.close}>
|
2020-01-18 18:14:08 +05:00
|
|
|
<KeyboardAvoidingView
|
|
|
|
|
behavior={Platform.OS === 'ios' ? 'padding' : null}
|
2020-01-08 22:47:49 +05:00
|
|
|
style={{
|
|
|
|
|
width: '100%',
|
|
|
|
|
height: '100%',
|
2020-01-18 18:14:08 +05:00
|
|
|
backgroundColor: 'rgba(0,0,0,0.3)',
|
|
|
|
|
justifyContent: 'center',
|
|
|
|
|
alignItems: 'center',
|
2019-12-03 18:12:50 +05:00
|
|
|
}}>
|
2020-01-18 18:14:08 +05:00
|
|
|
<TouchableOpacity
|
2020-01-20 15:32:32 +05:00
|
|
|
onPress={this.close}
|
2019-12-03 18:12:50 +05:00
|
|
|
style={{
|
2020-01-18 18:14:08 +05:00
|
|
|
width: '100%',
|
|
|
|
|
height: '100%',
|
|
|
|
|
position: 'absolute',
|
2020-01-08 22:47:49 +05:00
|
|
|
}}
|
2019-12-03 22:05:47 +05:00
|
|
|
/>
|
|
|
|
|
<View
|
|
|
|
|
style={{
|
2020-01-18 18:14:08 +05:00
|
|
|
...getElevation(5),
|
|
|
|
|
width: DDS.isTab ? '50%' : '80%',
|
2020-01-20 15:32:32 +05:00
|
|
|
maxHeight: '80%',
|
2020-01-18 18:14:08 +05:00
|
|
|
borderRadius: 5,
|
|
|
|
|
backgroundColor: colors.bg,
|
|
|
|
|
paddingHorizontal: ph,
|
|
|
|
|
paddingVertical: pv,
|
2019-12-03 18:12:50 +05:00
|
|
|
}}>
|
2020-01-18 18:14:08 +05:00
|
|
|
<View
|
2019-12-03 18:12:50 +05:00
|
|
|
style={{
|
2020-01-18 18:14:08 +05:00
|
|
|
flexDirection: 'row',
|
2019-12-03 18:12:50 +05:00
|
|
|
justifyContent: 'center',
|
|
|
|
|
alignItems: 'center',
|
|
|
|
|
}}>
|
2020-02-11 20:33:36 +05:00
|
|
|
<Icon name="book-outline" color={colors.accent} size={SIZE.lg} />
|
2019-12-03 18:12:50 +05:00
|
|
|
<Text
|
|
|
|
|
style={{
|
2020-01-18 18:14:08 +05:00
|
|
|
color: colors.accent,
|
|
|
|
|
fontFamily: WEIGHT.bold,
|
|
|
|
|
marginLeft: 5,
|
|
|
|
|
fontSize: SIZE.md,
|
2019-12-03 18:12:50 +05:00
|
|
|
}}>
|
2020-01-20 15:32:32 +05:00
|
|
|
{toEdit && toEdit.dateCreated
|
|
|
|
|
? 'Edit Notebook'
|
|
|
|
|
: 'New Notebook'}
|
2019-12-03 18:12:50 +05:00
|
|
|
</Text>
|
2020-01-18 18:14:08 +05:00
|
|
|
</View>
|
|
|
|
|
|
|
|
|
|
<TextInput
|
2020-02-02 23:50:55 +05:00
|
|
|
ref={ref => (this.titleRef = ref)}
|
2020-01-18 18:14:08 +05:00
|
|
|
style={{
|
|
|
|
|
padding: pv - 5,
|
|
|
|
|
borderWidth: 1.5,
|
|
|
|
|
borderColor: titleFocused ? colors.accent : colors.nav,
|
|
|
|
|
paddingHorizontal: ph,
|
|
|
|
|
borderRadius: 5,
|
|
|
|
|
fontSize: SIZE.sm,
|
2020-01-22 02:50:25 +05:00
|
|
|
height: 35,
|
2020-01-18 18:14:08 +05:00
|
|
|
fontFamily: WEIGHT.regular,
|
|
|
|
|
color: colors.pri,
|
|
|
|
|
marginTop: 20,
|
|
|
|
|
marginBottom: 5,
|
|
|
|
|
}}
|
|
|
|
|
onFocus={() => {
|
|
|
|
|
this.setState({
|
|
|
|
|
titleFocused: true,
|
|
|
|
|
});
|
2019-12-03 22:05:47 +05:00
|
|
|
}}
|
2020-01-18 18:14:08 +05:00
|
|
|
onBlur={() => {
|
|
|
|
|
this.setState({
|
|
|
|
|
titleFocused: false,
|
|
|
|
|
});
|
|
|
|
|
}}
|
|
|
|
|
defaultValue={toEdit ? toEdit.title : null}
|
|
|
|
|
onChangeText={value => {
|
2020-01-20 15:32:32 +05:00
|
|
|
this.title = value;
|
2020-01-18 18:14:08 +05:00
|
|
|
}}
|
2020-02-02 23:50:55 +05:00
|
|
|
onSubmitEditing={() => {
|
|
|
|
|
this.descriptionRef.focus();
|
|
|
|
|
}}
|
2020-01-18 18:14:08 +05:00
|
|
|
placeholder="Title of notebook"
|
|
|
|
|
placeholderTextColor={colors.icon}
|
|
|
|
|
/>
|
|
|
|
|
<TextInput
|
2020-02-02 23:50:55 +05:00
|
|
|
ref={ref => (this.descriptionRef = ref)}
|
2019-12-03 18:12:50 +05:00
|
|
|
style={{
|
2020-01-18 18:14:08 +05:00
|
|
|
padding: pv - 5,
|
|
|
|
|
borderWidth: 1.5,
|
|
|
|
|
borderColor: descFocused ? colors.accent : colors.nav,
|
2019-12-03 18:12:50 +05:00
|
|
|
paddingHorizontal: ph,
|
|
|
|
|
borderRadius: 5,
|
2020-03-15 09:31:03 +05:00
|
|
|
minHeight: 35,
|
|
|
|
|
fontSize: SIZE.xs + 1,
|
2020-01-18 18:14:08 +05:00
|
|
|
fontFamily: WEIGHT.regular,
|
|
|
|
|
color: colors.pri,
|
|
|
|
|
marginTop: 5,
|
|
|
|
|
marginBottom: 10,
|
|
|
|
|
}}
|
2020-03-15 09:31:03 +05:00
|
|
|
textAlignVertical="top"
|
|
|
|
|
numberOfLines={2}
|
2020-01-18 18:14:08 +05:00
|
|
|
onFocus={() => {
|
|
|
|
|
this.setState({
|
|
|
|
|
descFocused: true,
|
|
|
|
|
});
|
|
|
|
|
}}
|
|
|
|
|
onBlur={() => {
|
|
|
|
|
this.setState({
|
|
|
|
|
descFocused: false,
|
|
|
|
|
});
|
|
|
|
|
}}
|
|
|
|
|
defaultValue={toEdit ? toEdit.description : null}
|
|
|
|
|
onChangeText={value => {
|
2020-01-20 15:32:32 +05:00
|
|
|
this.description = value;
|
2020-01-18 18:14:08 +05:00
|
|
|
}}
|
2020-02-02 23:50:55 +05:00
|
|
|
onSubmitEditing={() => {
|
|
|
|
|
this.topicInputRef.focus();
|
|
|
|
|
}}
|
2020-03-15 09:31:03 +05:00
|
|
|
multiline
|
|
|
|
|
placeholder="Write a short description about notebook (optional)"
|
2020-01-18 18:14:08 +05:00
|
|
|
placeholderTextColor={colors.icon}
|
|
|
|
|
/>
|
|
|
|
|
|
2020-01-20 15:32:32 +05:00
|
|
|
<View
|
2020-01-18 18:14:08 +05:00
|
|
|
style={{
|
2020-01-20 15:32:32 +05:00
|
|
|
flexDirection: 'row',
|
|
|
|
|
justifyContent: 'space-between',
|
|
|
|
|
alignItems: 'center',
|
|
|
|
|
marginTop: 10,
|
2020-01-18 18:14:08 +05:00
|
|
|
}}>
|
2020-01-20 15:32:32 +05:00
|
|
|
<TextInput
|
|
|
|
|
ref={ref => (this.topicInputRef = ref)}
|
|
|
|
|
onChangeText={value => {
|
|
|
|
|
this.currentInputValue = value;
|
|
|
|
|
if (this.prevItem !== null) {
|
|
|
|
|
refs[this.prevIndex].setNativeProps({
|
|
|
|
|
text: this.prevIndex + 1 + '. ' + value,
|
|
|
|
|
style: {
|
|
|
|
|
borderBottomColor: colors.accent,
|
|
|
|
|
},
|
|
|
|
|
});
|
|
|
|
|
}
|
|
|
|
|
}}
|
|
|
|
|
blurOnSubmit={false}
|
|
|
|
|
onFocus={() => {
|
|
|
|
|
this.setState({
|
|
|
|
|
topicInputFoused: true,
|
|
|
|
|
});
|
|
|
|
|
}}
|
|
|
|
|
onBlur={() => {
|
2020-02-23 10:03:41 +05:00
|
|
|
this.onSubmit();
|
2020-01-20 15:32:32 +05:00
|
|
|
this.setState({
|
|
|
|
|
topicInputFoused: false,
|
|
|
|
|
});
|
|
|
|
|
}}
|
|
|
|
|
onSubmitEditing={this.onSubmit}
|
|
|
|
|
style={{
|
|
|
|
|
padding: pv - 5,
|
|
|
|
|
paddingHorizontal: 0,
|
|
|
|
|
borderRadius: 5,
|
|
|
|
|
borderWidth: 1.5,
|
2020-01-22 02:50:25 +05:00
|
|
|
height: 35,
|
2020-01-20 15:32:32 +05:00
|
|
|
fontSize: SIZE.sm,
|
|
|
|
|
borderColor: topicInputFoused ? colors.accent : colors.nav,
|
|
|
|
|
fontFamily: WEIGHT.regular,
|
|
|
|
|
color: colors.pri,
|
|
|
|
|
paddingHorizontal: ph,
|
|
|
|
|
width: '85%',
|
|
|
|
|
maxWidth: '85%',
|
|
|
|
|
}}
|
|
|
|
|
placeholder="Add a topic"
|
|
|
|
|
placeholderTextColor={colors.icon}
|
|
|
|
|
/>
|
|
|
|
|
<TouchableOpacity
|
|
|
|
|
onPress={this.onSubmit}
|
|
|
|
|
style={{
|
|
|
|
|
justifyContent: 'center',
|
|
|
|
|
alignItems: 'center',
|
|
|
|
|
borderWidth: 1.5,
|
|
|
|
|
borderColor: topicInputFoused ? colors.accent : colors.nav,
|
|
|
|
|
borderRadius: 5,
|
2020-01-22 02:50:25 +05:00
|
|
|
width: '12%',
|
|
|
|
|
height: 35,
|
2020-01-20 15:32:32 +05:00
|
|
|
}}>
|
|
|
|
|
<Icon
|
|
|
|
|
name="plus"
|
|
|
|
|
size={SIZE.lg}
|
|
|
|
|
color={topicInputFoused ? colors.accent : colors.icon}
|
|
|
|
|
/>
|
|
|
|
|
</TouchableOpacity>
|
|
|
|
|
</View>
|
2020-01-18 18:14:08 +05:00
|
|
|
|
|
|
|
|
<FlatList
|
|
|
|
|
data={topics}
|
|
|
|
|
ref={ref => (this.listRef = ref)}
|
|
|
|
|
removeClippedSubviews={false}
|
|
|
|
|
enableEmptySections={false}
|
|
|
|
|
getItemLayout={(data, index) => ({
|
|
|
|
|
length: 50,
|
|
|
|
|
offset: 50 * index,
|
|
|
|
|
index,
|
|
|
|
|
})}
|
2020-01-20 15:32:32 +05:00
|
|
|
keyExtractor={(item, index) => item + index.toString()}
|
2020-01-18 18:14:08 +05:00
|
|
|
renderItem={({item, index}) => (
|
|
|
|
|
<TopicItem
|
|
|
|
|
item={item}
|
2020-01-20 15:32:32 +05:00
|
|
|
onPress={(item, index) => {
|
|
|
|
|
this.prevIndex = index;
|
|
|
|
|
this.prevItem = item;
|
|
|
|
|
this.topicInputRef.setNativeProps({
|
|
|
|
|
text: item,
|
|
|
|
|
});
|
|
|
|
|
this.topicInputRef.focus();
|
|
|
|
|
this.currentInputValue = item;
|
|
|
|
|
}}
|
|
|
|
|
onDelete={this.onDelete}
|
2020-01-18 18:14:08 +05:00
|
|
|
index={index}
|
|
|
|
|
colors={colors}
|
|
|
|
|
/>
|
|
|
|
|
)}
|
|
|
|
|
/>
|
|
|
|
|
|
|
|
|
|
<View
|
|
|
|
|
style={{
|
|
|
|
|
justifyContent: 'space-between',
|
2019-12-03 18:12:50 +05:00
|
|
|
alignItems: 'center',
|
2020-01-18 18:14:08 +05:00
|
|
|
flexDirection: 'row',
|
|
|
|
|
width: '100%',
|
|
|
|
|
marginTop: 20,
|
2019-12-03 18:12:50 +05:00
|
|
|
}}>
|
2020-01-18 18:14:08 +05:00
|
|
|
<TouchableOpacity
|
|
|
|
|
activeOpacity={opacity}
|
2020-01-20 15:32:32 +05:00
|
|
|
onPress={this.addNewNotebook}
|
2019-12-03 18:12:50 +05:00
|
|
|
style={{
|
2020-01-18 18:14:08 +05:00
|
|
|
paddingVertical: pv,
|
|
|
|
|
paddingHorizontal: ph,
|
|
|
|
|
borderRadius: 5,
|
|
|
|
|
width: '48%',
|
|
|
|
|
justifyContent: 'center',
|
|
|
|
|
alignItems: 'center',
|
|
|
|
|
borderColor: colors.accent,
|
|
|
|
|
backgroundColor: colors.accent,
|
|
|
|
|
borderWidth: 1,
|
2019-12-03 18:12:50 +05:00
|
|
|
}}>
|
2020-01-18 18:14:08 +05:00
|
|
|
<Text
|
|
|
|
|
style={{
|
|
|
|
|
fontFamily: WEIGHT.medium,
|
|
|
|
|
color: 'white',
|
|
|
|
|
fontSize: SIZE.sm,
|
|
|
|
|
}}>
|
|
|
|
|
Add
|
|
|
|
|
</Text>
|
|
|
|
|
</TouchableOpacity>
|
|
|
|
|
|
|
|
|
|
<TouchableOpacity
|
|
|
|
|
activeOpacity={opacity}
|
2020-01-20 15:32:32 +05:00
|
|
|
onPress={this.close}
|
2020-01-18 18:14:08 +05:00
|
|
|
style={{
|
|
|
|
|
paddingVertical: pv,
|
|
|
|
|
paddingHorizontal: ph,
|
|
|
|
|
borderRadius: 5,
|
|
|
|
|
width: '48%',
|
|
|
|
|
justifyContent: 'center',
|
|
|
|
|
alignItems: 'center',
|
|
|
|
|
backgroundColor: colors.nav,
|
|
|
|
|
}}>
|
|
|
|
|
<Text
|
|
|
|
|
style={{
|
|
|
|
|
fontFamily: WEIGHT.medium,
|
|
|
|
|
color: colors.icon,
|
|
|
|
|
fontSize: SIZE.sm,
|
|
|
|
|
}}>
|
|
|
|
|
Cancel
|
|
|
|
|
</Text>
|
|
|
|
|
</TouchableOpacity>
|
|
|
|
|
</View>
|
2019-12-03 18:12:50 +05:00
|
|
|
</View>
|
2020-01-18 18:14:08 +05:00
|
|
|
</KeyboardAvoidingView>
|
2020-03-15 09:27:10 +05:00
|
|
|
<Toast context="local" />
|
2020-01-18 18:14:08 +05:00
|
|
|
</Modal>
|
|
|
|
|
);
|
|
|
|
|
}
|
|
|
|
|
}
|
2019-12-03 18:12:50 +05:00
|
|
|
|
2020-01-20 15:32:32 +05:00
|
|
|
const TopicItem = ({item, index, colors, onPress, onDelete}) => {
|
2019-12-03 18:12:50 +05:00
|
|
|
const topicRef = ref => (refs[index] = ref);
|
|
|
|
|
|
|
|
|
|
return (
|
|
|
|
|
<View
|
|
|
|
|
style={{
|
|
|
|
|
flexDirection: 'row',
|
|
|
|
|
justifyContent: 'space-between',
|
|
|
|
|
alignItems: 'center',
|
|
|
|
|
marginTop: 10,
|
|
|
|
|
}}>
|
2020-01-20 15:32:32 +05:00
|
|
|
<TouchableOpacity
|
2019-12-03 18:12:50 +05:00
|
|
|
style={{
|
2020-01-20 15:32:32 +05:00
|
|
|
width: '100%',
|
2019-12-03 18:12:50 +05:00
|
|
|
}}
|
2020-01-20 15:32:32 +05:00
|
|
|
onPress={() => {
|
|
|
|
|
onPress(item, index);
|
|
|
|
|
}}>
|
|
|
|
|
<TextInput
|
|
|
|
|
ref={topicRef}
|
|
|
|
|
editable={false}
|
|
|
|
|
style={{
|
|
|
|
|
padding: pv - 5,
|
|
|
|
|
paddingHorizontal: 0,
|
|
|
|
|
fontSize: SIZE.sm,
|
|
|
|
|
fontFamily: WEIGHT.regular,
|
|
|
|
|
color: colors.pri,
|
|
|
|
|
paddingHorizontal: ph,
|
|
|
|
|
borderBottomWidth: 1.5,
|
|
|
|
|
borderBottomColor: colors.nav,
|
|
|
|
|
paddingRight: 40,
|
|
|
|
|
width: '100%',
|
|
|
|
|
maxWidth: '100%',
|
|
|
|
|
}}
|
|
|
|
|
defaultValue={index + 1 + '. ' + item}
|
|
|
|
|
placeholder="Add a topic"
|
|
|
|
|
placeholderTextColor={colors.icon}
|
|
|
|
|
/>
|
|
|
|
|
</TouchableOpacity>
|
2019-12-03 22:05:47 +05:00
|
|
|
<TouchableOpacity
|
2020-01-20 15:32:32 +05:00
|
|
|
onPress={() => {
|
|
|
|
|
onDelete(index);
|
|
|
|
|
}}
|
2019-12-03 22:05:47 +05:00
|
|
|
style={{
|
|
|
|
|
justifyContent: 'center',
|
|
|
|
|
alignItems: 'center',
|
2020-01-20 15:32:32 +05:00
|
|
|
position: 'absolute',
|
|
|
|
|
right: 0,
|
|
|
|
|
borderColor: colors.nav,
|
2020-01-08 22:47:49 +05:00
|
|
|
borderRadius: 5,
|
|
|
|
|
width: 40,
|
|
|
|
|
height: 40,
|
2019-12-03 22:05:47 +05:00
|
|
|
}}>
|
2020-01-20 15:32:32 +05:00
|
|
|
<Icon name="minus" size={SIZE.lg} color={colors.icon} />
|
2019-12-03 22:05:47 +05:00
|
|
|
</TouchableOpacity>
|
2019-12-03 18:12:50 +05:00
|
|
|
</View>
|
|
|
|
|
);
|
|
|
|
|
};
|