2020-11-25 18:57:46 +05:00
|
|
|
import React, {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 01:04:33 +05:00
|
|
|
TouchableOpacity,
|
2020-11-25 18:57:46 +05:00
|
|
|
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-11-25 18:57:46 +05:00
|
|
|
import {useTracked} from '../../provider';
|
|
|
|
|
import {Actions} from '../../provider/Actions';
|
|
|
|
|
import {DDS} from '../../services/DeviceDetection';
|
2020-10-31 16:32:21 +05:00
|
|
|
import {
|
|
|
|
|
eSendEvent,
|
|
|
|
|
openVault,
|
|
|
|
|
sendNoteEditedEvent,
|
2020-11-25 18:57:46 +05:00
|
|
|
ToastEvent,
|
2020-10-31 16:32:21 +05:00
|
|
|
} from '../../services/EventManager';
|
2020-11-14 13:53:19 +05:00
|
|
|
import PremiumService from '../../services/PremiumService';
|
2020-10-13 17:02:14 +05:00
|
|
|
import {
|
|
|
|
|
ACCENT,
|
|
|
|
|
COLOR_SCHEME,
|
|
|
|
|
COLOR_SCHEME_DARK,
|
|
|
|
|
COLOR_SCHEME_LIGHT,
|
2020-11-25 18:57:46 +05:00
|
|
|
setColorScheme,
|
2020-10-31 16:32:21 +05:00
|
|
|
} from '../../utils/Colors';
|
2020-11-25 18:57:46 +05:00
|
|
|
import {db} from '../../utils/DB';
|
2020-11-14 13:53:19 +05:00
|
|
|
import {
|
|
|
|
|
eOpenLoginDialog,
|
|
|
|
|
eOpenMoveNoteDialog,
|
2020-11-25 18:57:46 +05:00
|
|
|
eShowGetPremium,
|
2020-11-14 13:53:19 +05:00
|
|
|
} from '../../utils/Events';
|
2020-11-25 18:57:46 +05:00
|
|
|
import {deleteItems} from '../../utils/functions';
|
|
|
|
|
import {MMKV} from '../../utils/mmkv';
|
|
|
|
|
import {opacity, ph, pv, SIZE} from '../../utils/SizeUtils';
|
|
|
|
|
import {timeConverter} from '../../utils/TimeUtils';
|
|
|
|
|
import {PremiumTag} from '../Premium/PremiumTag';
|
|
|
|
|
import {PressableButton} from '../PressableButton';
|
|
|
|
|
import {Toast} from '../Toast';
|
2020-11-09 20:26:20 +05:00
|
|
|
import Heading from '../Typography/Heading';
|
|
|
|
|
import Paragraph from '../Typography/Paragraph';
|
2020-11-25 18:57:46 +05:00
|
|
|
import {ActionSheetColorsSection} from './ActionSheetColorsSection';
|
|
|
|
|
import {ActionSheetTagsSection} from './ActionSheetTagsSection';
|
2020-01-09 20:14:51 +05:00
|
|
|
const w = Dimensions.get('window').width;
|
2020-10-31 16:32:21 +05:00
|
|
|
|
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-11-02 20:45:11 +05:00
|
|
|
const {colors, premiumUser, user} = state;
|
2020-09-08 14:36:25 +05:00
|
|
|
const [refreshing, setRefreshing] = useState(false);
|
2020-11-25 18:49:21 +05:00
|
|
|
const [isPinnedToMenu, setIsPinnedToMenu] = 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-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-11-25 18:49:21 +05:00
|
|
|
if (item.type !== note) {
|
|
|
|
|
setIsPinnedToMenu(
|
|
|
|
|
db.settings.pins.findIndex((i) => i.id === item.id) > -1,
|
|
|
|
|
);
|
|
|
|
|
}
|
2020-01-14 17:33:48 +05:00
|
|
|
}
|
2020-01-11 23:05:39 +05:00
|
|
|
}, [item]);
|
|
|
|
|
|
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-11-17 20:22:40 +05:00
|
|
|
openVault({
|
2020-11-20 01:23:05 +05:00
|
|
|
item: item,
|
|
|
|
|
novault: true,
|
|
|
|
|
locked: true,
|
|
|
|
|
share: 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-11-14 10:09:41 +05:00
|
|
|
func: async () => {
|
|
|
|
|
close();
|
|
|
|
|
try {
|
2020-11-14 13:53:19 +05:00
|
|
|
await deleteItems(note);
|
|
|
|
|
} catch (e) {
|
2020-11-14 10:09:41 +05:00
|
|
|
console.log(e);
|
|
|
|
|
}
|
|
|
|
|
},
|
2020-01-10 18:44:41 +05:00
|
|
|
},
|
|
|
|
|
{
|
|
|
|
|
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-11-25 14:02:01 +05:00
|
|
|
await PremiumService.verify(
|
|
|
|
|
async () => {
|
|
|
|
|
if (!note.id) return;
|
|
|
|
|
if (note.type === 'note') {
|
|
|
|
|
if (db.notes.pinned.length === 3) {
|
|
|
|
|
ToastEvent.show(
|
|
|
|
|
'You cannot pin more than 3 notes',
|
|
|
|
|
'error',
|
|
|
|
|
'local',
|
|
|
|
|
);
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
await db.notes.note(note.id).pin();
|
|
|
|
|
} else {
|
|
|
|
|
if (db.notebooks.pinned.length === 3) {
|
|
|
|
|
ToastEvent.show(
|
|
|
|
|
'You cannot pin more than 3 notes',
|
|
|
|
|
'error',
|
|
|
|
|
'local',
|
|
|
|
|
);
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
await db.notebooks.notebook(note.id).pin();
|
|
|
|
|
}
|
|
|
|
|
localRefresh(item.type);
|
|
|
|
|
},
|
|
|
|
|
{
|
|
|
|
|
context: 'sheet',
|
|
|
|
|
title: 'Get Notesnook Pro',
|
|
|
|
|
desc: 'To pin notes and notebooks become a Pro user today.',
|
|
|
|
|
},
|
|
|
|
|
);
|
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-10-13 17:02:14 +05:00
|
|
|
dispatch({type: Actions.FAVORITES});
|
2020-10-31 16:32:21 +05:00
|
|
|
sendNoteEditedEvent(note.id, false, true);
|
|
|
|
|
localRefresh(item.type, true);
|
2020-01-10 18:44:41 +05:00
|
|
|
},
|
|
|
|
|
close: false,
|
|
|
|
|
check: true,
|
|
|
|
|
on: note.favorite,
|
|
|
|
|
},
|
2020-11-25 18:49:21 +05:00
|
|
|
{
|
|
|
|
|
name: isPinnedToMenu ? 'Unpin from Menu' : 'Pin to Menu',
|
|
|
|
|
icon: 'tag-outline',
|
|
|
|
|
func: async () => {
|
|
|
|
|
try {
|
|
|
|
|
if (isPinnedToMenu) {
|
|
|
|
|
await db.settings.unpin(note.id);
|
|
|
|
|
} else {
|
2020-11-25 18:57:46 +05:00
|
|
|
if (item.type === 'topic') {
|
2020-11-25 18:49:21 +05:00
|
|
|
await db.settings.pin(note.type, {
|
|
|
|
|
id: note.notebookId,
|
|
|
|
|
topic: note.id,
|
|
|
|
|
});
|
2020-11-25 18:57:46 +05:00
|
|
|
} else {
|
|
|
|
|
await db.settings.pin(note.type, {id: note.id});
|
2020-11-25 18:49:21 +05:00
|
|
|
}
|
|
|
|
|
}
|
2020-11-25 18:57:46 +05:00
|
|
|
|
2020-11-25 18:49:21 +05:00
|
|
|
setIsPinnedToMenu(
|
|
|
|
|
db.settings.pins.findIndex((i) => i.id === item.id) > -1,
|
|
|
|
|
);
|
2020-11-25 18:57:46 +05:00
|
|
|
dispatch({type: Actions.MENU_PINS});
|
2020-11-25 18:49:21 +05:00
|
|
|
} catch (e) {}
|
|
|
|
|
},
|
|
|
|
|
close: false,
|
|
|
|
|
check: true,
|
|
|
|
|
on: isPinnedToMenu,
|
|
|
|
|
},
|
2020-01-10 18:44:41 +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
|
|
|
/>
|
2020-11-09 20:26:20 +05:00
|
|
|
<Paragraph>{rowItem.name}</Paragraph>
|
2020-01-16 19:53:16 +05:00
|
|
|
</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}
|
|
|
|
|
/>
|
2020-11-09 20:26:20 +05:00
|
|
|
<Paragraph>{item.name}</Paragraph>
|
2020-04-18 13:49:24 +05:00
|
|
|
</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-28 15:52:15 +05:00
|
|
|
if (!user) {
|
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;
|
|
|
|
|
}
|
2020-10-31 13:29:36 +05:00
|
|
|
if (user?.lastSynced < note?.dateEdited || !user.lastSynced) {
|
2020-09-08 14:36:25 +05:00
|
|
|
setRefreshing(true);
|
|
|
|
|
try {
|
|
|
|
|
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 {
|
2020-10-31 13:29:36 +05:00
|
|
|
let user = await db.user.get();
|
|
|
|
|
dispatch({type: Actions.USER, user: user});
|
|
|
|
|
dispatch({type: Actions.ALL});
|
2020-09-24 23:03:57 +05:00
|
|
|
setRefreshing(false);
|
2020-09-08 14:36:25 +05:00
|
|
|
}
|
2020-11-25 14:02:01 +05:00
|
|
|
}
|
2020-09-08 14:36:25 +05:00
|
|
|
};
|
|
|
|
|
|
2020-11-14 13:53:19 +05:00
|
|
|
const onPressVaultButton = async () => {
|
2020-11-17 20:17:50 +05:00
|
|
|
if (!note.id) return;
|
2020-11-02 20:45:11 +05:00
|
|
|
|
2020-11-17 20:17:50 +05:00
|
|
|
if (note.locked) {
|
|
|
|
|
close('unlock');
|
|
|
|
|
} else {
|
|
|
|
|
db.vault
|
|
|
|
|
.add(note.id)
|
|
|
|
|
.then(() => {
|
|
|
|
|
sendNoteEditedEvent(note.id, false, true);
|
|
|
|
|
close();
|
|
|
|
|
})
|
|
|
|
|
.catch(async (e) => {
|
|
|
|
|
switch (e.message) {
|
|
|
|
|
case db.vault.ERRORS.noVault:
|
|
|
|
|
close('novault');
|
|
|
|
|
break;
|
|
|
|
|
case db.vault.ERRORS.vaultLocked:
|
|
|
|
|
close('locked');
|
|
|
|
|
break;
|
|
|
|
|
case db.vault.ERRORS.wrongPassword:
|
2020-11-02 20:45:11 +05:00
|
|
|
close();
|
2020-11-17 20:17:50 +05:00
|
|
|
break;
|
|
|
|
|
}
|
|
|
|
|
});
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return;
|
|
|
|
|
await PremiumService.verify(
|
|
|
|
|
() => {},
|
2020-11-14 13:53:19 +05:00
|
|
|
() => {
|
|
|
|
|
eSendEvent(eShowGetPremium, {
|
|
|
|
|
context: 'sheet',
|
2020-11-14 14:17:58 +05:00
|
|
|
title: 'Add Notes to Vault',
|
2020-11-14 13:53:19 +05:00
|
|
|
desc:
|
|
|
|
|
'With Notesnook Pro you can add notes to your vault and do so much more! Get it now.',
|
2020-11-02 20:45:11 +05:00
|
|
|
});
|
2020-11-14 13:53:19 +05:00
|
|
|
},
|
|
|
|
|
);
|
2020-11-02 20:45:11 +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={{
|
2020-03-17 15:20:23 +05:00
|
|
|
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-11-09 20:26:20 +05:00
|
|
|
<Paragraph style={{marginVertical: 10}}>
|
|
|
|
|
Start writing to save your note.
|
|
|
|
|
</Paragraph>
|
2020-02-03 12:18:45 +05:00
|
|
|
) : (
|
2020-04-18 13:49:24 +05:00
|
|
|
<View
|
|
|
|
|
style={{
|
|
|
|
|
paddingHorizontal: 12,
|
|
|
|
|
alignItems: 'center',
|
|
|
|
|
marginVertical: 10,
|
|
|
|
|
}}>
|
2020-11-09 20:26:20 +05:00
|
|
|
<Heading size={SIZE.md}>{note.title.replace('\n', '')}</Heading>
|
|
|
|
|
|
2020-11-20 01:23:05 +05:00
|
|
|
<Paragraph
|
2020-04-18 13:49:24 +05:00
|
|
|
numberOfLines={2}
|
|
|
|
|
style={{
|
|
|
|
|
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}
|
2020-11-20 01:23:05 +05:00
|
|
|
</Paragraph>
|
2020-04-18 13:49:24 +05:00
|
|
|
|
2020-11-20 01:23:05 +05:00
|
|
|
<Paragraph
|
|
|
|
|
color={colors.icon}
|
|
|
|
|
size={SIZE.xs}
|
2020-04-18 13:49:24 +05:00
|
|
|
style={{
|
|
|
|
|
textAlignVertical: 'center',
|
|
|
|
|
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}
|
2020-11-20 01:23:05 +05:00
|
|
|
</Paragraph>
|
2020-04-18 13:49:24 +05:00
|
|
|
|
|
|
|
|
{note.type !== 'notebook' ? null : (
|
|
|
|
|
<View
|
2020-04-09 15:13:09 +05:00
|
|
|
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,
|
|
|
|
|
}}>
|
2020-11-20 01:23:05 +05:00
|
|
|
<Paragraph
|
|
|
|
|
size={SIZE.xs}
|
2020-02-03 12:21:38 +05:00
|
|
|
numberOfLines={1}
|
2020-11-20 01:23:05 +05:00
|
|
|
color="white"
|
2020-02-03 12:21:38 +05:00
|
|
|
style={{
|
|
|
|
|
maxWidth: '100%',
|
|
|
|
|
}}>
|
|
|
|
|
{topic.title}
|
2020-11-20 01:23:05 +05:00
|
|
|
</Paragraph>
|
2020-02-03 12:21:38 +05:00
|
|
|
</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-11-20 01:23:05 +05:00
|
|
|
<Paragraph
|
|
|
|
|
color={colors.accent}
|
|
|
|
|
size={SIZE.xs}
|
2020-09-08 14:36:25 +05:00
|
|
|
onPress={onPressSync}
|
2020-04-18 13:49:24 +05:00
|
|
|
style={{
|
|
|
|
|
textAlignVertical: 'center',
|
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-11-09 20:26:20 +05:00
|
|
|
height: 20,
|
2020-04-18 13:49:24 +05:00
|
|
|
}}>
|
2020-09-08 14:36:25 +05:00
|
|
|
{user && user.lastSynced > note.dateEdited
|
|
|
|
|
? 'Synced'
|
|
|
|
|
: 'Sync Now'}
|
2020-11-20 01:23:05 +05:00
|
|
|
</Paragraph>
|
2020-04-18 13:49:24 +05:00
|
|
|
)}
|
2020-09-08 14:36:25 +05:00
|
|
|
|
|
|
|
|
{refreshing ? (
|
|
|
|
|
<ActivityIndicator
|
2020-11-09 20:26:20 +05:00
|
|
|
style={{marginTop: 5, height: 20}}
|
2020-09-08 14:36:25 +05:00
|
|
|
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-11-02 20:45:11 +05:00
|
|
|
{note.type === 'note' ? (
|
|
|
|
|
<PressableButton
|
|
|
|
|
color={note.locked ? colors.errorBg : colors.shade}
|
|
|
|
|
selectedColor={note.locked ? '#FF0000' : colors.accent}
|
|
|
|
|
alpha={0.14}
|
|
|
|
|
onPress={onPressVaultButton}
|
|
|
|
|
opacity={0.15}
|
|
|
|
|
customStyle={{
|
|
|
|
|
width: '95%',
|
|
|
|
|
alignSelf: 'center',
|
|
|
|
|
height: 50,
|
2020-01-10 18:44:41 +05:00
|
|
|
flexDirection: 'row',
|
2020-11-02 20:45:11 +05:00
|
|
|
justifyContent: 'center',
|
2020-01-10 18:44:41 +05:00
|
|
|
alignItems: 'center',
|
|
|
|
|
}}>
|
2020-11-02 20:45:11 +05:00
|
|
|
<Icon
|
|
|
|
|
name={note.locked ? 'shield-off' : 'shield'}
|
|
|
|
|
color={note.locked ? '#FF0000' : colors.accent}
|
|
|
|
|
size={SIZE.md}
|
|
|
|
|
/>
|
2020-11-20 01:23:05 +05:00
|
|
|
<Paragraph
|
|
|
|
|
color={note.locked ? '#FF0000' : colors.accent}
|
|
|
|
|
size={SIZE.md}
|
2020-11-02 20:45:11 +05:00
|
|
|
style={{
|
|
|
|
|
marginLeft: 5,
|
|
|
|
|
}}>
|
|
|
|
|
{note.locked ? 'Remove from Vault' : 'Add to Vault'}
|
2020-11-20 01:23:05 +05:00
|
|
|
</Paragraph>
|
2020-11-02 20:45:11 +05:00
|
|
|
</PressableButton>
|
2020-01-10 18:44:41 +05:00
|
|
|
) : null}
|
2020-01-09 20:14:51 +05:00
|
|
|
|
2020-11-14 13:53:19 +05:00
|
|
|
{hasColors && note.id ? (
|
|
|
|
|
<ActionSheetColorsSection close={close} item={note} />
|
|
|
|
|
) : null}
|
2020-11-02 20:45:11 +05:00
|
|
|
|
|
|
|
|
{hasTags ? (
|
2020-11-14 13:53:19 +05:00
|
|
|
<ActionSheetTagsSection
|
|
|
|
|
close={close}
|
|
|
|
|
item={note}
|
|
|
|
|
localRefresh={localRefresh}
|
|
|
|
|
/>
|
2020-11-02 20:45:11 +05:00
|
|
|
) : null}
|
2020-01-10 18:44:41 +05:00
|
|
|
|
|
|
|
|
{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>
|
|
|
|
|
);
|
|
|
|
|
};
|