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

964 lines
26 KiB
JavaScript
Raw Normal View History

2020-04-18 13:49:24 +05:00
import React, {createRef, useEffect, useState} from 'react';
2020-01-09 20:14:51 +05:00
import {
2020-09-10 10:35:02 +05:00
ActivityIndicator,
2020-09-24 23:03:57 +05:00
Clipboard,
2020-01-09 20:14:51 +05:00
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-01-09 20:14:51 +05:00
} from 'react-native';
2020-03-14 13:37:07 +05:00
import Share from 'react-native-share';
2020-02-11 20:33:36 +05:00
import Icon from 'react-native-vector-icons/MaterialCommunityIcons';
2020-04-18 13:49:24 +05:00
import {useTracked} from '../../provider';
2020-10-13 17:02:14 +05:00
import {Actions} from '../../provider/Actions';
2020-10-16 20:16:52 +05:00
import {eSendEvent, openVault, sendNoteEditedEvent, ToastEvent} from '../../services/EventManager';
2020-09-14 17:17:17 +05:00
import {
2020-10-15 00:30:23 +05:00
eOnNoteEdited,
2020-09-14 17:17:17 +05:00
eOpenLoginDialog,
eOpenMoveNoteDialog,
refreshNotesPage,
2020-10-13 17:02:14 +05:00
} from '../../utils/Events';
2020-05-14 14:49:45 +05:00
import {PremiumTag} from '../Premium/PremiumTag';
2020-09-10 10:19:36 +05:00
import {PressableButton} from '../PressableButton';
2020-09-14 13:14:07 +05:00
import {Toast} from '../Toast';
2020-10-13 17:02:14 +05:00
import {hexToRGBA, RGB_Linear_Shade} from "../../utils/ColorUtils";
import {timeConverter} from "../../utils/TimeUtils";
import {
ACCENT,
COLOR_SCHEME,
COLOR_SCHEME_DARK,
COLOR_SCHEME_LIGHT,
COLORS_NOTE,
setColorScheme
} from "../../utils/Colors";
import {opacity, ph, pv, SIZE, WEIGHT} from "../../utils/SizeUtils";
import {db} from "../../utils/DB";
import {DDS} from "../../services/DeviceDetection";
import {MMKV} from "../../utils/MMKV";
2020-10-16 20:16:52 +05:00
import id from "notes-core/utils/id";
2020-03-14 13:37:07 +05:00
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 = ({
2020-04-18 13:49:24 +05:00
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();
2020-09-08 14:36:25 +05:00
const {colors, tags, premiumUser, user} = state;
2020-01-09 20:14:51 +05:00
const [focused, setFocused] = useState(false);
2020-09-08 14:36:25 +05:00
const [refreshing, setRefreshing] = useState(false);
2020-01-15 20:20:53 +05:00
const [note, setNote] = useState(
item
? item
: {
2020-04-18 13:49:24 +05:00
colors: [],
tags: [],
pinned: false,
favorite: false,
locked: false,
content: {
text: null,
delta: null,
},
dateCreated: null,
2020-01-15 20:20:53 +05:00
},
);
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
2020-10-13 17:02:14 +05:00
dispatch({type: Actions.THEME, colors: newColors});
2020-01-22 02:49:29 +05:00
}
2020-01-11 23:05:39 +05:00
useEffect(() => {
2020-01-14 17:33:48 +05:00
if (item.dateCreated !== null) {
2020-04-18 13:49:24 +05:00
setNote({...item});
2020-01-14 17:33:48 +05:00
}
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;
tag = tag.trim();
2020-01-09 20:14:51 +05:00
if (tag.includes(' ')) {
tag = tag.replace(' ', '_');
}
if (tag.includes(',')) {
tag = tag.replace(',', '');
}
2020-02-02 14:24:24 +05:00
2020-02-06 13:08:35 +05:00
await db.notes.note(note.id).tag(tag);
2020-04-18 13:49:24 +05:00
setNote({...db.notes.note(note.id).data});
2020-10-13 17:02:14 +05:00
dispatch({type: Actions.TAGS});
2020-05-10 22:21:31 +05:00
tagsInputRef.current?.setNativeProps({
text: '',
});
2020-01-09 20:14:51 +05:00
tagToAdd = '';
};
2020-09-06 10:34:54 +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];
2020-04-18 13:49:24 +05:00
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-04-18 13:49:24 +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 === ' ') {
2020-10-16 20:16:52 +05:00
await _onSubmit();
tagsInputRef.current?.setNativeProps({
text: '',
});
2020-03-04 09:51:13 +05:00
} else if (event.nativeEvent.key === ',') {
2020-10-16 20:16:52 +05:00
await _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) {
2020-04-18 13:49:24 +05:00
dispatch({type: type});
2020-10-13 17:02:14 +05:00
dispatch({type: Actions.FAVORITES});
2020-01-20 10:33:36 +05:00
}
2020-04-18 13:49:24 +05:00
setNote({...toAdd});
2020-01-10 18:44:41 +05:00
};
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-10-13 17:02:14 +05:00
dispatch({type: Actions.MODAL_NAVIGATOR, enabled: true});
dispatch({type: Actions.SELECTED_ITEMS, item: note});
2020-09-14 17:10:02 +05:00
close();
setTimeout(() => {
eSendEvent(eOpenMoveNoteDialog);
2020-09-14 17:17:17 +05:00
}, 400);
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: () => {
2020-09-08 14:36:25 +05:00
close('export');
2020-01-10 18:44:41 +05:00
},
},
{
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
{
2020-09-14 13:14:07 +05:00
name: 'Copy',
icon: 'content-copy',
func: async () => {
let text = await db.notes.note(note.id).text();
Clipboard.setString(text);
ToastEvent.show('Note copied to clipboard', 'success', 'local');
2020-02-20 20:02:37 +05:00
},
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 () => {
2020-10-13 17:02:14 +05:00
dispatch({type: Actions.TRASH});
2020-02-07 04:25:55 +05:00
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',
);
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-09-08 14:36:25 +05:00
MMKV.setStringAsync('theme', JSON.stringify({night: true}));
2020-01-10 18:44:41 +05:00
changeColorScheme(COLOR_SCHEME_DARK);
} else {
2020-04-18 13:49:24 +05:00
MMKV.setStringAsync('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,
2020-09-06 10:34:54 +05:00
nopremium: true,
2020-01-10 18:44:41 +05:00
},
{
name: 'Pin',
2020-02-11 20:33:36 +05:00
icon: 'tag-outline',
2020-02-01 12:56:30 +05:00
func: async () => {
2020-05-14 14:49:45 +05:00
if (!premiumUser) {
2020-06-03 10:39:47 +05:00
close('premium');
2020-05-14 14:49:45 +05:00
return;
}
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
}
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-05-14 14:49:45 +05:00
if (!premiumUser) {
2020-06-03 10:39:47 +05:00
close('premium');
2020-05-14 14:49:45 +05:00
return;
}
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-10-13 17:02:14 +05:00
dispatch({type: Actions.FAVORITES});
2020-10-16 20:16:52 +05:00
sendNoteEditedEvent(note.id, false,true)
2020-10-15 00:30:23 +05:00
localRefresh(item.type,true);
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-05-14 14:49:45 +05:00
if (!premiumUser) {
2020-06-03 10:39:47 +05:00
close('premium');
2020-05-14 14:49:45 +05:00
return;
}
2020-02-06 13:08:35 +05:00
if (!note.id) return;
2020-03-10 23:19:16 +05:00
if (note.locked) {
2020-04-18 13:49:24 +05:00
close('unlock');
2020-03-10 23:19:16 +05:00
} else {
db.vault
.add(note.id)
.then(() => {
2020-10-16 20:16:52 +05:00
sendNoteEditedEvent(note.id, false,true)
2020-03-10 23:19:16 +05:00
close();
})
2020-09-06 10:34:54 +05:00
.catch(async (e) => {
2020-03-10 23:19:16 +05:00
switch (e.message) {
case db.vault.ERRORS.noVault:
2020-04-18 13:49:24 +05:00
close('novault');
2020-03-10 23:19:16 +05:00
break;
case db.vault.ERRORS.vaultLocked:
2020-04-18 14:03:05 +05:00
close('locked');
2020-03-10 23:19:16 +05:00
break;
case db.vault.ERRORS.wrongPassword:
2020-03-15 09:27:10 +05:00
close();
2020-03-10 23:19:16 +05:00
break;
}
});
}
2020-01-10 18:44:41 +05:00
},
close: true,
check: true,
on: note.locked,
},
];
2020-09-06 10:34:54 +05:00
const _renderTag = (tag) => (
2020-01-16 19:53:16 +05:00
<TouchableOpacity
key={tag}
2020-02-02 14:24:24 +05:00
onPress={async () => {
2020-04-18 13:49:24 +05:00
let oldProps = {...note};
try {
await db.notes
.note(note.id)
.untag(oldProps.tags[oldProps.tags.indexOf(tag)]);
2020-10-16 20:16:52 +05:00
sendNoteEditedEvent(note.id, false,true)
2020-10-13 17:02:14 +05:00
dispatch({type: Actions.TAGS});
} catch (e) {
2020-10-16 20:16:52 +05:00
sendNoteEditedEvent(note.id, false,true)
}
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>
);
2020-09-10 10:19:36 +05:00
const _renderColor = (c) => {
const color = {
name: c,
value: COLORS_NOTE[c],
};
return (
<PressableButton
color={RGB_Linear_Shade(
!colors.night ? -0.2 : 0.2,
hexToRGBA(color.value, 1),
)}
selectedColor={color.value}
alpha={!colors.night ? -0.1 : 0.1}
opacity={1}
key={color.value}
onPress={async () => {
let noteColors = note.colors;
if (noteColors.includes(color.name)) {
await db.notes.note(note.id).uncolor(color.name);
} else {
await db.notes.note(note.id).color(color.name);
}
2020-10-13 17:02:14 +05:00
dispatch({type: Actions.COLORS});
2020-10-16 20:16:52 +05:00
sendNoteEditedEvent(note.id, false,true)
2020-10-15 00:30:23 +05:00
localRefresh(note.type,true);
2020-09-10 10:19:36 +05:00
}}
customStyle={{
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
borderRadius: 100,
justifyContent: 'center',
alignItems: 'center',
}}>
2020-09-10 10:19:36 +05:00
{note && note.colors && note.colors.includes(color.name) ? (
2020-01-16 19:53:16 +05:00
<Icon name="check" color="white" size={SIZE.lg} />
) : null}
2020-09-10 10:19:36 +05:00
</PressableButton>
);
};
2020-01-16 19:53:16 +05:00
2020-09-06 10:34:54 +05:00
const _renderRowItem = (rowItem) =>
2020-01-16 19:53:16 +05:00
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;
2020-09-06 10:34:54 +05:00
const _renderColumnItem = (item) =>
2020-02-06 13:08:35 +05:00
(note.id && columnItems.includes(item.name)) ||
2020-04-18 13:49:24 +05:00
(item.name === 'Dark Mode' && columnItems.includes(item.name)) ? (
<TouchableOpacity
key={item.name}
activeOpacity={opacity}
onPress={() => {
item.func();
}}
style={{
width: '100%',
alignSelf: 'center',
flexDirection: 'row',
justifyContent: 'space-between',
alignItems: 'flex-end',
paddingHorizontal: 12,
paddingVertical: pv,
}}>
<View
2020-01-16 19:53:16 +05:00
style={{
flexDirection: 'row',
2020-04-18 13:49:24 +05:00
alignItems: 'center',
2020-01-16 19:53:16 +05:00
}}>
2020-04-18 13:49:24 +05:00
<Icon
2020-01-16 19:53:16 +05:00
style={{
2020-04-18 13:49:24 +05:00
width: 30,
}}
name={item.icon}
color={colors.pri}
size={SIZE.md}
/>
<Text
style={{
fontFamily: WEIGHT.regular,
fontSize: SIZE.sm,
color: colors.pri,
2020-01-16 19:53:16 +05:00
}}>
2020-04-18 13:49:24 +05:00
{item.name}
</Text>
</View>
2020-09-06 10:34:54 +05:00
2020-05-14 14:49:45 +05:00
<View
style={{
flexDirection: 'row',
alignItems: 'center',
}}>
2020-09-06 10:34:54 +05:00
{item.switch ? (
<Icon
size={SIZE.lg + 2}
color={item.on ? colors.accent : colors.icon}
name={item.on ? 'toggle-switch' : 'toggle-switch-off'}
/>
) : undefined}
{item.nopremium ? null : <PremiumTag pro={premiumUser} />}
2020-05-14 14:49:45 +05:00
{item.check ? (
<Icon
name={
item.on
? 'check-circle-outline'
: 'checkbox-blank-circle-outline'
}
color={item.on ? colors.accent : colors.icon}
size={SIZE.lg + 2}
/>
) : null}
</View>
2020-04-18 13:49:24 +05:00
</TouchableOpacity>
) : null;
2020-01-16 19:53:16 +05:00
2020-09-08 14:36:25 +05:00
const onPressSync = async () => {
2020-10-15 00:30:23 +05:00
if (!user || !user.Id) {
2020-09-14 13:14:07 +05:00
ToastEvent.show(
'You must login to sync',
'error',
'local',
5000,
() => {
close();
setTimeout(() => {
eSendEvent(eOpenLoginDialog);
}, 500);
},
'Login',
);
2020-09-08 14:36:25 +05:00
return;
}
if (user?.lastSynced < note?.dateEdited) {
setRefreshing(true);
try {
let user = await db.user.get();
2020-10-13 17:02:14 +05:00
dispatch({type: Actions.USER, user: user});
2020-09-08 14:36:25 +05:00
await db.sync();
localRefresh();
2020-09-14 13:14:07 +05:00
ToastEvent.show('Note synced', 'success', 'local');
2020-09-08 14:36:25 +05:00
} catch (e) {
ToastEvent.show(e.message, 'error', 'local');
2020-09-24 23:03:57 +05:00
} finally {
setRefreshing(false);
2020-09-08 14:36:25 +05:00
}
2020-10-13 17:02:14 +05:00
dispatch({type: Actions.ALL});
2020-09-08 14:36:25 +05:00
}
};
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: 30,
2020-01-10 18:44:41 +05:00
backgroundColor: colors.bg,
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
) : (
2020-04-18 13:49:24 +05:00
<View
style={{
paddingHorizontal: 12,
alignItems: 'center',
marginVertical: 10,
}}>
<Text
numberOfLines={1}
2020-02-03 12:18:45 +05:00
style={{
2020-09-08 14:36:25 +05:00
color: colors.heading,
2020-04-18 13:49:24 +05:00
fontSize: SIZE.sm + 1,
fontFamily: WEIGHT.bold,
maxWidth: '100%',
2020-02-03 12:18:45 +05:00
}}>
2020-04-18 13:49:24 +05:00
{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'
? 'Last edited on ' + timeConverter(note.dateEdited)
: null}
{note.type !== 'note' && !note.dateDeleted
? 'Created on ' + timeConverter(note.dateCreated)
: null}
{note.dateDeleted
? 'Deleted on ' + timeConverter(note.dateDeleted)
: null}
</Text>
{note.type !== 'notebook' ? null : (
<View
style={{
2020-04-18 13:49:24 +05:00
flexDirection: 'row',
alignItems: 'center',
justifyContent: 'center',
2020-02-03 12:21:38 +05:00
width: '100%',
maxWidth: '100%',
2020-04-18 13:49:24 +05:00
flexWrap: 'wrap',
2020-02-03 12:21:38 +05:00
}}>
2020-04-18 13:49:24 +05:00
{note && note.topics
2020-09-06 10:34:54 +05:00
? note.topics.slice(1, 4).map((topic) => (
2020-02-03 12:21:38 +05:00
<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>
))
2020-04-18 13:49:24 +05:00
: null}
</View>
)}
2020-09-08 14:36:25 +05:00
{note.type !== 'note' || refreshing ? null : (
2020-04-18 13:49:24 +05:00
<Text
2020-09-08 14:36:25 +05:00
onPress={onPressSync}
2020-04-18 13:49:24 +05:00
style={{
color: colors.accent,
fontSize: SIZE.xs - 1,
textAlignVertical: 'center',
fontFamily: WEIGHT.regular,
2020-09-08 14:36:25 +05:00
marginTop: 5,
2020-04-18 13:49:24 +05:00
borderWidth: 1,
textAlign: 'center',
borderColor: colors.accent,
paddingHorizontal: 5,
borderRadius: 2,
}}>
2020-09-08 14:36:25 +05:00
{user && user.lastSynced > note.dateEdited
? 'Synced'
: 'Sync Now'}
2020-04-18 13:49:24 +05:00
</Text>
)}
2020-09-08 14:36:25 +05:00
{refreshing ? (
<ActivityIndicator
style={{marginTop: 5}}
size={12}
color={colors.accent}
/>
) : null}
2020-04-18 13:49:24 +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',
}}>
2020-09-10 10:19:36 +05:00
{Object.keys(COLORS_NOTE).map(_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,
}}>
2020-05-14 14:49:45 +05:00
{tags.filter(
2020-09-06 10:34:54 +05:00
(o) => o.count > 1 && !note.tags.find((t) => t === o.title),
2020-05-14 14:49:45 +05:00
).length === 0
? ''
: 'Suggestions '}
2020-03-04 09:51:13 +05:00
</Text>
{tags
2020-09-06 10:34:54 +05:00
.filter(
(o) => o.count > 1 && !note.tags.find((t) => t === o.title),
)
.map((tag) => (
2020-03-04 09:51:13 +05:00
<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,
2020-05-14 14:49:45 +05:00
alignItems: 'center',
height:40
2020-02-03 12:18:45 +05:00
}}>
<TouchableOpacity
onPress={() => {
2020-05-14 14:49:45 +05:00
if (!premiumUser) {
2020-06-03 10:39:47 +05:00
close('premium');
2020-05-14 14:49:45 +05:00
return;
}
tagsInputRef.current?.focus();
}}
activeOpacity={1}
style={{
position: 'absolute',
width: '100%',
height: '100%',
2020-05-14 14:49:45 +05:00
justifyContent: 'flex-start',
alignItems: 'flex-end',
zIndex:10
2020-05-14 14:49:45 +05:00
}}>
{!premiumUser ? (
<Text
style={{
color: colors.accent,
fontFamily: WEIGHT.regular,
fontSize: 10,
marginRight: 4,
marginTop:2.5
2020-05-14 14:49:45 +05:00
}}>
PRO
</Text>
) : null}
</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:0,
height:40,
textAlignVertical:"center"
2020-02-03 12:18:45 +05:00
}}
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"
2020-09-06 10:34:54 +05:00
onChangeText={(value) => {
2020-02-03 12:18:45 +05:00
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-09-14 13:14:07 +05:00
<Toast context="local" />
2020-01-09 20:14:51 +05:00
</View>
);
};