2019-12-09 13:17:40 +05:00
|
|
|
import React, {useEffect, useState, createRef} from 'react';
|
|
|
|
|
import {
|
|
|
|
|
ScrollView,
|
|
|
|
|
View,
|
|
|
|
|
Text,
|
|
|
|
|
TouchableOpacity,
|
|
|
|
|
Dimensions,
|
|
|
|
|
Image,
|
|
|
|
|
SafeAreaView,
|
|
|
|
|
Platform,
|
|
|
|
|
Modal,
|
|
|
|
|
} from 'react-native';
|
|
|
|
|
import NavigationService from '../../services/NavigationService';
|
|
|
|
|
import {
|
|
|
|
|
COLOR_SCHEME,
|
|
|
|
|
SIZE,
|
|
|
|
|
br,
|
|
|
|
|
ph,
|
|
|
|
|
pv,
|
|
|
|
|
opacity,
|
|
|
|
|
FONT,
|
|
|
|
|
WEIGHT,
|
|
|
|
|
} from '../../common/common';
|
|
|
|
|
import Icon from 'react-native-vector-icons/Feather';
|
|
|
|
|
|
|
|
|
|
import {getElevation, h, w, timeSince, ToastEvent} from '../../utils/utils';
|
|
|
|
|
import {FlatList, TextInput} from 'react-native-gesture-handler';
|
|
|
|
|
import {useForceUpdate} from '../../views/ListsEditor';
|
2019-12-11 01:10:04 +05:00
|
|
|
import {db} from '../../../App';
|
2019-12-14 19:26:44 +05:00
|
|
|
import {useAppContext} from '../../provider/useAppContext';
|
2020-01-17 21:26:01 +05:00
|
|
|
import {useTracked} from '../../provider';
|
2019-12-09 13:17:40 +05:00
|
|
|
|
|
|
|
|
export const AddTopicDialog = ({
|
|
|
|
|
visible,
|
|
|
|
|
close = () => {},
|
|
|
|
|
notebookID,
|
|
|
|
|
toEdit = null,
|
|
|
|
|
}) => {
|
2020-01-17 21:26:01 +05:00
|
|
|
const [state, dispatch] = useTracked();
|
|
|
|
|
const {colors} = state;
|
2020-01-08 22:47:49 +05:00
|
|
|
const [titleFocused, setTitleFocused] = useState(false);
|
|
|
|
|
|
2019-12-09 13:17:40 +05:00
|
|
|
let title = null;
|
|
|
|
|
const addNewTopic = async () => {
|
|
|
|
|
if (!title)
|
|
|
|
|
return ToastEvent.show('Title is required', 'error', 3000, () => {}, '');
|
2019-12-11 01:10:04 +05:00
|
|
|
db.addTopicToNotebook(notebookID, title);
|
2019-12-09 13:17:40 +05:00
|
|
|
ToastEvent.show('New topic added', 'success', 3000, () => {}, '');
|
|
|
|
|
close(true);
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
return (
|
|
|
|
|
<Modal
|
|
|
|
|
visible={visible}
|
2019-12-11 15:20:18 +05:00
|
|
|
animated
|
|
|
|
|
animationType="fade"
|
2019-12-09 13:17:40 +05:00
|
|
|
transparent={true}
|
|
|
|
|
onRequestClose={() => (refs = [])}>
|
|
|
|
|
<View
|
|
|
|
|
style={{
|
|
|
|
|
width: '100%',
|
|
|
|
|
height: '100%',
|
2020-01-08 22:47:49 +05:00
|
|
|
backgroundColor: 'rgba(0,0,0,0.3)',
|
2019-12-09 13:17:40 +05:00
|
|
|
justifyContent: 'center',
|
|
|
|
|
alignItems: 'center',
|
|
|
|
|
}}>
|
2020-01-08 22:47:49 +05:00
|
|
|
<TouchableOpacity
|
|
|
|
|
onPress={() => close()}
|
|
|
|
|
style={{
|
|
|
|
|
width: '100%',
|
|
|
|
|
height: '100%',
|
|
|
|
|
position: 'absolute',
|
|
|
|
|
}}
|
|
|
|
|
/>
|
|
|
|
|
|
2019-12-09 13:17:40 +05:00
|
|
|
<View
|
|
|
|
|
style={{
|
2019-12-11 15:20:18 +05:00
|
|
|
...getElevation(5),
|
2019-12-09 13:17:40 +05:00
|
|
|
width: '80%',
|
|
|
|
|
maxHeight: 350,
|
|
|
|
|
borderRadius: 5,
|
|
|
|
|
backgroundColor: colors.bg,
|
|
|
|
|
paddingHorizontal: ph,
|
|
|
|
|
paddingVertical: pv,
|
|
|
|
|
}}>
|
|
|
|
|
<View
|
|
|
|
|
style={{
|
|
|
|
|
flexDirection: 'row',
|
|
|
|
|
justifyContent: 'center',
|
|
|
|
|
alignItems: 'center',
|
|
|
|
|
}}>
|
|
|
|
|
<Icon name="book-open" color={colors.accent} size={SIZE.lg} />
|
|
|
|
|
<Text
|
|
|
|
|
style={{
|
|
|
|
|
color: colors.accent,
|
2019-12-14 16:00:16 +05:00
|
|
|
fontFamily: WEIGHT.bold,
|
|
|
|
|
marginLeft: 5,
|
|
|
|
|
fontSize: SIZE.md,
|
2019-12-09 13:17:40 +05:00
|
|
|
}}>
|
|
|
|
|
{toEdit ? 'Edit Topic' : 'Add New Topic'}
|
|
|
|
|
</Text>
|
|
|
|
|
</View>
|
|
|
|
|
|
|
|
|
|
<TextInput
|
|
|
|
|
style={{
|
|
|
|
|
padding: pv,
|
|
|
|
|
borderWidth: 1.5,
|
2020-01-08 22:47:49 +05:00
|
|
|
borderColor: titleFocused ? colors.accent : colors.nav,
|
2019-12-09 13:17:40 +05:00
|
|
|
paddingHorizontal: ph,
|
|
|
|
|
borderRadius: 5,
|
|
|
|
|
fontSize: SIZE.sm,
|
|
|
|
|
fontFamily: WEIGHT.regular,
|
|
|
|
|
color: colors.pri,
|
|
|
|
|
marginTop: 20,
|
|
|
|
|
}}
|
2020-01-08 22:47:49 +05:00
|
|
|
onFocus={() => {
|
|
|
|
|
setTitleFocused(true);
|
|
|
|
|
}}
|
|
|
|
|
onBlur={() => {
|
|
|
|
|
setTitleFocused(false);
|
|
|
|
|
}}
|
2019-12-09 13:17:40 +05:00
|
|
|
defaultValue={toEdit ? toEdit.title : null}
|
|
|
|
|
onChangeText={value => {
|
|
|
|
|
title = value;
|
|
|
|
|
}}
|
|
|
|
|
placeholder="Enter title of topic"
|
|
|
|
|
placeholderTextColor={colors.icon}
|
|
|
|
|
/>
|
|
|
|
|
|
|
|
|
|
<View
|
|
|
|
|
style={{
|
|
|
|
|
justifyContent: 'space-around',
|
|
|
|
|
alignItems: 'center',
|
|
|
|
|
flexDirection: 'row',
|
|
|
|
|
marginTop: 20,
|
|
|
|
|
}}>
|
|
|
|
|
<TouchableOpacity
|
|
|
|
|
activeOpacity={opacity}
|
|
|
|
|
onPress={async () => await addNewTopic()}
|
|
|
|
|
style={{
|
|
|
|
|
paddingVertical: pv,
|
|
|
|
|
paddingHorizontal: ph,
|
|
|
|
|
borderRadius: 5,
|
|
|
|
|
width: '45%',
|
|
|
|
|
justifyContent: 'center',
|
|
|
|
|
alignItems: 'center',
|
|
|
|
|
borderColor: colors.accent,
|
|
|
|
|
backgroundColor: colors.accent,
|
|
|
|
|
borderWidth: 1,
|
|
|
|
|
}}>
|
|
|
|
|
<Text
|
|
|
|
|
style={{
|
|
|
|
|
fontFamily: WEIGHT.medium,
|
|
|
|
|
color: 'white',
|
|
|
|
|
fontSize: SIZE.sm,
|
|
|
|
|
}}>
|
|
|
|
|
Add
|
|
|
|
|
</Text>
|
|
|
|
|
</TouchableOpacity>
|
|
|
|
|
|
|
|
|
|
<TouchableOpacity
|
|
|
|
|
activeOpacity={opacity}
|
|
|
|
|
onPress={() => 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>
|
|
|
|
|
</View>
|
|
|
|
|
</View>
|
|
|
|
|
</Modal>
|
|
|
|
|
);
|
|
|
|
|
};
|