Files
notesnook/apps/mobile/src/components/ActionSheetComponent/index.js

858 lines
22 KiB
JavaScript
Raw Normal View History

import React, {useEffect, useState, createRef} from 'react';
2020-01-09 20:14:51 +05:00
import {
Dimensions,
2020-01-18 18:13:34 +05:00
StatusBar,
2020-01-18 01:04:33 +05:00
Text,
2020-01-09 20:14:51 +05:00
TextInput,
2020-01-18 01:04:33 +05:00
TouchableOpacity,
View,
2020-02-22 13:02:16 +05:00
Platform,
2020-03-04 09:51:13 +05:00
ToastAndroid,
2020-01-09 20:14:51 +05:00
} from 'react-native';
2020-03-10 13:36:33 +05:00
import MMKV from 'react-native-mmkv-storage';
2020-02-11 20:33:36 +05:00
import Icon from 'react-native-vector-icons/MaterialCommunityIcons';
2020-01-22 02:49:29 +05:00
import {db, DDS} from '../../../App';
2020-01-10 18:44:41 +05:00
import {
2020-01-18 01:04:33 +05:00
ACCENT,
COLOR_SCHEME,
2020-01-10 18:44:41 +05:00
COLOR_SCHEME_DARK,
COLOR_SCHEME_LIGHT,
2020-01-18 01:04:33 +05:00
opacity,
pv,
2020-01-18 18:13:34 +05:00
setColorScheme,
2020-01-18 01:04:33 +05:00
SIZE,
WEIGHT,
2020-02-03 12:21:38 +05:00
ph,
2020-01-10 18:44:41 +05:00
} from '../../common/common';
2020-01-24 23:13:09 +05:00
import {useTracked} from '../../provider';
import {ACTIONS} from '../../provider/actions';
2020-01-25 23:24:01 +05:00
import {moveNoteEvent} from '../DialogManager';
2020-01-29 17:38:50 +05:00
import Share from 'react-native-share';
2020-02-22 13:02:16 +05:00
import {timeConverter, ToastEvent, hexToRGBA} from '../../utils/utils';
2020-02-20 20:02:37 +05:00
import NavigationService from '../../services/NavigationService';
2020-03-10 23:19:16 +05:00
import {eSendEvent} from '../../services/eventManager';
import {eOpenVaultDialog} from '../../services/events';
import {openVault} from '../VaultDialog';
2020-01-09 20:14:51 +05:00
const w = Dimensions.get('window').width;
const h = Dimensions.get('window').height;
const tagsInputRef = createRef();
2020-01-09 20:14:51 +05:00
export const ActionSheetComponent = ({
close = () => {},
2020-01-11 23:05:39 +05:00
item,
2020-01-10 18:44:41 +05:00
hasColors = false,
hasTags = false,
rowItems = [],
columnItems = [],
2020-01-09 20:14:51 +05:00
}) => {
2020-01-17 21:26:01 +05:00
const [state, dispatch] = useTracked();
const {colors, tags, currentEditingNote} = state;
2020-01-09 20:14:51 +05:00
const [focused, setFocused] = useState(false);
2020-01-15 20:20:53 +05:00
const [note, setNote] = useState(
item
? item
: {
colors: [],
tags: [],
pinned: false,
favorite: false,
locked: false,
content: {
2020-01-29 18:20:54 +05:00
text: null,
delta: null,
2020-01-15 20:20:53 +05:00
},
dateCreated: null,
},
);
2020-01-09 20:14:51 +05:00
2020-01-22 02:49:29 +05:00
function changeColorScheme(colors = COLOR_SCHEME, accent = ACCENT) {
let newColors = setColorScheme(colors, accent);
2020-02-22 20:00:57 +05:00
StatusBar.setBarStyle(colors.night ? 'light-content' : 'dark-content');
2020-01-22 02:49:29 +05:00
dispatch({type: ACTIONS.THEME, colors: newColors});
}
2020-01-11 23:05:39 +05:00
useEffect(() => {
2020-01-14 17:33:48 +05:00
if (item.dateCreated !== null) {
setNote({...item});
}
2020-01-11 23:05:39 +05:00
}, [item]);
2020-01-09 20:14:51 +05:00
let tagToAdd = null;
let backPressCount = 0;
2020-02-02 14:24:24 +05:00
const _onSubmit = async () => {
if (!tagToAdd || tagToAdd === '' || tagToAdd.trimStart().length == 0) {
ToastEvent.show('Empty Tag', 'success');
return;
}
2020-01-09 20:14:51 +05:00
let tag = tagToAdd;
2020-02-02 14:24:24 +05:00
2020-01-09 20:14:51 +05:00
if (tag.includes(' ')) {
tag = tag.replace(' ', '_');
}
tagsInputRef.current?.setNativeProps({
2020-02-02 14:24:24 +05:00
text: '',
2020-01-09 20:14:51 +05:00
});
2020-02-02 14:24:24 +05:00
2020-02-06 13:08:35 +05:00
await db.notes.note(note.id).tag(tag);
setNote({...db.notes.note(note.id).data});
2020-03-04 09:51:13 +05:00
dispatch({type: ACTIONS.TAGS});
2020-01-09 20:14:51 +05:00
tagToAdd = '';
};
2020-02-02 14:24:24 +05:00
const _onKeyPress = async event => {
2020-01-09 20:14:51 +05:00
if (event.nativeEvent.key === 'Backspace') {
if (backPressCount === 0 && !tagToAdd) {
backPressCount = 1;
return;
}
if (backPressCount === 1 && !tagToAdd) {
backPressCount = 0;
let tagInputValue = note.tags[note.tags.length - 1];
let oldProps = {...note};
2020-02-02 14:24:24 +05:00
if (oldProps.tags.length === 0) return;
2020-02-06 14:17:28 +05:00
2020-02-06 13:08:35 +05:00
await db.notes
.note(note.id)
.untag(oldProps.tags[oldProps.tags.length - 1]);
2020-01-09 20:14:51 +05:00
2020-02-06 13:08:35 +05:00
setNote({...db.notes.note(note.id).data});
2020-01-09 20:14:51 +05:00
tagsInputRef.current?.setNativeProps({
2020-01-09 20:14:51 +05:00
text: tagInputValue,
});
}
} else if (event.nativeEvent.key === ' ') {
_onSubmit();
tagsInputRef.current?.setNativeProps({
text: '',
});
2020-03-04 09:51:13 +05:00
} else if (event.nativeEvent.key === ',') {
_onSubmit();
tagsInputRef.current?.setNativeProps({
text: '',
});
2020-01-09 20:14:51 +05:00
}
};
2020-01-20 10:33:36 +05:00
const localRefresh = (type, nodispatch = false) => {
2020-02-06 13:08:35 +05:00
if (!note || !note.id) return;
2020-01-10 18:44:41 +05:00
let toAdd;
2020-02-02 23:50:55 +05:00
2020-01-10 18:44:41 +05:00
switch (type) {
case 'note': {
2020-02-07 04:25:55 +05:00
toAdd = db.notes.note(note.id);
if (toAdd) {
toAdd = toAdd.data;
} else {
setTimeout(() => {
toAdd = db.notes.note(note.id);
if (toAdd) {
toAdd = toAdd.data;
}
}, 500);
}
2020-01-10 18:44:41 +05:00
break;
}
case 'notebook': {
2020-02-07 04:25:55 +05:00
toAdd = db.notebooks.notebook(note.id);
if (toAdd) {
toAdd = toAdd.data;
} else {
setTimeout(() => {
toAdd = db.notebooks.notebook(note.id);
if (toAdd) {
toAdd = toAdd.data;
}
}, 500);
}
2020-01-10 18:44:41 +05:00
break;
}
case 'topic': {
2020-02-06 13:08:35 +05:00
toAdd = db.notebooks.notebook(note.notebookId).topics.topic(note.title);
2020-02-02 23:50:55 +05:00
2020-01-10 18:44:41 +05:00
break;
}
}
2020-02-06 13:08:35 +05:00
if (!toAdd || !toAdd.id) return;
2020-01-20 15:32:32 +05:00
2020-01-20 10:33:36 +05:00
if (!nodispatch) {
dispatch({type: type});
2020-02-01 12:56:30 +05:00
dispatch({type: ACTIONS.PINNED});
dispatch({type: ACTIONS.FAVORITES});
2020-01-20 10:33:36 +05:00
}
2020-01-10 18:44:41 +05:00
setNote({...toAdd});
};
const rowItemsData = [
{
name: 'Add to',
2020-02-11 20:33:36 +05:00
icon: 'book-outline',
2020-01-10 18:44:41 +05:00
func: () => {
2020-01-18 18:13:34 +05:00
dispatch({type: ACTIONS.MODAL_NAVIGATOR, enabled: true});
dispatch({type: ACTIONS.SELECTED_ITEMS, item: note});
2020-02-22 20:00:57 +05:00
close('movenote');
2020-01-10 18:44:41 +05:00
},
},
{
name: 'Share',
2020-02-12 03:24:36 +05:00
icon: 'share-variant',
2020-01-10 18:44:41 +05:00
func: () => {
2020-01-29 17:38:50 +05:00
if (note.locked) {
2020-03-10 23:19:16 +05:00
openVault(item, false, true, false, false, true);
2020-01-29 17:38:50 +05:00
} else {
close();
let m = `${note.title}\n \n ${note.content.text}`;
Share.open({
title: 'Share note to',
failOnCancel: false,
message: m,
});
}
2020-01-10 18:44:41 +05:00
},
},
{
name: 'Export',
2020-02-12 03:24:36 +05:00
icon: 'export',
2020-01-10 18:44:41 +05:00
func: () => {
close();
},
},
{
name: 'Delete',
2020-02-11 20:33:36 +05:00
icon: 'delete',
2020-01-10 18:44:41 +05:00
func: () => close('delete'),
},
{
name: 'Edit Notebook',
2020-02-11 20:33:36 +05:00
icon: 'square-edit-outline',
2020-01-10 18:44:41 +05:00
func: () => {
2020-01-18 18:13:34 +05:00
close('notebook');
2020-01-10 18:44:41 +05:00
},
},
{
name: 'Edit Topic',
2020-02-11 20:33:36 +05:00
icon: 'square-edit-outline',
2020-01-10 18:44:41 +05:00
func: () => {
close('topic');
},
},
2020-02-03 12:18:45 +05:00
{
name: 'Open',
2020-02-11 20:33:36 +05:00
icon: 'open-in-app',
2020-02-20 20:02:37 +05:00
func: () => {
NavigationService.navigate('Editor', {
note: item,
});
close();
},
2020-02-03 12:18:45 +05:00
},
2020-01-10 18:44:41 +05:00
{
name: 'Restore',
2020-02-11 20:33:36 +05:00
icon: 'delete-restore',
2020-02-07 04:25:55 +05:00
func: async () => {
await db.trash.restore(note.id);
dispatch({type: ACTIONS.TRASH});
localRefresh(note.type);
2020-01-10 18:44:41 +05:00
ToastEvent.show(
2020-01-19 21:31:26 +05:00
item.type === 'note' ? 'Note restored' : 'Notebook restored',
2020-01-10 18:44:41 +05:00
'success',
1000,
() => {},
'',
);
close();
},
},
{
name: 'Remove',
2020-02-11 20:33:36 +05:00
icon: 'delete',
2020-01-10 18:44:41 +05:00
func: () => {
2020-03-04 11:58:44 +05:00
close('permanant_delete');
2020-01-10 18:44:41 +05:00
},
},
];
2020-01-29 17:38:50 +05:00
const columnItemsData = [
2020-01-10 18:44:41 +05:00
{
name: 'Dark Mode',
2020-02-11 20:33:36 +05:00
icon: 'theme-light-dark',
2020-01-10 18:44:41 +05:00
func: () => {
if (!colors.night) {
2020-03-10 13:36:33 +05:00
MMKV.setString('theme', JSON.stringify({night: true}));
2020-01-10 18:44:41 +05:00
changeColorScheme(COLOR_SCHEME_DARK);
} else {
2020-03-10 13:36:33 +05:00
MMKV.setString('theme', JSON.stringify({night: false}));
2020-01-10 18:44:41 +05:00
changeColorScheme(COLOR_SCHEME_LIGHT);
}
},
switch: true,
on: colors.night ? true : false,
close: false,
},
{
name: 'Pin',
2020-02-11 20:33:36 +05:00
icon: 'tag-outline',
2020-02-01 12:56:30 +05:00
func: async () => {
2020-02-06 13:08:35 +05:00
if (!note.id) return;
2020-02-02 16:18:52 +05:00
if (note.type === 'note') {
2020-02-06 13:08:35 +05:00
await db.notes.note(note.id).pin();
2020-02-02 16:18:52 +05:00
} else {
2020-02-06 13:08:35 +05:00
await db.notebooks.notebook(note.id).pin();
2020-02-02 16:18:52 +05:00
}
2020-01-18 00:45:37 +05:00
dispatch({type: ACTIONS.PINNED});
2020-02-02 16:18:52 +05:00
localRefresh(item.type);
2020-01-10 18:44:41 +05:00
},
close: false,
check: true,
on: note.pinned,
},
{
name: 'Favorite',
icon: 'star',
2020-02-01 12:56:30 +05:00
func: async () => {
2020-02-06 13:08:35 +05:00
if (!note.id) return;
2020-02-02 16:18:52 +05:00
if (note.type === 'note') {
2020-02-06 13:08:35 +05:00
await db.notes.note(note.id).favorite();
2020-02-02 16:18:52 +05:00
} else {
2020-02-06 13:08:35 +05:00
await db.notebooks.notebook(note.id).favorite();
2020-02-02 16:18:52 +05:00
}
2020-02-01 12:56:30 +05:00
dispatch({type: ACTIONS.FAVORITES});
2020-02-02 16:18:52 +05:00
localRefresh(item.type);
2020-01-10 18:44:41 +05:00
},
close: false,
check: true,
on: note.favorite,
},
{
name: 'Add to Vault',
2020-02-11 20:33:36 +05:00
icon: 'shield',
2020-01-10 18:44:41 +05:00
func: () => {
2020-02-06 13:08:35 +05:00
if (!note.id) return;
2020-03-10 23:19:16 +05:00
if (note.locked) {
close();
2020-03-14 12:13:00 +05:00
openVault(note, true, true, true, false, false);
2020-03-10 23:19:16 +05:00
return;
} else {
db.vault
.add(note.id)
.then(() => {
close();
})
.catch(async e => {
switch (e.message) {
case db.vault.ERRORS.noVault:
close();
openVault(note, false);
break;
case db.vault.ERRORS.vaultLocked:
openVault(note, true, true);
break;
case db.vault.ERRORS.wrongPassword:
break;
}
});
}
2020-01-10 18:44:41 +05:00
},
close: true,
check: true,
on: note.locked,
},
];
2020-01-16 19:53:16 +05:00
const _renderTag = tag => (
<TouchableOpacity
key={tag}
2020-02-02 14:24:24 +05:00
onPress={async () => {
2020-01-16 19:53:16 +05:00
let oldProps = {...note};
try {
await db.notes
.note(note.id)
.untag(oldProps.tags[oldProps.tags.indexOf(tag)]);
localRefresh(oldProps.type);
} catch (e) {
localRefresh(oldProps.type);
}
2020-01-16 19:53:16 +05:00
}}
style={{
flexDirection: 'row',
justifyContent: 'flex-start',
alignItems: 'center',
margin: 1,
paddingHorizontal: 5,
paddingVertical: 2.5,
}}>
<Text
style={{
fontFamily: WEIGHT.regular,
fontSize: SIZE.sm,
color: colors.pri,
}}>
<Text
style={{
color: colors.accent,
}}>
2020-02-03 12:31:18 +05:00
#
2020-01-16 19:53:16 +05:00
</Text>
2020-02-03 12:31:18 +05:00
{tag}
2020-01-16 19:53:16 +05:00
</Text>
</TouchableOpacity>
);
const _renderColor = color => (
<TouchableOpacity
key={color}
2020-02-06 23:38:40 +05:00
onPress={async () => {
2020-01-16 19:53:16 +05:00
let noteColors = note.colors;
if (noteColors.includes(color)) {
2020-02-06 23:38:40 +05:00
await db.notes.note(note.id).uncolor(color);
2020-01-16 19:53:16 +05:00
} else {
2020-02-07 00:26:44 +05:00
await db.notes.note(note.id).color(color);
2020-01-16 19:53:16 +05:00
}
2020-02-07 00:26:44 +05:00
dispatch({type: ACTIONS.COLORS});
localRefresh(note.type);
2020-01-16 19:53:16 +05:00
}}
style={{
flexDirection: 'row',
justifyContent: 'flex-start',
alignItems: 'center',
borderColor: colors.nav,
}}>
<View
style={{
2020-02-22 17:36:18 +05:00
width: DDS.isTab ? 400 / 10 : w / 10,
height: DDS.isTab ? 400 / 10 : w / 10,
2020-01-16 19:53:16 +05:00
backgroundColor: color,
borderRadius: 100,
justifyContent: 'center',
alignItems: 'center',
}}>
{note && note.colors && note.colors.includes(color) ? (
<Icon name="check" color="white" size={SIZE.lg} />
) : null}
</View>
</TouchableOpacity>
);
const _renderRowItem = rowItem =>
rowItems.includes(rowItem.name) ? (
<TouchableOpacity
onPress={rowItem.func}
key={rowItem.name}
style={{
alignItems: 'center',
2020-02-22 17:36:18 +05:00
width: DDS.isTab
? (400 - 24) / rowItems.length
: (w - 25) / rowItems.length,
2020-01-16 19:53:16 +05:00
}}>
<Icon
style={{
width: 50,
height: 40,
borderRadius: 100,
justifyContent: 'center',
alignItems: 'center',
textAlign: 'center',
textAlignVertical: 'center',
2020-01-24 18:48:33 +05:00
marginBottom: DDS.isTab ? 7 : 3.5,
2020-01-16 19:53:16 +05:00
}}
name={rowItem.icon}
2020-01-24 18:48:33 +05:00
size={DDS.isTab ? SIZE.xl : SIZE.lg}
2020-03-02 15:10:49 +05:00
color={rowItem.name === 'Delete' ? colors.errorText : colors.accent}
2020-01-16 19:53:16 +05:00
/>
<Text
style={{
fontFamily: WEIGHT.regular,
2020-02-03 12:18:45 +05:00
fontSize: DDS.isTab ? SIZE.sm : SIZE.xs + 1,
2020-01-16 19:53:16 +05:00
color: colors.pri,
}}>
{rowItem.name}
</Text>
</TouchableOpacity>
) : null;
const _renderColumnItem = item =>
2020-02-06 13:08:35 +05:00
(note.id && columnItems.includes(item.name)) ||
2020-02-02 19:09:33 +05:00
(item.name === 'Dark Mode' && columnItems.includes(item.name)) ? (
2020-01-16 19:53:16 +05:00
<TouchableOpacity
key={item.name}
activeOpacity={opacity}
onPress={() => {
item.func();
}}
style={{
width: '100%',
alignSelf: 'center',
flexDirection: 'row',
justifyContent: 'space-between',
alignItems: 'flex-end',
paddingHorizontal: 12,
2020-01-24 18:48:33 +05:00
paddingVertical: pv,
2020-01-16 19:53:16 +05:00
}}>
<View
style={{
flexDirection: 'row',
alignItems: 'center',
}}>
<Icon
style={{
width: 30,
}}
name={item.icon}
color={colors.pri}
size={SIZE.md}
/>
<Text
style={{
fontFamily: WEIGHT.regular,
fontSize: SIZE.sm,
color: colors.pri,
}}>
{item.name}
</Text>
</View>
{item.switch ? (
<Icon
size={SIZE.lg + 2}
color={item.on ? colors.accent : colors.icon}
2020-02-11 20:33:36 +05:00
name={item.on ? 'toggle-switch' : 'toggle-switch-off'}
2020-01-16 19:53:16 +05:00
/>
) : (
undefined
)}
{item.check ? (
2020-02-11 20:33:36 +05:00
<Icon
name={
item.on ? 'check-circle-outline' : 'checkbox-blank-circle-outline'
}
color={item.on ? colors.accent : colors.icon}
size={SIZE.lg + 2}
/>
2020-01-16 19:53:16 +05:00
) : null}
</TouchableOpacity>
) : null;
2020-01-09 20:14:51 +05:00
return (
2020-01-10 18:44:41 +05:00
<View
2020-01-20 10:33:36 +05:00
onLayout={() => {
2020-02-02 16:18:52 +05:00
if (!item.dateDeleted) {
localRefresh(item.type, true);
}
2020-01-20 10:33:36 +05:00
}}
2020-01-10 18:44:41 +05:00
style={{
paddingBottom: 15,
backgroundColor: colors.bg,
2020-01-22 02:49:29 +05:00
width: '100%',
2020-01-24 18:48:33 +05:00
paddingHorizontal: 0,
2020-01-10 18:44:41 +05:00
}}>
2020-02-12 03:24:36 +05:00
{!note.id && !note.dateCreated ? (
2020-01-29 18:20:54 +05:00
<Text
style={{
width: '100%',
textAlign: 'center',
marginVertical: 10,
color: colors.icon,
fontFamily: WEIGHT.regular,
}}>
Please start writing to save your note.
</Text>
2020-02-03 12:18:45 +05:00
) : (
<View
style={{
paddingHorizontal: 12,
alignItems: 'center',
marginVertical: 10,
}}>
<Text
numberOfLines={1}
style={{
color: colors.pri,
fontSize: SIZE.sm + 1,
fontFamily: WEIGHT.bold,
maxWidth: '100%',
}}>
{note.title.replace('\n', '')}
</Text>
<Text
numberOfLines={2}
style={{
fontSize: SIZE.sm - 1,
color: colors.pri + 'B3',
fontFamily: WEIGHT.regular,
width: '100%',
textAlign: 'center',
maxWidth: '100%',
}}>
{note.type === 'notebook' && note.description
? note.description
: null}
{note.type === 'note'
? note.headline[item.headline.length - 1] === '\n'
? note.headline.slice(0, note.headline.length - 1)
: note.headline
: null}
</Text>
<Text
style={{
color: colors.icon,
fontSize: SIZE.xs - 1,
textAlignVertical: 'center',
fontFamily: WEIGHT.regular,
marginTop: 2.5,
}}>
{note.type === 'note'
2020-02-06 13:08:35 +05:00
? 'Last edited on ' + timeConverter(note.dateEdited)
2020-02-03 12:18:45 +05:00
: null}
{note.type !== 'note' && !note.dateDeleted
? 'Created on ' + timeConverter(note.dateCreated)
: null}
{note.dateDeleted
? 'Deleted on ' + timeConverter(note.dateDeleted)
: null}
</Text>
2020-02-03 12:21:38 +05:00
{note.type !== 'notebook' ? null : (
<View
style={{
flexDirection: 'row',
alignItems: 'center',
justifyContent: 'center',
width: '100%',
maxWidth: '100%',
flexWrap: 'wrap',
}}>
{note && note.topics
? note.topics.slice(1, 4).map(topic => (
<View
key={topic.dateCreated.toString() + topic.title}
style={{
borderRadius: 5,
backgroundColor: colors.accent,
paddingHorizontal: ph / 1.5,
paddingVertical: pv / 4,
marginRight: 5,
marginVertical: 2.5,
}}>
<Text
numberOfLines={1}
style={{
color: 'white',
fontFamily: WEIGHT.regular,
fontSize: SIZE.xxs,
maxWidth: '100%',
}}>
{topic.title}
</Text>
</View>
))
: null}
</View>
)}
{note.type !== 'note' ? null : (
<Text
style={{
color: colors.accent,
fontSize: SIZE.xs - 1,
textAlignVertical: 'center',
fontFamily: WEIGHT.regular,
marginTop: 2,
borderWidth: 1,
textAlign: 'center',
borderColor: colors.accent,
paddingHorizontal: 5,
borderRadius: 2,
}}>
Synced
</Text>
)}
2020-02-03 12:18:45 +05:00
</View>
)}
2020-01-29 18:20:54 +05:00
2020-02-12 03:24:36 +05:00
{note.id || note.dateCreated ? (
2020-01-29 18:20:54 +05:00
<View
style={{
width: '100%',
justifyContent: 'space-between',
alignItems: 'center',
paddingVertical: 10,
flexDirection: 'row',
2020-02-03 12:18:45 +05:00
paddingHorizontal: 12,
2020-01-29 18:20:54 +05:00
}}>
{rowItemsData.map(_renderRowItem)}
</View>
) : null}
2020-01-09 20:14:51 +05:00
2020-02-06 13:08:35 +05:00
{hasColors && note.id ? (
2020-01-10 18:44:41 +05:00
<View
style={{
flexDirection: 'row',
flexWrap: 'wrap',
paddingHorizontal: 12,
width: '100%',
marginVertical: 10,
alignItems: 'center',
justifyContent: 'space-between',
}}>
{['red', 'yellow', 'green', 'blue', 'purple', 'orange', 'gray'].map(
2020-01-16 19:53:16 +05:00
_renderColor,
2020-01-10 18:44:41 +05:00
)}
</View>
) : null}
2020-01-09 20:14:51 +05:00
2020-02-12 03:24:36 +05:00
{hasTags && (note.id || note.dateCreated) ? (
2020-01-10 18:44:41 +05:00
<View
style={{
marginHorizontal: 12,
}}>
2020-03-04 09:51:13 +05:00
<View
style={{
flexDirection: 'row',
flexWrap: 'wrap',
marginBottom: 5,
marginTop: 5,
alignItems: 'center',
}}>
<Text
style={{
fontFamily: WEIGHT.regular,
fontSize: SIZE.xs,
color: colors.accent,
}}>
Suggestions:{' '}
</Text>
{tags
.filter(o => o.count > 1 && !note.tags.find(t => t === o.title))
.map(tag => (
<TouchableOpacity
key={tag.title}
onPress={() => {
tagToAdd = tag.title;
_onSubmit();
}}
style={{
flexDirection: 'row',
justifyContent: 'flex-start',
alignItems: 'center',
margin: 1,
marginRight: 5,
paddingHorizontal: 5,
paddingVertical: 1,
borderRadius: 2.5,
borderBottomWidth: 1,
borderBottomColor: colors.nav,
}}>
<Text
style={{
fontFamily: WEIGHT.regular,
fontSize: SIZE.xs,
color: colors.pri,
}}>
<Text
style={{
color: colors.accent,
}}>
#
</Text>
{tag.title}{' '}
</Text>
<View
style={{
borderRadius: 2.5,
backgroundColor: colors.accent,
alignItems: 'center',
justifyContent: 'center',
}}>
<Text
style={{
color: 'white',
fontSize: SIZE.xxs - 2,
minWidth: 12,
textAlign: 'center',
}}>
{tag.count}
</Text>
</View>
</TouchableOpacity>
))}
</View>
2020-02-03 12:18:45 +05:00
<View
2020-01-10 18:44:41 +05:00
style={{
2020-02-03 12:18:45 +05:00
flexDirection: 'row',
flexWrap: 'wrap',
borderRadius: 5,
borderWidth: 1.5,
borderColor: focused ? colors.accent : colors.nav,
paddingVertical: 5,
}}>
<TouchableOpacity
onPress={() => {
tagsInputRef.current?.focus();
}}
style={{
position: 'absolute',
width: '100%',
height: '100%',
}}></TouchableOpacity>
2020-02-03 12:18:45 +05:00
{note && note.tags ? note.tags.map(_renderTag) : null}
<TextInput
style={{
backgroundColor: 'transparent',
minWidth: 100,
zIndex: 10,
2020-02-03 12:18:45 +05:00
fontFamily: WEIGHT.regular,
color: colors.pri,
paddingHorizontal: 5,
paddingVertical: 1.5,
margin: 1,
}}
blurOnSubmit={false}
ref={tagsInputRef}
2020-02-03 12:18:45 +05:00
placeholderTextColor={colors.icon}
onFocus={() => {
setFocused(true);
}}
selectionColor={colors.accent}
onBlur={() => {
setFocused(false);
}}
placeholder="#hashtag"
onChangeText={value => {
tagToAdd = value;
if (tagToAdd.length > 0) backPressCount = 0;
}}
onSubmitEditing={_onSubmit}
onKeyPress={_onKeyPress}
/>
</View>
2020-01-10 18:44:41 +05:00
</View>
) : null}
{columnItems.length > 0 ? (
2020-01-16 19:53:16 +05:00
<View>{columnItemsData.map(_renderColumnItem)}</View>
2020-01-10 18:44:41 +05:00
) : null}
2020-01-24 18:48:33 +05:00
{DDS.isTab ? (
<View
style={{
height: 20,
}}
/>
) : null}
2020-01-09 20:14:51 +05:00
</View>
);
};