import React, {useState} from 'react';
import {
ScrollView,
View,
Text,
TouchableOpacity,
Platform,
FlatList,
ActivityIndicator,
KeyboardAvoidingView,
StatusBar,
} from 'react-native';
import {
SIZE,
pv,
opacity,
WEIGHT,
COLOR_SCHEME_DARK,
COLOR_SCHEME_LIGHT,
} from '../../common/common';
import Icon from 'react-native-vector-icons/Feather';
import {h} from '../../utils/utils';
import FastStorage from 'react-native-fast-storage';
import {AnimatedSafeAreaView} from '../../views/Home';
import {TextInput} from 'react-native-gesture-handler';
import {useAppContext} from '../../provider/useAppContext';
import {VaultDialog} from '../VaultDialog';
let tagsInputRef;
let tagsList;
export const EditorMenu = ({
close = () => {},
hide,
update = () => {},
updateProps = () => {},
noteProps,
note,
timestamp,
}) => {
const {colors, changeColorScheme} = useAppContext();
// Todo
///////
const [unlock, setUnlock] = useState(false);
const [vaultDialog, setVaultDialog] = useState(false);
const [focused, setFocused] = useState(false);
let tagToAdd = null;
let backPressCount = 0;
_renderListItem = ({item, index}) => (
{
item.func();
}}
style={{
width: '100%',
alignSelf: 'center',
flexDirection: 'row',
justifyContent: 'space-between',
alignItems: 'flex-end',
paddingHorizontal: 12,
paddingVertical: pv + 5,
paddingTop: index === 0 ? 5 : pv + 5,
}}>
{item.name}
{item.switch ? (
) : (
undefined
)}
{item.check ? (
{item.on ? (
) : null}
) : null}
);
_renderTag = item => (
{item}
);
_renderColor = item => (
{
let props = {...noteProps};
if (props.colors.includes(item)) {
props.colors.splice(props.colors.indexOf(item), 1);
} else {
props.colors.push(item);
}
updateProps(props);
}}
style={{
flexDirection: 'row',
justifyContent: 'flex-start',
alignItems: 'center',
marginRight: 5,
marginBottom: 5,
borderWidth: 1.5,
borderRadius: 100,
padding: 3,
borderColor: noteProps.colors.includes(item)
? colors.pri
: colors.shade,
}}>
{noteProps.colors.includes(item) ? (
) : null}
);
_onSubmit = () => {
if (!tagToAdd || tagToAdd === '#') return;
let tag = tagToAdd;
if (tag[0] !== '#') {
tag = '#' + tag;
}
if (tag.includes(' ')) {
tag = tag.replace(' ', '_');
}
let oldProps = {...noteProps};
oldProps.tags.push(tag);
tagsInputRef.setNativeProps({
text: '#',
});
updateProps(oldProps);
tagToAdd = '';
setTimeout(() => {
tagsInputRef.focus();
}, 300);
};
_onKeyPress = event => {
if (event.nativeEvent.key === 'Backspace') {
if (backPressCount === 0 && !tagToAdd) {
backPressCount = 1;
return;
}
if (backPressCount === 1 && !tagToAdd) {
backPressCount = 0;
let tagInputValue = noteProps.tags[noteProps.tags.length - 1];
let oldProps = {...noteProps};
if (allTags.length === 1) return;
oldProps.tags.splice(allTags.length - 1);
updateProps(oldProps);
tagsInputRef.setNativeProps({
text: tagInputValue,
});
setTimeout(() => {
tagsInputRef.focus();
}, 300);
}
}
};
return (
Properties
{
if (!colors.night) {
FastStorage.setItem(
'theme',
JSON.stringify(COLOR_SCHEME_DARK),
);
changeColorScheme(COLOR_SCHEME_DARK);
} else {
FastStorage.setItem(
'theme',
JSON.stringify(COLOR_SCHEME_LIGHT),
);
changeColorScheme(COLOR_SCHEME_LIGHT);
}
},
switch: true,
on: colors.night ? true : false,
close: false,
},
{
name: 'Pinned',
icon: 'tag',
func: () => {
let props = {...noteProps};
props.pinned = !noteProps.pinned;
updateProps(props);
},
close: false,
check: true,
on: noteProps.pinned,
},
{
name: 'Add to Favorites',
icon: 'star',
func: () => {
let props = {...noteProps};
props.favorite = !noteProps.favorite;
updateProps(props);
},
close: false,
check: true,
on: noteProps.favorite,
},
{
name: 'Share ',
icon: 'share',
func: () => {},
close: true,
},
{
name: 'Move to Notebook',
icon: 'arrow-right',
func: () => {},
close: true,
},
{
name: 'Export',
icon: 'external-link',
func: () => {},
close: true,
},
{
name: 'Delete Note',
icon: 'trash',
func: () => {},
close: true,
},
{
name: noteProps.locked ? 'Remove from Vault' : 'Add to Vault',
icon: 'lock',
func: () => {
if (noteProps.locked) {
setUnlock(true);
} else {
setUnlock(false);
}
setVaultDialog(true);
},
close: true,
check: true,
on: noteProps.locked,
},
]}
keyExtractor={(item, index) => item.name}
renderItem={_renderListItem}
/>
Add Tags
(tagsList = ref)}
contentContainerStyle={{
flexDirection: 'row',
flexWrap: 'wrap',
marginHorizontal: '5%',
marginBottom: 0,
marginTop: 10,
borderRadius: 5,
backgroundColor: colors.nav,
borderWidth: 1.5,
borderColor: focused ? colors.accent : 'transparent',
}}>
{noteProps.tags.map(_renderTag)}
(tagsInputRef = ref)}
placeholderTextColor={colors.icon}
onFocus={() => {
setFocused(true);
}}
selectionColor={colors.accent}
selectTextOnFocus={true}
onBlur={() => {
setFocused(false);
}}
placeholder="#hashtag"
onChangeText={value => {
tagToAdd = value;
if (tagToAdd.length > 0) backPressCount = 0;
}}
onKeyPress={_onKeyPress}
onSubmitEditing={_onSubmit}
/>
Assign Colors
{[
'red',
'yellow',
'green',
'blue',
'purple',
'orange',
'gray',
].map(_renderColor)}
Last Synced: 5 secs ago.
{}
{
if (item) {
update(item);
}
let props = {...noteProps};
props.locked = locked;
updateProps(props);
setVaultDialog(false);
setUnlock(false);
}}
note={note}
timestamp={timestamp}
perm={true}
openedToUnlock={unlock}
visible={vaultDialog}
/>
);
};