mirror of
https://github.com/streetwriters/notesnook.git
synced 2025-12-22 14:39:34 +01:00
minor fixes and improvements
This commit is contained in:
@@ -1,5 +1,6 @@
|
|||||||
import React from 'react';
|
import React from 'react';
|
||||||
import {
|
import {
|
||||||
|
Keyboard,
|
||||||
KeyboardAvoidingView,
|
KeyboardAvoidingView,
|
||||||
Modal,
|
Modal,
|
||||||
Platform,
|
Platform,
|
||||||
@@ -15,10 +16,11 @@ import {Actions} from '../../provider/Actions';
|
|||||||
import {Button} from '../Button';
|
import {Button} from '../Button';
|
||||||
import {updateEvent} from '../DialogManager/recievers';
|
import {updateEvent} from '../DialogManager/recievers';
|
||||||
import {Toast} from '../Toast';
|
import {Toast} from '../Toast';
|
||||||
import {ToastEvent} from "../../services/EventManager";
|
import {ToastEvent} from '../../services/EventManager';
|
||||||
import {ph, pv, SIZE, WEIGHT} from "../../utils/SizeUtils";
|
import {ph, pv, SIZE, WEIGHT} from '../../utils/SizeUtils';
|
||||||
import {db} from "../../utils/DB";
|
import {db} from '../../utils/DB';
|
||||||
import {DDS} from "../../services/DeviceDetection";
|
import {DDS} from '../../services/DeviceDetection';
|
||||||
|
import {ActionIcon} from '../ActionIcon';
|
||||||
|
|
||||||
let refs = [];
|
let refs = [];
|
||||||
|
|
||||||
@@ -32,7 +34,8 @@ export class AddNotebookDialog extends React.Component {
|
|||||||
titleFocused: false,
|
titleFocused: false,
|
||||||
descFocused: false,
|
descFocused: false,
|
||||||
count: 0,
|
count: 0,
|
||||||
topicInputFoused: false,
|
topicInputFocused: false,
|
||||||
|
editTopic: false,
|
||||||
};
|
};
|
||||||
this.title = null;
|
this.title = null;
|
||||||
this.description = null;
|
this.description = null;
|
||||||
@@ -99,7 +102,7 @@ export class AddNotebookDialog extends React.Component {
|
|||||||
let edit = this.props.toEdit;
|
let edit = this.props.toEdit;
|
||||||
if (edit && edit.id) {
|
if (edit && edit.id) {
|
||||||
let topicToDelete = edit.topics[index + 1];
|
let topicToDelete = edit.topics[index + 1];
|
||||||
console.log(topicToDelete)
|
console.log(topicToDelete);
|
||||||
if (topicToDelete) {
|
if (topicToDelete) {
|
||||||
this.topicsToDelete.push(topicToDelete.id);
|
this.topicsToDelete.push(topicToDelete.id);
|
||||||
}
|
}
|
||||||
@@ -139,12 +142,10 @@ export class AddNotebookDialog extends React.Component {
|
|||||||
prevTopics[this.prevIndex] = this.currentInputValue;
|
prevTopics[this.prevIndex] = this.currentInputValue;
|
||||||
} else {
|
} else {
|
||||||
prevTopics.push(this.currentInputValue);
|
prevTopics.push(this.currentInputValue);
|
||||||
this.currentInputValue =
|
this.currentInputValue = null;
|
||||||
null;
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
if (id) {
|
if (id) {
|
||||||
|
|
||||||
if (this.topicsToDelete?.length > 0) {
|
if (this.topicsToDelete?.length > 0) {
|
||||||
await db.notebooks
|
await db.notebooks
|
||||||
.notebook(toEdit.id)
|
.notebook(toEdit.id)
|
||||||
@@ -212,7 +213,7 @@ export class AddNotebookDialog extends React.Component {
|
|||||||
topics: prevTopics,
|
topics: prevTopics,
|
||||||
});
|
});
|
||||||
this.currentInputValue = null;
|
this.currentInputValue = null;
|
||||||
if (prevTopics[this.prevIndex + 1] && forward) {
|
/* if (prevTopics[this.prevIndex + 1] && forward) {
|
||||||
this.prevIndex = this.prevIndex + 1;
|
this.prevIndex = this.prevIndex + 1;
|
||||||
this.prevItem = prevTopics[this.prevIndex];
|
this.prevItem = prevTopics[this.prevIndex];
|
||||||
this.currentInputValue = this.prevItem;
|
this.currentInputValue = this.prevItem;
|
||||||
@@ -222,20 +223,31 @@ export class AddNotebookDialog extends React.Component {
|
|||||||
this.topicInputRef.setNativeProps({
|
this.topicInputRef.setNativeProps({
|
||||||
text: prevTopics[this.prevIndex],
|
text: prevTopics[this.prevIndex],
|
||||||
});
|
});
|
||||||
} else {
|
this.setState({
|
||||||
|
editTopic:true
|
||||||
|
})
|
||||||
|
} else {} */
|
||||||
|
|
||||||
|
if (this.state.editTopic) {
|
||||||
|
this.topicInputRef.blur();
|
||||||
|
Keyboard.dismiss();
|
||||||
|
this.setState({
|
||||||
|
editTopic: false,
|
||||||
|
});
|
||||||
|
}
|
||||||
this.prevItem = null;
|
this.prevItem = null;
|
||||||
this.prevIndex = null;
|
this.prevIndex = null;
|
||||||
this.currentInputValue = null;
|
this.currentInputValue = null;
|
||||||
this.topicInputRef.setNativeProps({
|
this.topicInputRef.setNativeProps({
|
||||||
text: null,
|
text: null,
|
||||||
});
|
});
|
||||||
|
|
||||||
if (forward) {
|
if (forward) {
|
||||||
setTimeout(() => {
|
setTimeout(() => {
|
||||||
this.listRef.scrollToEnd({animated: true});
|
this.listRef.scrollToEnd({animated: true});
|
||||||
}, 30);
|
}, 30);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
|
||||||
};
|
};
|
||||||
|
|
||||||
render() {
|
render() {
|
||||||
@@ -245,14 +257,14 @@ export class AddNotebookDialog extends React.Component {
|
|||||||
descFocused,
|
descFocused,
|
||||||
topics,
|
topics,
|
||||||
visible,
|
visible,
|
||||||
topicInputFoused,
|
topicInputFocused,
|
||||||
} = this.state;
|
} = this.state;
|
||||||
return (
|
return (
|
||||||
<Modal
|
<Modal
|
||||||
visible={visible}
|
visible={visible}
|
||||||
transparent={true}
|
transparent={true}
|
||||||
animated
|
animated
|
||||||
animationType={DDS.isTab ? "fade" : "slide"}
|
animationType={DDS.isTab ? 'fade' : 'slide'}
|
||||||
onShow={() => {
|
onShow={() => {
|
||||||
this.topicsToDelete = [];
|
this.topicsToDelete = [];
|
||||||
this.titleRef.focus();
|
this.titleRef.focus();
|
||||||
@@ -262,7 +274,7 @@ export class AddNotebookDialog extends React.Component {
|
|||||||
<KeyboardAvoidingView
|
<KeyboardAvoidingView
|
||||||
behavior={Platform.OS === 'ios' ? 'padding' : null}
|
behavior={Platform.OS === 'ios' ? 'padding' : null}
|
||||||
style={styles.wrapper}>
|
style={styles.wrapper}>
|
||||||
<TouchableOpacity onPress={this.close} style={styles.overlay}/>
|
<TouchableOpacity onPress={this.close} style={styles.overlay} />
|
||||||
<View
|
<View
|
||||||
style={[
|
style={[
|
||||||
styles.container,
|
styles.container,
|
||||||
@@ -276,7 +288,7 @@ export class AddNotebookDialog extends React.Component {
|
|||||||
color={colors.accent}
|
color={colors.accent}
|
||||||
size={SIZE.xl}
|
size={SIZE.xl}
|
||||||
/>
|
/>
|
||||||
<Text style={[styles.headingText, {color: colors.accent}]}>
|
<Text style={[styles.headingText, {color: colors.heading}]}>
|
||||||
{toEdit && toEdit.dateCreated
|
{toEdit && toEdit.dateCreated
|
||||||
? 'Edit Notebook'
|
? 'Edit Notebook'
|
||||||
: 'New Notebook'}
|
: 'New Notebook'}
|
||||||
@@ -363,20 +375,21 @@ export class AddNotebookDialog extends React.Component {
|
|||||||
blurOnSubmit={false}
|
blurOnSubmit={false}
|
||||||
onFocus={() => {
|
onFocus={() => {
|
||||||
this.setState({
|
this.setState({
|
||||||
topicInputFoused: true,
|
topicInputFocused: true,
|
||||||
});
|
});
|
||||||
}}
|
}}
|
||||||
onBlur={() => {
|
onBlur={() => {
|
||||||
this.onSubmit(false);
|
this.onSubmit(false);
|
||||||
this.setState({
|
this.setState({
|
||||||
topicInputFoused: false,
|
topicInputFocused: false,
|
||||||
|
editTopic: false,
|
||||||
});
|
});
|
||||||
}}
|
}}
|
||||||
onSubmitEditing={this.onSubmit}
|
onSubmitEditing={this.onSubmit}
|
||||||
style={[
|
style={[
|
||||||
styles.input,
|
styles.input,
|
||||||
{
|
{
|
||||||
borderColor: topicInputFoused
|
borderColor: topicInputFocused
|
||||||
? colors.accent
|
? colors.accent
|
||||||
: colors.nav,
|
: colors.nav,
|
||||||
color: colors.pri,
|
color: colors.pri,
|
||||||
@@ -393,20 +406,19 @@ export class AddNotebookDialog extends React.Component {
|
|||||||
style={[
|
style={[
|
||||||
styles.addBtn,
|
styles.addBtn,
|
||||||
{
|
{
|
||||||
borderColor: topicInputFoused
|
borderColor: topicInputFocused
|
||||||
? colors.accent
|
? colors.accent
|
||||||
: colors.nav,
|
: colors.nav,
|
||||||
},
|
},
|
||||||
]}>
|
]}>
|
||||||
<Icon
|
<Icon
|
||||||
name="plus"
|
name={this.state.editTopic ? 'check' : 'plus'}
|
||||||
size={SIZE.lg}
|
size={SIZE.lg}
|
||||||
color={topicInputFoused ? colors.accent : colors.icon}
|
color={topicInputFocused ? colors.accent : colors.icon}
|
||||||
/>
|
/>
|
||||||
</TouchableOpacity>
|
</TouchableOpacity>
|
||||||
</View>
|
</View>
|
||||||
|
|
||||||
|
|
||||||
<FlatList
|
<FlatList
|
||||||
data={topics}
|
data={topics}
|
||||||
ref={(ref) => (this.listRef = ref)}
|
ref={(ref) => (this.listRef = ref)}
|
||||||
@@ -415,7 +427,7 @@ export class AddNotebookDialog extends React.Component {
|
|||||||
<TopicItem
|
<TopicItem
|
||||||
item={item}
|
item={item}
|
||||||
onPress={(item, index) => {
|
onPress={(item, index) => {
|
||||||
console.log("here")
|
console.log('here');
|
||||||
this.prevIndex = index;
|
this.prevIndex = index;
|
||||||
this.prevItem = item;
|
this.prevItem = item;
|
||||||
this.topicInputRef.setNativeProps({
|
this.topicInputRef.setNativeProps({
|
||||||
@@ -423,6 +435,9 @@ export class AddNotebookDialog extends React.Component {
|
|||||||
});
|
});
|
||||||
this.topicInputRef.focus();
|
this.topicInputRef.focus();
|
||||||
this.currentInputValue = item;
|
this.currentInputValue = item;
|
||||||
|
this.setState({
|
||||||
|
editTopic: true,
|
||||||
|
});
|
||||||
}}
|
}}
|
||||||
onDelete={this.onDelete}
|
onDelete={this.onDelete}
|
||||||
index={index}
|
index={index}
|
||||||
@@ -447,7 +462,7 @@ export class AddNotebookDialog extends React.Component {
|
|||||||
</View>
|
</View>
|
||||||
</View>
|
</View>
|
||||||
</KeyboardAvoidingView>
|
</KeyboardAvoidingView>
|
||||||
<Toast context="local"/>
|
<Toast context="local" />
|
||||||
</SafeAreaView>
|
</SafeAreaView>
|
||||||
</Modal>
|
</Modal>
|
||||||
);
|
);
|
||||||
@@ -463,20 +478,32 @@ const TopicItem = ({item, index, colors, onPress, onDelete}) => {
|
|||||||
flexDirection: 'row',
|
flexDirection: 'row',
|
||||||
justifyContent: 'space-between',
|
justifyContent: 'space-between',
|
||||||
alignItems: 'center',
|
alignItems: 'center',
|
||||||
|
borderBottomWidth:1,
|
||||||
|
borderColor:colors.nav
|
||||||
}}>
|
}}>
|
||||||
<TouchableOpacity
|
<TouchableOpacity
|
||||||
|
|
||||||
style={{
|
style={{
|
||||||
width: '80%',
|
width: '80%',
|
||||||
backgroundColor: "transparent",
|
backgroundColor: 'transparent',
|
||||||
zIndex: 10,
|
zIndex: 10,
|
||||||
position: 'absolute',
|
position: 'absolute',
|
||||||
height: 30
|
height: 30,
|
||||||
|
|
||||||
}}
|
}}
|
||||||
onPress={() => {
|
onPress={() => {
|
||||||
onPress(item, index)
|
onPress(item, index);
|
||||||
}}
|
}}
|
||||||
/>
|
/>
|
||||||
|
<Text
|
||||||
|
style={{
|
||||||
|
fontFamily:WEIGHT.regular,
|
||||||
|
fontSize: SIZE.sm,
|
||||||
|
color:colors.primary,
|
||||||
|
marginRight:index === 0? 2 : 0
|
||||||
|
}}
|
||||||
|
>
|
||||||
|
{index + 1 + "."}
|
||||||
|
</Text>
|
||||||
<TextInput
|
<TextInput
|
||||||
ref={topicRef}
|
ref={topicRef}
|
||||||
editable={false}
|
editable={false}
|
||||||
@@ -484,27 +511,39 @@ const TopicItem = ({item, index, colors, onPress, onDelete}) => {
|
|||||||
styles.topicInput,
|
styles.topicInput,
|
||||||
{
|
{
|
||||||
color: colors.pri,
|
color: colors.pri,
|
||||||
|
|
||||||
borderBottomColor: colors.nav,
|
|
||||||
},
|
},
|
||||||
]}
|
]}
|
||||||
defaultValue={index + 1 + '. ' + item}
|
defaultValue={item}
|
||||||
placeholder="Add a topic"
|
|
||||||
placeholderTextColor={colors.icon}
|
placeholderTextColor={colors.icon}
|
||||||
/>
|
/>
|
||||||
|
|
||||||
<TouchableOpacity
|
<View
|
||||||
|
style={{
|
||||||
|
width:80,
|
||||||
|
position:"absolute",
|
||||||
|
right:0,
|
||||||
|
alignItems:"center",
|
||||||
|
flexDirection:"row",
|
||||||
|
justifyContent:'flex-end'
|
||||||
|
}}
|
||||||
|
>
|
||||||
|
<ActionIcon
|
||||||
|
onPress={() => {
|
||||||
|
onPress(item, index);
|
||||||
|
}}
|
||||||
|
name="pencil"
|
||||||
|
size={SIZE.lg - 5}
|
||||||
|
color={colors.icon}
|
||||||
|
/>
|
||||||
|
<ActionIcon
|
||||||
onPress={() => {
|
onPress={() => {
|
||||||
onDelete(index);
|
onDelete(index);
|
||||||
}}
|
}}
|
||||||
style={[
|
name="minus"
|
||||||
styles.topicBtn,
|
size={SIZE.lg}
|
||||||
{
|
color={colors.icon}
|
||||||
borderColor: colors.nav,
|
/>
|
||||||
},
|
</View>
|
||||||
]}>
|
|
||||||
<Icon name="minus" size={SIZE.lg} color={colors.icon}/>
|
|
||||||
</TouchableOpacity>
|
|
||||||
</View>
|
</View>
|
||||||
);
|
);
|
||||||
};
|
};
|
||||||
@@ -578,7 +617,6 @@ const styles = StyleSheet.create({
|
|||||||
fontSize: SIZE.sm,
|
fontSize: SIZE.sm,
|
||||||
fontFamily: WEIGHT.regular,
|
fontFamily: WEIGHT.regular,
|
||||||
paddingHorizontal: ph,
|
paddingHorizontal: ph,
|
||||||
borderBottomWidth: 1.5,
|
|
||||||
paddingRight: 40,
|
paddingRight: 40,
|
||||||
paddingVertical: 10,
|
paddingVertical: 10,
|
||||||
width: '100%',
|
width: '100%',
|
||||||
|
|||||||
Reference in New Issue
Block a user