mirror of
https://github.com/streetwriters/notesnook.git
synced 2025-12-23 23:19:40 +01:00
minor improvements
This commit is contained in:
@@ -7,11 +7,8 @@ import {
|
|||||||
View,
|
View,
|
||||||
DeviceEventEmitter,
|
DeviceEventEmitter,
|
||||||
Platform,
|
Platform,
|
||||||
Keyboard,
|
|
||||||
Animated,
|
Animated,
|
||||||
} from 'react-native';
|
} from 'react-native';
|
||||||
import Icon from 'react-native-vector-icons/Ionicons';
|
|
||||||
import ActionButton from 'react-native-action-button';
|
|
||||||
import * as Animatable from 'react-native-animatable';
|
import * as Animatable from 'react-native-animatable';
|
||||||
import {h, w} from './src/utils/utils';
|
import {h, w} from './src/utils/utils';
|
||||||
import {Toast} from './src/components/Toast';
|
import {Toast} from './src/components/Toast';
|
||||||
@@ -22,6 +19,7 @@ import StorageInterface from './src/utils/storage';
|
|||||||
import {AppProvider} from './src/provider';
|
import {AppProvider} from './src/provider';
|
||||||
import {DeviceDetectionService} from './src/utils/deviceDetection';
|
import {DeviceDetectionService} from './src/utils/deviceDetection';
|
||||||
import {useAppContext} from './src/provider/useAppContext';
|
import {useAppContext} from './src/provider/useAppContext';
|
||||||
|
|
||||||
export const DDS = new DeviceDetectionService();
|
export const DDS = new DeviceDetectionService();
|
||||||
|
|
||||||
export const db = new Storage(StorageInterface);
|
export const db = new Storage(StorageInterface);
|
||||||
|
|||||||
@@ -1,32 +1,17 @@
|
|||||||
import React, {useEffect, useState, createRef} from 'react';
|
import React, {useState, createRef} from 'react';
|
||||||
import {
|
import {
|
||||||
ScrollView,
|
|
||||||
View,
|
View,
|
||||||
Text,
|
Text,
|
||||||
TouchableOpacity,
|
TouchableOpacity,
|
||||||
Dimensions,
|
|
||||||
Image,
|
|
||||||
SafeAreaView,
|
|
||||||
Platform,
|
Platform,
|
||||||
Modal,
|
Modal,
|
||||||
KeyboardAvoidingView,
|
KeyboardAvoidingView,
|
||||||
} from 'react-native';
|
} from 'react-native';
|
||||||
import NavigationService from '../../services/NavigationService';
|
import {SIZE, ph, pv, opacity, WEIGHT} from '../../common/common';
|
||||||
import {
|
|
||||||
COLOR_SCHEME,
|
|
||||||
SIZE,
|
|
||||||
br,
|
|
||||||
ph,
|
|
||||||
pv,
|
|
||||||
opacity,
|
|
||||||
FONT,
|
|
||||||
WEIGHT,
|
|
||||||
} from '../../common/common';
|
|
||||||
import Icon from 'react-native-vector-icons/Feather';
|
import Icon from 'react-native-vector-icons/Feather';
|
||||||
|
|
||||||
import {getElevation, h, w, timeSince, ToastEvent} from '../../utils/utils';
|
import {getElevation, ToastEvent} from '../../utils/utils';
|
||||||
import {FlatList, TextInput} from 'react-native-gesture-handler';
|
import {FlatList, TextInput} from 'react-native-gesture-handler';
|
||||||
import {useForceUpdate} from '../../views/ListsEditor';
|
|
||||||
import {db, DDS} from '../../../App';
|
import {db, DDS} from '../../../App';
|
||||||
import {useAppContext} from '../../provider/useAppContext';
|
import {useAppContext} from '../../provider/useAppContext';
|
||||||
|
|
||||||
@@ -36,28 +21,30 @@ export const AddNotebookDialog = ({visible, close}) => {
|
|||||||
const {colors} = useAppContext();
|
const {colors} = useAppContext();
|
||||||
const [topics, setTopics] = useState(['']);
|
const [topics, setTopics] = useState(['']);
|
||||||
const [title, setTitle] = useState(null);
|
const [title, setTitle] = useState(null);
|
||||||
const forceUpdate = useForceUpdate();
|
|
||||||
|
|
||||||
let listRef = createRef();
|
let listRef = createRef();
|
||||||
let prevItem = null;
|
let prevItem = null;
|
||||||
let prevIndex = null;
|
let prevIndex = null;
|
||||||
let currentSelectedItem = null;
|
let currentSelectedInput = null;
|
||||||
|
|
||||||
let description = 'my first notebook';
|
let description = 'my first notebook';
|
||||||
const onSubmit = (text, index, willFocus = true) => {
|
const onSubmit = (text, index, willFocus = true) => {
|
||||||
let oldData = topics;
|
let prevTopics = topics;
|
||||||
oldData[index] = text;
|
prevTopics[index] = text;
|
||||||
|
|
||||||
if (
|
if (
|
||||||
oldData.length === index + 1 &&
|
prevTopics.length === index + 1 &&
|
||||||
prevIndex !== null &&
|
prevIndex !== null &&
|
||||||
prevItem !== null
|
prevItem !== null
|
||||||
) {
|
) {
|
||||||
oldData.push('');
|
prevTopics.push('');
|
||||||
}
|
}
|
||||||
setTopics(oldData);
|
|
||||||
forceUpdate();
|
let nextTopics = [...prevTopics];
|
||||||
currentSelectedItem = null;
|
|
||||||
|
setTopics(nextTopics);
|
||||||
|
|
||||||
|
currentSelectedInput = null;
|
||||||
|
|
||||||
//if (!willFocus) return;
|
//if (!willFocus) return;
|
||||||
if (!refs[index + 1]) {
|
if (!refs[index + 1]) {
|
||||||
@@ -73,31 +60,39 @@ export const AddNotebookDialog = ({visible, close}) => {
|
|||||||
}
|
}
|
||||||
};
|
};
|
||||||
const onFocus = index => {
|
const onFocus = index => {
|
||||||
currentSelectedItem = index;
|
currentSelectedInput = index;
|
||||||
if (currentSelectedItem) {
|
|
||||||
let oldData = topics;
|
if (currentSelectedInput) {
|
||||||
oldData[prevIndex] = prevItem;
|
let prevTopics = topics;
|
||||||
if (oldData.length === prevIndex + 1) {
|
|
||||||
oldData.push('');
|
prevTopics[prevIndex] = prevItem;
|
||||||
|
if (prevTopics.length === prevIndex + 1) {
|
||||||
|
prevTopics.push('');
|
||||||
}
|
}
|
||||||
prevIndex = null;
|
prevIndex = null;
|
||||||
prevItem = null;
|
prevItem = null;
|
||||||
setTopics(oldData);
|
|
||||||
forceUpdate();
|
let nextTopics = [...prevTopics];
|
||||||
|
|
||||||
|
setTopics(nextTopics);
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
const onChange = (text, index) => {
|
const onChange = (text, index) => {
|
||||||
prevIndex = index;
|
prevIndex = index;
|
||||||
prevItem = text;
|
prevItem = text;
|
||||||
};
|
};
|
||||||
const onDelete = index => {
|
|
||||||
let listData = topics;
|
|
||||||
if (listData.length === 1) return;
|
|
||||||
refs.splice(index, 1);
|
|
||||||
listData.splice(index, 1);
|
|
||||||
|
|
||||||
setTopics(listData);
|
const onDelete = index => {
|
||||||
forceUpdate();
|
let prevTopics = topics;
|
||||||
|
|
||||||
|
if (prevTopics.length === 1) return;
|
||||||
|
|
||||||
|
refs = [];
|
||||||
|
prevTopics.splice(index, 1);
|
||||||
|
|
||||||
|
let nextTopics = [...prevTopics];
|
||||||
|
|
||||||
|
setTopics(nextTopics);
|
||||||
};
|
};
|
||||||
|
|
||||||
const addNewNotebook = async () => {
|
const addNewNotebook = async () => {
|
||||||
@@ -113,7 +108,7 @@ export const AddNotebookDialog = ({visible, close}) => {
|
|||||||
setTopics(['']);
|
setTopics(['']);
|
||||||
prevIndex = null;
|
prevIndex = null;
|
||||||
prevItem = null;
|
prevItem = null;
|
||||||
currentSelectedItem = null;
|
currentSelectedInput = null;
|
||||||
refs = [];
|
refs = [];
|
||||||
close(true);
|
close(true);
|
||||||
};
|
};
|
||||||
@@ -252,10 +247,12 @@ export const AddNotebookDialog = ({visible, close}) => {
|
|||||||
activeOpacity={opacity}
|
activeOpacity={opacity}
|
||||||
onPress={() => {
|
onPress={() => {
|
||||||
setTopics(['']);
|
setTopics(['']);
|
||||||
|
|
||||||
|
refs = [];
|
||||||
prevIndex = null;
|
prevIndex = null;
|
||||||
prevItem = null;
|
prevItem = null;
|
||||||
currentSelectedItem = null;
|
currentSelectedInput = null;
|
||||||
refs = [];
|
|
||||||
close();
|
close();
|
||||||
}}
|
}}
|
||||||
style={{
|
style={{
|
||||||
@@ -313,7 +310,6 @@ const TopicItem = ({
|
|||||||
ref={topicRef}
|
ref={topicRef}
|
||||||
onFocus={() => {
|
onFocus={() => {
|
||||||
onFocus(index);
|
onFocus(index);
|
||||||
|
|
||||||
setFocus(true);
|
setFocus(true);
|
||||||
}}
|
}}
|
||||||
onBlur={() => {
|
onBlur={() => {
|
||||||
|
|||||||
@@ -126,7 +126,7 @@ export const NotebookItem = ({
|
|||||||
numberOfLines={1}
|
numberOfLines={1}
|
||||||
style={{
|
style={{
|
||||||
fontFamily: WEIGHT.bold,
|
fontFamily: WEIGHT.bold,
|
||||||
fontSize: SIZE.sm,
|
fontSize: SIZE.md,
|
||||||
color: colors.pri,
|
color: colors.pri,
|
||||||
maxWidth: '100%',
|
maxWidth: '100%',
|
||||||
}}>
|
}}>
|
||||||
@@ -137,9 +137,9 @@ export const NotebookItem = ({
|
|||||||
numberOfLines={numColumns === 2 ? 3 : 2}
|
numberOfLines={numColumns === 2 ? 3 : 2}
|
||||||
style={{
|
style={{
|
||||||
fontFamily: WEIGHT.regular,
|
fontFamily: WEIGHT.regular,
|
||||||
fontSize: SIZE.xs,
|
fontSize: SIZE.xs + 1,
|
||||||
lineHeight: SIZE.sm,
|
lineHeight: SIZE.sm,
|
||||||
color: colors.icon,
|
color: colors.pri,
|
||||||
maxWidth: '100%',
|
maxWidth: '100%',
|
||||||
paddingVertical: 5,
|
paddingVertical: 5,
|
||||||
height: numColumns === 2 ? SIZE.sm * 3.5 : null,
|
height: numColumns === 2 ? SIZE.sm * 3.5 : null,
|
||||||
|
|||||||
@@ -33,12 +33,13 @@ let titleRef;
|
|||||||
let EditorWebView;
|
let EditorWebView;
|
||||||
|
|
||||||
const Editor = ({navigation}) => {
|
const Editor = ({navigation}) => {
|
||||||
// STATE
|
// Global State
|
||||||
|
|
||||||
const {colors} = useAppContext();
|
const {colors} = useAppContext();
|
||||||
|
|
||||||
|
// Local State
|
||||||
|
|
||||||
const [dialog, setDialog] = useState(false);
|
const [dialog, setDialog] = useState(false);
|
||||||
const [isOpen, setOpen] = useState(false);
|
const [isOpen, setOpen] = useState(false);
|
||||||
const [hide, setHide] = useState(true);
|
|
||||||
const [sidebar, setSidebar] = useState(DDS.isTab ? true : false);
|
const [sidebar, setSidebar] = useState(DDS.isTab ? true : false);
|
||||||
// VARIABLES
|
// VARIABLES
|
||||||
let updateInterval = null;
|
let updateInterval = null;
|
||||||
@@ -227,7 +228,6 @@ const Editor = ({navigation}) => {
|
|||||||
title = null;
|
title = null;
|
||||||
timestamp = null;
|
timestamp = null;
|
||||||
content = null;
|
content = null;
|
||||||
|
|
||||||
handleBack.remove();
|
handleBack.remove();
|
||||||
handleBack = null;
|
handleBack = null;
|
||||||
};
|
};
|
||||||
@@ -245,26 +245,15 @@ const Editor = ({navigation}) => {
|
|||||||
}, []);
|
}, []);
|
||||||
|
|
||||||
useEffect(() => {
|
useEffect(() => {
|
||||||
DeviceEventEmitter.emit('hide');
|
|
||||||
|
|
||||||
return () => {
|
|
||||||
DeviceEventEmitter.emit('show');
|
|
||||||
};
|
|
||||||
}, []);
|
|
||||||
|
|
||||||
useEffect(() => {
|
|
||||||
null;
|
|
||||||
|
|
||||||
return () => {
|
return () => {
|
||||||
DDS.isTab ? SideMenuEvent.open() : null;
|
DDS.isTab ? SideMenuEvent.open() : null;
|
||||||
|
|
||||||
SideMenuEvent.enable();
|
SideMenuEvent.enable();
|
||||||
};
|
};
|
||||||
});
|
});
|
||||||
|
|
||||||
useEffect(() => {
|
useEffect(() => {
|
||||||
EditorWebView.reload();
|
EditorWebView.reload();
|
||||||
}, [colors.bg]);
|
}, [colors]);
|
||||||
|
|
||||||
return DDS.isTab ? (
|
return DDS.isTab ? (
|
||||||
<View
|
<View
|
||||||
|
|||||||
@@ -158,51 +158,9 @@ export const Folders = ({navigation}) => {
|
|||||||
ListHeaderComponent={
|
ListHeaderComponent={
|
||||||
<View
|
<View
|
||||||
style={{
|
style={{
|
||||||
marginTop: margin + 20,
|
marginTop: margin,
|
||||||
flexDirection: 'row',
|
}}
|
||||||
justifyContent: 'space-between',
|
/>
|
||||||
width:
|
|
||||||
numColumns === 2
|
|
||||||
? DDS.isTab
|
|
||||||
? w * 0.7 * 0.95
|
|
||||||
: w * 0.95
|
|
||||||
: w * 0.95,
|
|
||||||
|
|
||||||
alignSelf: 'center',
|
|
||||||
marginLeft:
|
|
||||||
numColumns === 2 ? (DDS.isTab ? w * 0.7 * 0.025 : 0) : 0,
|
|
||||||
paddingHorizontal: ph + 5,
|
|
||||||
}}>
|
|
||||||
<View>
|
|
||||||
<Text
|
|
||||||
transition="marginTop"
|
|
||||||
delay={200}
|
|
||||||
duration={200}
|
|
||||||
style={{
|
|
||||||
fontSize: SIZE.lg,
|
|
||||||
fontFamily: WEIGHT.medium,
|
|
||||||
color: colors.pri,
|
|
||||||
paddingHorizontal: DDS.isTab ? '2.5%' : '5%',
|
|
||||||
maxWidth: '100%',
|
|
||||||
}}>
|
|
||||||
<Text
|
|
||||||
style={{
|
|
||||||
color: colors.accent,
|
|
||||||
}}></Text>
|
|
||||||
</Text>
|
|
||||||
</View>
|
|
||||||
|
|
||||||
<TouchableOpacity
|
|
||||||
onPress={() => {
|
|
||||||
setNumColumns(numColumns === 1 ? 2 : 1);
|
|
||||||
}}
|
|
||||||
style={{
|
|
||||||
justifyContent: 'center',
|
|
||||||
alignItems: 'center',
|
|
||||||
}}>
|
|
||||||
<Icon name="list" size={SIZE.xl} color={colors.icon} />
|
|
||||||
</TouchableOpacity>
|
|
||||||
</View>
|
|
||||||
}
|
}
|
||||||
numColumns={numColumns}
|
numColumns={numColumns}
|
||||||
key={numColumns}
|
key={numColumns}
|
||||||
|
|||||||
Reference in New Issue
Block a user