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

806 lines
22 KiB
JavaScript
Raw Normal View History

2021-06-14 08:37:38 +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-12-31 12:01:14 +05:00
Dimensions,
Keyboard,
ScrollView,
TouchableOpacity,
2021-06-14 08:37:38 +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';
2021-06-14 08:37:38 +05:00
import {notesnook} from '../../../e2e/test.ids';
import {useTracked} from '../../provider';
import {Actions} from '../../provider/Actions';
2020-10-31 16:32:21 +05:00
import {
2021-06-14 08:37:38 +05:00
useMenuStore,
useSelectionStore,
useUserStore,
} from '../../provider/stores';
import {DDS} from '../../services/DeviceDetection';
import {eSendEvent, openVault, ToastEvent} from '../../services/EventManager';
2021-02-16 16:11:10 +05:00
import Navigation from '../../services/Navigation';
2020-12-20 23:01:35 +05:00
import Sync from '../../services/Sync';
2021-06-14 08:37:38 +05:00
import {editing, toTXT} from '../../utils';
2020-10-13 17:02:14 +05:00
import {
ACCENT,
COLOR_SCHEME,
COLOR_SCHEME_DARK,
COLOR_SCHEME_LIGHT,
2021-06-14 08:37:38 +05:00
setColorScheme,
2020-10-31 16:32:21 +05:00
} from '../../utils/Colors';
2021-06-14 08:37:38 +05:00
import {db} from '../../utils/DB';
import {eOpenMoveNoteDialog, eOpenPublishNoteDialog} from '../../utils/Events';
import {deleteItems} from '../../utils/functions';
import {MMKV} from '../../utils/mmkv';
2021-06-14 10:01:44 +05:00
import {SIZE} from '../../utils/SizeUtils';
2021-06-14 08:37:38 +05:00
import {sleep, timeConverter} from '../../utils/TimeUtils';
import {Button} from '../Button';
import {PressableButton} from '../PressableButton';
2020-11-09 20:26:20 +05:00
import Heading from '../Typography/Heading';
import Paragraph from '../Typography/Paragraph';
2021-06-14 08:37:38 +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-12-19 14:26:44 +05:00
getRef,
2020-01-09 20:14:51 +05:00
}) => {
2020-01-17 21:26:01 +05:00
const [state, dispatch] = useTracked();
2021-06-14 08:37:38 +05:00
const {colors} = state;
2021-06-05 21:10:20 +05:00
const clearSelection = useSelectionStore(state => state.clearSelection);
const setSelectedItem = useSelectionStore(state => state.setSelectedItem);
const setMenuPins = useMenuStore(state => state.setMenuPins);
const user = useUserStore(state => state.user);
const lastSynced = useUserStore(state => state.lastSynced);
2021-06-14 08:37:38 +05:00
const refreshing = false;
const [isPinnedToMenu, setIsPinnedToMenu] = useState(
db.settings.isPinned(item.id),
);
2020-12-31 13:42:53 +05:00
const [note, setNote] = useState(item);
2021-06-05 01:35:58 +05:00
2021-06-14 08:37:38 +05:00
const noteInTopic =
editing.actionAfterFirstSave.type === 'topic' &&
2021-06-14 08:37:38 +05:00
db.notebooks
.notebook(editing.actionAfterFirstSave.notebook)
.topics.topic(editing.actionAfterFirstSave.id)
.has(item.id);
2020-01-22 02:49:29 +05:00
2020-01-11 23:05:39 +05:00
useEffect(() => {
2021-06-14 08:37:38 +05:00
if (item.id === null) return;
sleep(1000).then(() => {
2020-04-18 13:49:24 +05:00
setNote({...item});
2020-11-25 18:49:21 +05:00
if (item.type !== note) {
2020-11-26 11:32:30 +05:00
setIsPinnedToMenu(db.settings.isPinned(note.id));
2020-11-25 18:49:21 +05:00
}
2021-06-14 08:37:38 +05:00
});
2020-01-11 23:05:39 +05:00
}, [item]);
2021-06-14 08:37:38 +05:00
function changeColorScheme(colors = COLOR_SCHEME, accent = ACCENT) {
let newColors = setColorScheme(colors, accent);
dispatch({type: Actions.THEME, colors: newColors});
}
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;
2021-06-14 08:37:38 +05:00
let _item;
2020-02-02 23:50:55 +05:00
2020-01-10 18:44:41 +05:00
switch (type) {
case 'note': {
2021-06-14 08:37:38 +05:00
_item = db.notes.note(note.id)?.data;
2020-01-10 18:44:41 +05:00
break;
}
case 'notebook': {
2021-06-14 08:37:38 +05:00
_item = db.notebooks.notebook(note.id)?.data;
2020-01-10 18:44:41 +05:00
break;
}
case 'topic': {
2021-06-14 08:37:38 +05:00
_item = db.notebooks.notebook(note.notebookId).topics.topic(note.title);
2020-01-10 18:44:41 +05:00
break;
}
}
2021-06-14 08:37:38 +05:00
if (!_item || !_item.id) return;
2020-01-20 15:32:32 +05:00
2020-01-20 10:33:36 +05:00
if (!nodispatch) {
2021-06-05 21:10:20 +05:00
Navigation.setRoutesToUpdate([
2021-06-14 08:37:38 +05:00
Navigation.routeNames.NotesPage,
Navigation.routeNames.Favorites,
Navigation.routeNames.Notes,
Navigation.routeNames.Notebooks,
Navigation.routeNames.Notebook,
Navigation.routeNames.Tags,
Navigation.routeNames.Trash,
]);
2020-01-20 10:33:36 +05:00
}
2021-06-05 21:10:20 +05:00
2021-06-14 08:37:38 +05:00
setNote({..._item});
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: () => {
close();
2021-06-05 21:10:20 +05:00
clearSelection();
setSelectedItem(item);
2020-09-14 17:10:02 +05:00
setTimeout(() => {
2020-12-15 14:14:19 +05:00
eSendEvent(eOpenMoveNoteDialog, note);
}, 300);
2020-01-10 18:44:41 +05:00
},
},
{
name: 'Share',
2020-02-12 03:24:36 +05:00
icon: 'share-variant',
2020-12-01 16:36:19 +05:00
func: async () => {
2020-01-29 17:38:50 +05:00
if (note.locked) {
close();
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,
2021-02-20 15:03:02 +05:00
title: 'Share note',
description: 'Unlock note to share it.',
2020-11-20 01:23:05 +05:00
});
2020-01-29 17:38:50 +05:00
} else {
2020-12-01 16:36:19 +05:00
let text = await db.notes.note(note.id).export('txt');
let m = `${note.title}\n \n ${text}`;
2020-01-29 17:38:50 +05:00
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
},
},
2021-06-14 08:37:38 +05:00
{
name: 'Edit Notebook',
icon: 'square-edit-outline',
func: () => {
close('notebook');
},
},
{
name: 'Edit Topic',
icon: 'square-edit-outline',
func: () => {
close('topic');
},
},
2020-01-10 18:44:41 +05:00
{
name: 'Delete',
2021-06-14 08:37:38 +05:00
title:
note.type !== 'notebook' && note.type !== 'note'
? 'Delete ' + item.type
: 'Move to trash',
icon: 'delete-outline',
type: 'error',
2020-11-14 10:09:41 +05:00
func: async () => {
close();
if (note.locked) {
await sleep(300);
openVault({
deleteNote: true,
novault: true,
locked: true,
item: note,
2021-02-20 15:03:02 +05:00
title: 'Delete note',
description: 'Unlock note to delete it.',
});
} else {
try {
close();
await deleteItems(note);
2021-06-14 08:37:38 +05:00
} catch (e) {}
2020-11-14 10:09:41 +05:00
}
},
2020-01-10 18:44:41 +05:00
},
2020-02-03 12:18:45 +05:00
{
2020-09-14 13:14:07 +05:00
name: 'Copy',
icon: 'content-copy',
func: async () => {
2020-12-07 11:26:30 +05:00
if (note.locked) {
2020-12-10 15:26:02 +05:00
openVault({
copyNote: true,
novault: true,
locked: true,
item: note,
2021-02-20 15:03:02 +05:00
title: 'Copy note',
description: 'Unlock note to copy to clipboard.',
2020-12-10 15:26:02 +05:00
});
2020-12-07 11:26:30 +05:00
} else {
2020-12-10 15:26:02 +05:00
let text = await db.notes.note(note.id).content();
text = toTXT(text);
text = `${note.title}\n \n ${text}`;
Clipboard.setString(text);
2021-02-20 15:03:02 +05:00
ToastEvent.show({
heading: 'Note copied to clipboard',
type: 'success',
context: 'local',
});
2020-12-07 11:26:30 +05:00
}
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 () => {
close();
2020-12-16 11:35:40 +05:00
await db.trash.restore(note.id);
2021-02-16 16:11:10 +05:00
Navigation.setRoutesToUpdate([
Navigation.routeNames.Tags,
Navigation.routeNames.Notes,
Navigation.routeNames.Notebooks,
Navigation.routeNames.NotesPage,
Navigation.routeNames.Favorites,
2021-02-20 15:03:02 +05:00
Navigation.routeNames.Trash,
]);
2021-01-01 15:40:12 +05:00
type = note.type === 'trash' ? note.itemType : note.type;
2021-02-20 15:03:02 +05:00
ToastEvent.show({
heading:
type === 'note'
? 'Note restored from trash'
: 'Notebook restored from trash',
type: 'success',
});
2020-01-10 18:44:41 +05:00
},
},
{
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
},
},
2021-06-14 08:37:38 +05:00
{
name: 'Publish',
icon: 'link-box-outline',
func: async () => {
close();
await sleep(300);
2021-06-14 10:01:44 +05:00
eSendEvent(eOpenPublishNoteDialog, note);
2021-06-14 08:37:38 +05:00
},
},
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,
id: notesnook.ids.dialogs.actionsheet.night,
2020-01-10 18:44:41 +05:00
},
2021-06-14 08:37:38 +05:00
{
name: 'Vault',
title: note.locked ? 'Remove from vault' : 'Add to vault',
icon: note.locked ? 'shield-off-outline' : 'shield-outline',
func: async () => {
if (!note.id) return;
if (note.locked) {
close('unlock');
} else {
db.vault
.add(note.id)
.then(r => {
let n = db.notes.note(note.id).data;
if (n.locked) {
close();
}
Navigation.setRoutesToUpdate([
Navigation.routeNames.NotesPage,
Navigation.routeNames.Favorites,
Navigation.routeNames.Notes,
]);
localRefresh(note.type);
})
.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:
close();
break;
}
});
}
},
on: note.locked,
},
2020-01-10 18:44:41 +05:00
{
name: 'Pin',
2021-06-14 08:37:38 +05:00
title: note.pinned ? 'Unpin from top' : 'Pin to top',
icon: note.pinned ? 'pin-off-outline' : 'pin-outline',
2020-02-01 12:56:30 +05:00
func: async () => {
2020-12-15 14:16:47 +05:00
if (!note.id) return;
close();
2020-12-15 14:16:47 +05:00
if (note.type === 'note') {
2020-12-31 12:04:00 +05:00
if (db.notes.pinned.length === 3 && !note.pinned) {
2021-02-20 15:03:02 +05:00
ToastEvent.show({
heading: 'Cannot pin more than 3 notes',
type: 'error',
context: 'local',
});
2020-12-15 14:16:47 +05:00
return;
}
await db.notes.note(note.id).pin();
} else {
2020-12-31 12:04:00 +05:00
if (db.notebooks.pinned.length === 3 && !note.pinned) {
2021-02-20 15:03:02 +05:00
ToastEvent.show({
heading: 'Cannot pin more than 3 notebooks',
type: 'error',
context: 'local',
});
2020-12-15 14:16:47 +05:00
return;
}
await db.notebooks.notebook(note.id).pin();
}
localRefresh(item.type);
2020-01-10 18:44:41 +05:00
},
close: false,
check: true,
on: note.pinned,
2021-01-08 12:52:55 +05:00
nopremium: true,
id: notesnook.ids.dialogs.actionsheet.pin,
2020-01-10 18:44:41 +05:00
},
{
name: 'Favorite',
2021-06-14 08:37:38 +05:00
title: !note.favorite ? 'Add to favorites' : 'Remove from favorites',
icon: note.favorite ? 'star-off' : 'star-outline',
2020-02-01 12:56:30 +05:00
func: async () => {
2020-02-06 13:08:35 +05:00
if (!note.id) return;
close();
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
}
2021-06-02 17:34:39 +05:00
Navigation.setRoutesToUpdate([
Navigation.routeNames.NotesPage,
Navigation.routeNames.Favorites,
Navigation.routeNames.Notes,
]);
2020-10-31 16:32:21 +05:00
localRefresh(item.type, true);
2020-01-10 18:44:41 +05:00
},
close: false,
check: true,
on: note.favorite,
2021-01-08 12:52:55 +05:00
nopremium: true,
id: notesnook.ids.dialogs.actionsheet.favorite,
color: 'orange',
2020-01-10 18:44:41 +05:00
},
2020-11-25 18:49:21 +05:00
{
2021-06-14 08:37:38 +05:00
name: 'Add Shortcut to Menu',
title: isPinnedToMenu ? 'Remove Shortcut' : 'Add Shortcut to Menu',
2021-02-20 15:03:02 +05:00
icon: isPinnedToMenu ? 'link-variant-remove' : 'link-variant',
2020-11-25 18:49:21 +05:00
func: async () => {
close();
2020-11-25 18:49:21 +05:00
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, {
2020-11-26 11:32:30 +05:00
id: note.id,
notebookId: note.notebookId,
2020-11-25 18:49:21 +05:00
});
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-26 11:32:30 +05:00
setIsPinnedToMenu(db.settings.isPinned(note.id));
2021-06-05 21:10:20 +05:00
setMenuPins();
2020-11-25 18:49:21 +05:00
} catch (e) {}
},
close: false,
check: true,
on: isPinnedToMenu,
2021-01-08 12:52:55 +05:00
nopremium: true,
id: notesnook.ids.dialogs.actionsheet.pinMenu,
2020-11-25 18:49:21 +05:00
},
2021-06-14 08:37:38 +05:00
{
name: 'RemoveTopic',
title: 'Remove from topic',
hidden: !noteInTopic,
2021-06-14 10:01:44 +05:00
icon: 'minus-circle-outline',
2021-06-14 08:37:38 +05:00
func: async () => {
await db.notebooks
.notebook(editing.actionAfterFirstSave.notebook)
.topics.topic(editing.actionAfterFirstSave.id)
.delete(note.id);
Navigation.setRoutesToUpdate([
Navigation.routeNames.Notebooks,
Navigation.routeNames.Notes,
Navigation.routeNames.NotesPage,
Navigation.routeNames.Notebook,
]);
setNote(db.notes.note(note.id).data);
close();
},
},
{
name: 'Delete',
title:
note.type !== 'notebook' && note.type !== 'note'
? 'Delete ' + item.type
: 'Move to trash',
icon: 'delete-outline',
type: 'error',
func: async () => {
close();
if (note.locked) {
await sleep(300);
openVault({
deleteNote: true,
novault: true,
locked: true,
item: note,
title: 'Delete note',
description: 'Unlock note to delete it.',
});
} else {
try {
close();
await deleteItems(note);
} catch (e) {}
}
},
},
2020-01-10 18:44:41 +05:00
];
2021-06-14 10:01:44 +05:00
const isFullWidthButton = index => {
let filtered = columnItemsData.filter(
i => columnItems.indexOf(i.name) > -1 && !i.hidden,
);
let colLength = filtered.length;
if (colLength % 2 === 0) return false;
if (index === colLength - 1) return true;
};
const _renderRowItem = rowItem => (
<TouchableOpacity
onPress={rowItem.func}
key={rowItem.name}
testID={'icon-' + rowItem.name}
style={{
alignItems: 'center',
width: DDS.isTab
? (400 - 24) / rowItems.length
: (w - 25) / rowItems.length,
}}>
<Icon
2020-01-16 19:53:16 +05:00
style={{
2021-06-14 10:01:44 +05:00
width: 50,
height: 40,
borderRadius: 100,
justifyContent: 'center',
2020-01-16 19:53:16 +05:00
alignItems: 'center',
2021-06-14 10:01:44 +05:00
textAlign: 'center',
textAlignVertical: 'center',
marginBottom: DDS.isTab ? 7 : 3.5,
}}
name={rowItem.icon}
size={DDS.isTab ? SIZE.xl : SIZE.lg}
color={rowItem.name === 'Delete' ? colors.errorText : colors.accent}
/>
<Paragraph>{rowItem.name}</Paragraph>
</TouchableOpacity>
);
2020-01-16 19:53:16 +05:00
2021-06-14 08:37:38 +05:00
const _renderColumnItem = (item, index) =>
2021-06-14 10:01:44 +05:00
item.hidden ? null : (
<Button
key={item.title}
title={item.title}
type={item.type ? item.type : item.on ? 'accent' : 'shade'}
onPress={item.func}
style={{
marginTop: 12,
}}
width={isFullWidthButton(index) ? '100%' : '48%'}
icon={item.icon}
height={50}
/>
);
2020-11-02 20:45:11 +05:00
2020-12-19 14:26:44 +05:00
const onScrollEnd = () => {
2020-12-29 17:19:32 +05:00
getRef().current?.handleChildScrollEnd();
2020-12-19 14:26:44 +05:00
};
2020-01-09 20:14:51 +05:00
return (
2020-12-19 13:15:34 +05:00
<ScrollView
2020-12-19 14:26:44 +05:00
nestedScrollEnabled
onScrollEndDrag={onScrollEnd}
onScrollAnimationEnd={onScrollEnd}
onMomentumScrollEnd={onScrollEnd}
2020-12-31 12:16:28 +05:00
keyboardShouldPersistTaps="always"
keyboardDismissMode="none"
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={{
backgroundColor: colors.bg,
2020-01-24 18:48:33 +05:00
paddingHorizontal: 0,
2020-12-19 14:26:44 +05:00
borderBottomRightRadius: DDS.isLargeTablet() ? 10 : 1,
borderBottomLeftRadius: DDS.isLargeTablet() ? 10 : 1,
2020-01-10 18:44:41 +05:00
}}>
2020-12-15 14:14:19 +05:00
<TouchableOpacity
style={{
width: '100%',
height: '100%',
position: 'absolute',
}}
onPress={() => {
Keyboard.dismiss();
}}
/>
2020-12-31 13:44:34 +05:00
{!note || !note.id ? (
2020-12-31 12:04:00 +05:00
<Paragraph style={{marginVertical: 10, alignSelf: 'center'}}>
2020-11-09 20:26:20 +05:00
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',
marginTop: 5,
2021-04-29 10:45:46 +05:00
zIndex: 10,
2020-04-18 13:49:24 +05:00
}}>
<Heading
2020-04-18 13:49:24 +05:00
style={{
2021-04-29 10:45:46 +05:00
maxWidth: '90%',
textAlign: 'center',
}}
size={SIZE.md}>
2021-06-14 10:01:44 +05:00
{note.type === 'tag' ? '#' : null}
{note?.title.replace('\n', '')}
</Heading>
{note.headline || note.description ? (
<Paragraph
numberOfLines={2}
style={{
2021-04-29 10:45:46 +05:00
width: '90%',
textAlign: 'center',
2021-04-29 10:45:46 +05:00
maxWidth: '90%',
}}>
{note.type === 'notebook' && note.description
? note.description
: null}
{note.type === 'note' && note.headline
? note.headline[item.headline.length - 1] === '\n'
? note.headline.slice(0, note.headline.length - 1)
: note.headline
: null}
</Paragraph>
) : null}
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,
}}>
2021-06-14 10:01:44 +05:00
{note.dateEdited
2020-04-18 13:49:24 +05:00
? 'Last edited on ' + timeConverter(note.dateEdited)
: null}
2021-06-14 10:01:44 +05:00
{note.dateCreated && !note.dateDeleted
? 'Last edited on ' + timeConverter(note.dateCreated)
2020-04-18 13:49:24 +05:00
: 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' && (
2020-04-18 13:49:24 +05:00
<View
style={{
2020-04-18 13:49:24 +05:00
flexDirection: 'row',
alignItems: 'center',
justifyContent: 'center',
width: '90%',
maxWidth: '90%',
2020-04-18 13:49:24 +05:00
flexWrap: 'wrap',
2020-02-03 12:21:38 +05:00
}}>
{note && note.topics && note.topics.length > 0
? note.topics
.slice()
.sort((a, b) => a.dateEdited - b.dateEdited)
.slice(0, 6)
2021-04-18 00:46:31 +05:00
.map(topic => (
<View
key={topic.id}
2020-02-03 12:21:38 +05:00
style={{
borderRadius: 2.5,
backgroundColor: colors.accent,
paddingHorizontal: 5,
paddingVertical: 2,
marginRight: 5,
marginVertical: 2.5,
2020-02-03 12:21:38 +05:00
}}>
<Paragraph
size={SIZE.xs}
numberOfLines={1}
color="white"
style={{
maxWidth: '100%',
}}>
{topic.title.length > 16
? topic.title.slice(0, 16) + '...'
: topic.title}
</Paragraph>
</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-12-10 15:26:02 +05:00
<TouchableOpacity
activeOpacity={0.9}
2020-12-01 22:52:01 +05:00
testID={notesnook.ids.dialogs.actionsheet.sync}
2021-06-14 08:37:38 +05:00
onPress={async () => await Sync.run('local')}
2020-04-18 13:49:24 +05:00
style={{
borderColor: colors.accent,
paddingHorizontal: 5,
2020-12-16 20:00:17 +05:00
borderRadius: 2.5,
2020-12-10 15:26:02 +05:00
justifyContent: 'center',
alignItems: 'center',
marginTop: 5,
borderWidth: 1,
2020-12-16 20:00:17 +05:00
height: 18,
2020-04-18 13:49:24 +05:00
}}>
2020-12-10 15:26:02 +05:00
<Paragraph
color={colors.accent}
size={SIZE.xs}
style={{
textAlignVertical: 'center',
textAlign: 'center',
}}>
2021-04-29 10:45:46 +05:00
{user && lastSynced > note.dateEdited ? 'Synced' : 'Sync Now'}
2020-12-10 15:26:02 +05:00
</Paragraph>
</TouchableOpacity>
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
}}>
2021-06-14 10:01:44 +05:00
{rowItemsData
.filter(i => rowItems.indexOf(i.name) > -1)
.map(_renderRowItem)}
2020-01-29 18:20:54 +05:00
</View>
) : 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
2020-12-31 13:42:53 +05:00
{hasTags && note ? (
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 ? (
2021-06-14 08:37:38 +05:00
<View
style={{
paddingHorizontal: 12,
flexDirection: 'row',
justifyContent: 'space-between',
flexWrap: 'wrap',
marginTop: 6,
}}>
2021-06-14 10:01:44 +05:00
{columnItemsData
.filter(i => columnItems.indexOf(i.name) > -1 && !i.hidden)
.map(_renderColumnItem)}
2021-06-14 08:37:38 +05:00
</View>
2020-01-10 18:44:41 +05:00
) : null}
2020-01-24 18:48:33 +05:00
2021-04-29 10:45:46 +05:00
{note.type === 'note' && user && lastSynced >= note.dateEdited ? (
<PressableButton
type="shade"
customStyle={{
borderWidth: 1,
borderRadius: 5,
paddingVertical: 10,
width: '95%',
alignItems: 'flex-start',
paddingHorizontal: 12,
marginTop: 25,
borderColor: colors.accent,
flexDirection: 'row',
justifyContent: 'flex-start',
}}>
2021-06-14 08:37:38 +05:00
<Icon name="shield-key-outline" color={colors.accent} size={40} />
<View
style={{
flex: 1,
2021-06-14 08:37:38 +05:00
marginLeft: 5,
}}>
<Heading
color={colors.accent}
style={{
fontSize: SIZE.md,
}}>
2021-04-29 10:45:46 +05:00
This note is encrypted and synced
</Heading>
<Paragraph
style={{
flexWrap: 'wrap',
flexBasis: 1,
}}
color={colors.accent}>
No one can read it except you.
</Paragraph>
</View>
</PressableButton>
) : null}
2020-01-24 18:48:33 +05:00
{DDS.isTab ? (
<View
style={{
height: 20,
}}
/>
) : null}
2020-12-19 13:15:34 +05:00
</ScrollView>
2020-01-09 20:14:51 +05:00
);
};