Files
notesnook/apps/mobile/app/hooks/use-actions.js

890 lines
23 KiB
JavaScript
Raw Normal View History

/*
This file is part of the Notesnook project (https://notesnook.com/)
2023-01-16 13:44:52 +05:00
Copyright (C) 2023 Streetwriters (Private) Limited
This program is free software: you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation, either version 3 of the License, or
(at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
2022-08-30 16:13:11 +05:00
import Clipboard from "@react-native-clipboard/clipboard";
2022-09-16 16:02:40 +05:00
import React, { useCallback, useEffect, useState } from "react";
import { Platform } from "react-native";
import Share from "react-native-share";
2022-08-29 16:19:17 +05:00
import { db } from "../common/database";
2023-03-16 21:22:21 +05:00
import { AttachmentDialog } from "../components/attachments";
import { presentDialog } from "../components/dialog/functions";
import NoteHistory from "../components/note-history";
2023-03-16 21:22:21 +05:00
import { AddNotebookSheet } from "../components/sheets/add-notebook";
import MoveNoteSheet from "../components/sheets/add-to";
2022-09-16 16:02:40 +05:00
import ExportNotesSheet from "../components/sheets/export-notes";
import { MoveNotes } from "../components/sheets/move-notes/movenote";
2023-03-16 21:22:21 +05:00
import PublishNoteSheet from "../components/sheets/publish-note";
import { RelationsList } from "../components/sheets/relations-list/index";
2022-11-18 17:30:29 +05:00
import ReminderSheet from "../components/sheets/reminder";
2022-02-28 13:48:59 +05:00
import {
eSendEvent,
eSubscribeEvent,
eUnSubscribeEvent,
openVault,
presentSheet,
ToastEvent
} from "../services/event-manager";
import Navigation from "../services/navigation";
import Notifications from "../services/notifications";
import { useEditorStore } from "../stores/use-editor-store";
import { useMenuStore } from "../stores/use-menu-store";
2022-08-29 16:19:17 +05:00
import useNavigationStore from "../stores/use-navigation-store";
2023-03-16 21:22:21 +05:00
import { useRelationStore } from "../stores/use-relation-store";
import { useSelectionStore } from "../stores/use-selection-store";
import { useTagStore } from "../stores/use-tag-store";
import { useThemeStore } from "../stores/use-theme-store";
import { useUserStore } from "../stores/use-user-store";
2023-06-10 12:17:23 +05:00
import { convertNoteToText } from "../utils/note-to-text";
import { toggleDarkMode } from "../utils/color-scheme/utils";
import {
eOnTopicSheetUpdate,
eOpenAddTopicDialog,
eOpenLoginDialog
} from "../utils/events";
import { deleteItems } from "../utils/functions";
import { sleep } from "../utils/time";
2022-02-28 13:48:59 +05:00
2022-08-04 18:12:27 +05:00
export const useActions = ({ close = () => null, item }) => {
const colors = useThemeStore((state) => state.colors);
const clearSelection = useSelectionStore((state) => state.clearSelection);
const setSelectedItem = useSelectionStore((state) => state.setSelectedItem);
const setMenuPins = useMenuStore((state) => state.setMenuPins);
const [isPinnedToMenu, setIsPinnedToMenu] = useState(
2022-09-08 14:24:31 +05:00
db.shortcuts.exists(item.id)
);
const user = useUserStore((state) => state.user);
2022-02-28 13:48:59 +05:00
const [notifPinned, setNotifPinned] = useState(null);
2022-07-08 20:54:55 +05:00
const alias = item.alias || item.title;
2023-06-01 20:56:02 +05:00
const [defaultNotebook, setDefaultNotebook] = useState(
db.settings.getDefaultNotebook()
);
2022-02-28 13:48:59 +05:00
const isPublished =
item.type === "note" && db.monographs.isPublished(item.id);
2022-02-28 13:48:59 +05:00
useEffect(() => {
if (item.id === null) return;
checkNotifPinned();
if (item.type !== "note") {
2022-09-08 14:24:31 +05:00
setIsPinnedToMenu(db.shortcuts.exists(item.id));
2022-02-28 13:48:59 +05:00
}
2022-08-30 18:27:09 +05:00
}, [checkNotifPinned, item]);
2022-02-28 13:48:59 +05:00
2022-08-30 18:27:09 +05:00
const checkNotifPinned = useCallback(() => {
2022-02-28 13:48:59 +05:00
let pinned = Notifications.getPinnedNotes();
if (!pinned) {
setNotifPinned(null);
return;
}
let index = pinned.findIndex((notif) => notif.id === item.id);
2022-02-28 13:48:59 +05:00
if (index !== -1) {
setNotifPinned(pinned[index]);
} else {
setNotifPinned(null);
}
2022-08-30 18:27:09 +05:00
}, [item.id]);
2022-02-28 13:48:59 +05:00
const isNoteInTopic = () => {
2022-08-04 18:12:27 +05:00
const currentScreen = useNavigationStore.getState().currentScreen;
if (item.type !== "note" || currentScreen.name !== "TopicNotes") return;
return (
db.notes?.topicReferences?.get(currentScreen.id)?.indexOf(item.id) > -1
);
};
const isNoteInNotebook = () => {
const currentScreen = useNavigationStore.getState().currentScreen;
if (item.type !== "note" || currentScreen.name !== "Notebook") return;
return !!db.relations
.to(item, "notebook")
.find((notebook) => notebook.id === currentScreen.id);
};
2022-08-30 18:27:09 +05:00
const onUpdate = useCallback(
async (type) => {
if (type === "unpin") {
await sleep(1000);
await Notifications.get();
checkNotifPinned();
}
},
[checkNotifPinned]
);
2022-02-28 13:48:59 +05:00
useEffect(() => {
eSubscribeEvent("onUpdate", onUpdate);
2022-02-28 13:48:59 +05:00
return () => {
eUnSubscribeEvent("onUpdate", onUpdate);
2022-02-28 13:48:59 +05:00
};
2022-08-30 18:27:09 +05:00
}, [item, onUpdate]);
2022-02-28 13:48:59 +05:00
function switchTheme() {
2022-03-03 15:09:30 +05:00
toggleDarkMode();
2022-02-28 13:48:59 +05:00
}
function addTo() {
clearSelection(true);
setSelectedItem(item);
2023-03-16 21:22:21 +05:00
MoveNoteSheet.present(item);
2022-02-28 13:48:59 +05:00
}
async function addToFavorites() {
if (!item.id) return;
close();
await db.notes.note(item.id).favorite();
2023-04-01 14:06:16 +05:00
Navigation.queueRoutesForUpdate();
2022-02-28 13:48:59 +05:00
}
async function pinItem() {
if (!item.id) return;
close();
let type = item.type;
await db[`${type}s`][type](item.id).pin();
2023-04-01 14:06:16 +05:00
Navigation.queueRoutesForUpdate();
2022-02-28 13:48:59 +05:00
}
async function pinToNotifications() {
if (!checkNoteSynced()) return;
if (Platform.OS === "ios") return;
2022-02-28 13:48:59 +05:00
if (notifPinned !== null) {
Notifications.remove(item.id, notifPinned.identifier);
await sleep(1000);
await Notifications.get();
checkNotifPinned();
return;
}
2023-04-07 02:20:17 +05:00
if (item.locked) {
ToastEvent.show({
heading: "Note is locked",
type: "error",
message: "Locked notes cannot be pinned to notifications",
context: "local"
});
return;
}
2023-06-10 12:17:23 +05:00
let text = await convertNoteToText(item, false);
2023-04-07 02:07:36 +05:00
let html = text.replace(/\n/g, "<br />");
Notifications.displayNotification({
2022-02-28 13:48:59 +05:00
title: item.title,
message: item.headline || text,
subtitle: item.headline || text,
bigText: html,
2022-02-28 13:48:59 +05:00
ongoing: true,
actions: ["UNPIN"],
id: item.id
2022-02-28 13:48:59 +05:00
});
await sleep(1000);
await Notifications.get();
checkNotifPinned();
}
async function restoreTrashItem() {
if (!checkNoteSynced()) return;
2022-02-28 13:48:59 +05:00
close();
await db.trash.restore(item.id);
2023-04-01 14:06:16 +05:00
Navigation.queueRoutesForUpdate();
let type = item.type === "trash" ? item.itemType : item.type;
2022-02-28 13:48:59 +05:00
ToastEvent.show({
heading:
type === "note"
? "Note restored from trash"
: "Notebook restored from trash",
type: "success"
2022-02-28 13:48:59 +05:00
});
}
async function copyContent() {
if (!checkNoteSynced()) return;
2022-02-28 13:48:59 +05:00
if (item.locked) {
close();
await sleep(300);
openVault({
copyNote: true,
novault: true,
locked: true,
item: item,
title: "Copy note",
description: "Unlock note to copy to clipboard."
2022-02-28 13:48:59 +05:00
});
} else {
2023-06-10 12:17:23 +05:00
Clipboard.setString(await convertNoteToText(item));
2022-02-28 13:48:59 +05:00
ToastEvent.show({
heading: "Note copied to clipboard",
type: "success",
context: "local"
2022-02-28 13:48:59 +05:00
});
}
}
async function publishNote() {
if (!checkNoteSynced()) return;
2022-02-28 13:48:59 +05:00
if (!user) {
ToastEvent.show({
heading: "Login required",
message: "Login to publish note",
context: "local",
2022-02-28 13:48:59 +05:00
func: () => {
2022-07-06 12:17:08 +05:00
eSendEvent(eOpenLoginDialog);
2022-02-28 13:48:59 +05:00
},
actionText: "Login"
2022-02-28 13:48:59 +05:00
});
return;
}
2022-03-09 13:50:50 +05:00
if (!user?.isEmailConfirmed) {
2022-02-28 13:48:59 +05:00
ToastEvent.show({
heading: "Email is not verified",
message: "Please verify your email first.",
context: "local"
2022-02-28 13:48:59 +05:00
});
return;
}
if (item.locked) {
ToastEvent.show({
heading: "Locked notes cannot be published",
type: "error",
context: "local"
2022-02-28 13:48:59 +05:00
});
return;
}
2023-03-16 21:22:21 +05:00
PublishNoteSheet.present(item);
2022-02-28 13:48:59 +05:00
}
const checkNoteSynced = () => {
2022-09-22 11:55:14 +05:00
if (!user) return true;
if (item.type !== "note" || item.itemType !== "note") return true;
let isTrash = item.itemType === "note";
2022-04-01 14:52:40 +05:00
if (!isTrash && !db.notes.note(item.id).synced()) {
ToastEvent.show({
context: "local",
heading: "Note not synced",
message: "Please run sync before making changes",
type: "error"
});
return false;
}
2022-04-01 14:52:40 +05:00
if (isTrash && !db.trash.synced(item.id)) {
ToastEvent.show({
context: "local",
heading: "Note not synced",
message: "Please run sync before making changes",
type: "error"
2022-04-01 14:52:40 +05:00
});
return false;
}
return true;
};
2022-02-28 13:48:59 +05:00
async function addToVault() {
if (!item.id) return;
if (!checkNoteSynced()) return;
2022-02-28 13:48:59 +05:00
if (item.locked) {
close();
await sleep(300);
openVault({
item: item,
novault: true,
locked: true,
permanant: true,
title: "Unlock note",
description: "Remove note from the vault."
2022-02-28 13:48:59 +05:00
});
return;
}
try {
await db.vault.add(item.id);
let note = db.notes.note(item.id).data;
if (note.locked) {
close();
2023-04-01 14:06:16 +05:00
Navigation.queueRoutesForUpdate();
2022-02-28 13:48:59 +05:00
}
} catch (e) {
close();
await sleep(300);
switch (e.message) {
case db.vault.ERRORS.noVault:
openVault({
item: item,
novault: false,
title: "Create vault",
description: "Set a password to create a vault and lock note."
2022-02-28 13:48:59 +05:00
});
break;
case db.vault.ERRORS.vaultLocked:
openVault({
item: item,
novault: true,
locked: true,
title: "Lock note",
description: "Give access to vault to lock this note."
2022-02-28 13:48:59 +05:00
});
break;
}
}
}
async function createMenuShortcut() {
close();
try {
if (isPinnedToMenu) {
2022-09-08 14:24:31 +05:00
await db.shortcuts.remove(item.id);
2022-02-28 13:48:59 +05:00
} else {
if (item.type === "topic") {
2022-09-08 14:24:31 +05:00
await db.shortcuts.add({
item: {
type: "topic",
id: item.id,
notebookId: item.notebookId
}
2022-02-28 13:48:59 +05:00
});
} else {
2022-09-08 14:24:31 +05:00
await db.shortcuts.add({
item: {
type: item.type,
id: item.id
}
});
2022-02-28 13:48:59 +05:00
}
}
2022-09-08 14:24:31 +05:00
setIsPinnedToMenu(db.shortcuts.exists(item.id));
2022-02-28 13:48:59 +05:00
setMenuPins();
} catch (e) {
2022-09-08 14:24:31 +05:00
console.error("error", e);
}
2022-02-28 13:48:59 +05:00
}
async function renameTag() {
close();
await sleep(300);
presentDialog({
title: "Rename tag",
paragraph: "Change the title of the tag " + alias,
positivePress: async (value) => {
if (!value || value === "" || value.trimStart().length == 0) return;
2022-02-28 13:48:59 +05:00
await db.tags.rename(item.id, db.tags.sanitize(value));
setTimeout(() => {
useTagStore.getState().setTags();
useMenuStore.getState().setMenuPins();
Navigation.queueRoutesForUpdate();
useRelationStore.getState().update();
}, 1);
2022-02-28 13:48:59 +05:00
},
input: true,
defaultValue: alias,
inputPlaceholder: "Enter title of tag",
positiveText: "Save"
2022-02-28 13:48:59 +05:00
});
}
async function shareNote() {
if (!checkNoteSynced()) return;
2022-02-28 13:48:59 +05:00
if (item.locked) {
close();
await sleep(300);
openVault({
item: item,
novault: true,
locked: true,
share: true,
title: "Share note",
description: "Unlock note to share it."
2022-02-28 13:48:59 +05:00
});
} else {
Share.open({
title: "Share note to",
2022-02-28 13:48:59 +05:00
failOnCancel: false,
2023-06-10 12:17:23 +05:00
message: await convertNoteToText(item)
2022-02-28 13:48:59 +05:00
});
}
}
async function deleteItem() {
if (!checkNoteSynced()) return;
2022-02-28 13:48:59 +05:00
close();
2022-11-18 17:30:29 +05:00
if (item.type === "tag" || item.type === "reminder") {
2022-02-28 13:48:59 +05:00
await sleep(300);
presentDialog({
2022-11-18 17:30:29 +05:00
title: `Delete ${item.type}`,
paragraph:
item.type === "reminder"
? "This reminder will be removed"
: "This tag will be removed from all notes.",
positivePress: async () => {
2022-11-18 17:30:29 +05:00
if (item.type === "reminder") {
await db.reminders.remove(item.id);
} else {
await db.tags.remove(item.id);
}
setImmediate(() => {
useTagStore.getState().setTags();
Navigation.queueRoutesForUpdate();
useRelationStore.getState().update();
});
2022-02-28 13:48:59 +05:00
},
positiveText: "Delete",
positiveType: "errorShade"
2022-02-28 13:48:59 +05:00
});
return;
}
2022-11-18 17:30:29 +05:00
2022-02-28 13:48:59 +05:00
if (item.locked) {
await sleep(300);
openVault({
deleteNote: true,
novault: true,
locked: true,
item: item,
title: "Delete note",
description: "Unlock note to delete it."
2022-02-28 13:48:59 +05:00
});
} else {
try {
close();
await sleep(300);
2022-02-28 13:48:59 +05:00
await deleteItems(item);
} catch (e) {
console.error(e);
}
2022-02-28 13:48:59 +05:00
}
}
async function removeNoteFromTopic() {
2022-08-04 18:12:27 +05:00
const currentScreen = useNavigationStore.getState().currentScreen;
if (currentScreen.name !== "TopicNotes") return;
await db.notes.removeFromNotebook(
{
id: currentScreen.notebookId,
topic: currentScreen.id
},
item.id
);
2023-04-01 14:06:16 +05:00
Navigation.queueRoutesForUpdate();
eSendEvent(eOnTopicSheetUpdate);
2022-02-28 13:48:59 +05:00
close();
}
async function removeNoteFromNotebook() {
const currentScreen = useNavigationStore.getState().currentScreen;
if (currentScreen.name !== "Notebook") return;
await db.relations.unlink({ type: "notebook", id: currentScreen.id }, item);
2023-04-01 14:06:16 +05:00
Navigation.queueRoutesForUpdate();
close();
}
2022-02-28 13:48:59 +05:00
async function deleteTrashItem() {
if (!checkNoteSynced()) return;
2022-02-28 13:48:59 +05:00
close();
await sleep(300);
presentDialog({
title: "Permanent delete",
2022-02-28 13:48:59 +05:00
paragraph: `Are you sure you want to delete this ${item.itemType} permanantly from trash?`,
positiveText: "Delete",
negativeText: "Cancel",
2022-02-28 13:48:59 +05:00
positivePress: async () => {
await db.trash.delete(item.id);
setImmediate(() => {
Navigation.queueRoutesForUpdate();
useSelectionStore.getState().setSelectionMode(false);
ToastEvent.show({
heading: "Permanantly deleted items",
type: "success",
context: "local"
});
2022-02-28 13:48:59 +05:00
});
},
positiveType: "errorShade"
2022-02-28 13:48:59 +05:00
});
}
async function openHistory() {
presentSheet({
component: (ref) => <NoteHistory fwdRef={ref} note={item} />
2022-02-28 13:48:59 +05:00
});
}
async function showAttachments() {
2023-04-28 21:59:15 +05:00
AttachmentDialog.present(item);
2022-02-28 13:48:59 +05:00
}
async function exportNote() {
2023-04-07 02:20:17 +05:00
if (item.locked) {
ToastEvent.show({
heading: "Note is locked",
type: "error",
message: "Locked notes cannot be exported",
context: "local"
});
return;
}
2022-10-14 17:44:35 +05:00
ExportNotesSheet.present([item]);
2022-02-28 13:48:59 +05:00
}
2022-03-14 16:28:54 +05:00
async function toggleLocalOnly() {
if (!checkNoteSynced() || !user) return;
2022-03-14 16:28:54 +05:00
db.notes.note(item.id).localOnly();
2023-04-01 14:06:16 +05:00
Navigation.queueRoutesForUpdate();
2022-03-14 16:28:54 +05:00
close();
}
2022-02-28 13:48:59 +05:00
const toggleReadyOnlyMode = async () => {
await db.notes.note(item.id).readonly();
let current = db.notes.note(item.id).data.readonly;
if (useEditorStore.getState().currentEditingNote === item.id) {
useEditorStore.getState().setReadonly(current);
2022-05-20 14:49:38 +05:00
// tiny.call(EditorWebView, tiny.toogleReadMode(current ? 'readonly' : 'design'));
2022-02-28 13:48:59 +05:00
}
2023-04-01 14:06:16 +05:00
Navigation.queueRoutesForUpdate();
2022-02-28 13:48:59 +05:00
close();
};
2022-03-14 16:28:54 +05:00
const duplicateNote = async () => {
if (!checkNoteSynced()) return;
2022-03-14 16:28:54 +05:00
await db.notes.note(item.id).duplicate();
2023-04-01 14:06:16 +05:00
Navigation.queueRoutesForUpdate();
2022-03-14 16:28:54 +05:00
close();
};
2022-02-28 13:48:59 +05:00
const actions = [
{
2023-02-09 15:34:29 +05:00
id: "notebooks",
title: "Link Notebooks",
icon: "book-outline",
2022-02-28 13:48:59 +05:00
func: addTo
},
2022-12-05 15:29:35 +05:00
{
2023-02-09 15:34:29 +05:00
id: "add-tag",
title: "Add tags",
icon: "pound",
func: addTo
},
{
id: "add-reminder",
title: "Remind me",
icon: "clock-plus-outline",
2022-12-05 15:29:35 +05:00
func: () => {
ReminderSheet.present(null, { id: item.id, type: "note" });
},
close: true
},
{
2023-02-09 15:34:29 +05:00
id: "lock-unlock",
title: item.locked ? "Unlock" : "Lock",
2023-02-09 15:34:29 +05:00
icon: item.locked ? "lock-open-outline" : "key-outline",
func: addToVault,
on: item.locked
},
{
2023-02-09 15:34:29 +05:00
id: "publish",
title: isPublished ? "Published" : "Publish",
icon: "cloud-upload-outline",
on: isPublished,
func: publishNote
},
{
2023-02-09 15:34:29 +05:00
id: "export",
title: "Export",
icon: "export",
func: exportNote
},
{
2023-02-09 15:34:29 +05:00
id: "move-notes",
title: "Add notes",
icon: "plus",
2022-02-28 13:48:59 +05:00
func: async () => {
MoveNotes.present(db.notebooks.notebook(item.notebookId).data, item);
}
},
{
2023-02-09 15:34:29 +05:00
id: "pin",
2023-04-27 08:18:25 +05:00
title: item.pinned ? "Unpin" : "Pin",
icon: item.pinned ? "pin-off-outline" : "pin-outline",
2022-02-28 13:48:59 +05:00
func: pinItem,
close: false,
check: true,
on: item.pinned,
2023-02-09 15:34:29 +05:00
pro: true
2022-02-28 13:48:59 +05:00
},
{
2023-02-09 15:34:29 +05:00
id: "favorite",
2023-04-27 08:18:25 +05:00
title: item.favorite ? "Unfavorite" : "Favorite",
icon: item.favorite ? "star-off" : "star-outline",
2022-02-28 13:48:59 +05:00
func: addToFavorites,
close: false,
check: true,
on: item.favorite,
2023-02-09 15:34:29 +05:00
pro: true,
color: "orange"
2022-02-28 13:48:59 +05:00
},
{
2023-02-09 15:34:29 +05:00
id: "pin-to-notifications",
title:
notifPinned !== null
? "Unpin from notifications"
2023-02-09 15:34:29 +05:00
: "Pin to notifications",
icon: "message-badge-outline",
2022-02-28 13:48:59 +05:00
on: notifPinned !== null,
func: pinToNotifications
},
{
2023-02-09 15:34:29 +05:00
id: "edit-notebook",
title: "Edit notebook",
icon: "square-edit-outline",
2022-02-28 13:48:59 +05:00
func: async () => {
2023-03-16 21:22:21 +05:00
AddNotebookSheet.present(item);
2022-02-28 13:48:59 +05:00
}
},
{
2023-02-09 15:34:29 +05:00
id: "edit-topic",
title: "Edit topic",
icon: "square-edit-outline",
2022-02-28 13:48:59 +05:00
func: async () => {
close();
await sleep(300);
eSendEvent(eOpenAddTopicDialog, {
notebookId: item.notebookId,
toEdit: item
});
}
},
{
2023-02-09 15:34:29 +05:00
id: "copy",
title: "Copy",
icon: "content-copy",
2022-02-28 13:48:59 +05:00
func: copyContent
},
{
2023-02-09 15:34:29 +05:00
id: "restore",
title: "Restore " + item.itemType,
icon: "delete-restore",
2022-02-28 13:48:59 +05:00
func: restoreTrashItem
},
{
2023-02-09 15:34:29 +05:00
id: "add-shortcut",
title: isPinnedToMenu ? "Remove Shortcut" : "Add Shortcut",
icon: isPinnedToMenu ? "link-variant-remove" : "link-variant",
2022-02-28 13:48:59 +05:00
func: createMenuShortcut,
close: false,
check: true,
on: isPinnedToMenu,
2023-02-09 15:34:29 +05:00
pro: true
2022-02-28 13:48:59 +05:00
},
{
2023-02-09 15:34:29 +05:00
id: "rename-tag",
title: "Rename tag",
icon: "square-edit-outline",
2022-02-28 13:48:59 +05:00
func: renameTag
},
{
2023-02-09 15:34:29 +05:00
id: "share",
title: "Share",
icon: "share-variant",
2022-02-28 13:48:59 +05:00
func: shareNote
},
{
2023-02-09 15:34:29 +05:00
id: "read-only",
2023-04-27 08:18:25 +05:00
title: "Readonly",
icon: "pencil-lock",
2022-02-28 13:48:59 +05:00
func: toggleReadyOnlyMode,
on: item.readonly
},
2022-03-14 16:28:54 +05:00
{
2023-02-09 15:34:29 +05:00
id: "local-only",
title: "Local only",
icon: "sync-off",
2022-03-14 16:28:54 +05:00
func: toggleLocalOnly,
on: item.localOnly
},
{
2023-02-09 15:34:29 +05:00
id: "duplicate",
title: "Duplicate",
icon: "content-duplicate",
2022-03-14 16:28:54 +05:00
func: duplicateNote
},
2022-02-28 13:48:59 +05:00
{
2023-02-09 15:34:29 +05:00
id: "dark-mode",
title: "Dark mode",
icon: "theme-light-dark",
2022-02-28 13:48:59 +05:00
func: switchTheme,
switch: true,
on: colors.night ? true : false,
close: false,
2023-02-09 15:34:29 +05:00
pro: true
2022-11-18 17:30:29 +05:00
},
{
2023-02-09 15:34:29 +05:00
id: "edit-reminder",
2022-11-18 17:30:29 +05:00
title: "Edit reminder",
2022-12-05 15:29:35 +05:00
icon: "pencil",
2022-11-18 17:30:29 +05:00
func: async () => {
ReminderSheet.present(item);
},
close: false
2022-12-05 15:29:35 +05:00
},
2023-01-03 10:23:48 +05:00
{
2023-02-09 15:34:29 +05:00
id: "reminders",
title: "Reminders",
icon: "clock-outline",
func: async () => {
RelationsList.present({
reference: item,
referenceType: "reminder",
relationType: "from",
title: "Reminders",
onAdd: () => ReminderSheet.present(null, item, true),
button: {
title: "Add",
type: "accent",
onPress: () => ReminderSheet.present(null, item, true),
icon: "plus"
}
});
},
close: false
},
{
id: "attachments",
title: "Attachments",
icon: "attachment",
func: showAttachments
},
{
id: "history",
title: "History",
icon: "history",
func: openHistory
},
2023-06-01 20:56:02 +05:00
{
id: "default-notebook",
title:
defaultNotebook?.id === item.id
2023-06-05 12:06:22 +05:00
? "Remove as default"
: "Set as default",
2023-06-01 20:56:02 +05:00
hidden: item.type !== "notebook",
icon: "notebook",
func: async () => {
if (defaultNotebook?.id === item.id) {
await db.settings.setDefaultNotebook();
setDefaultNotebook();
} else {
2023-06-05 12:06:22 +05:00
const notebook = {
id: item.id
};
await db.settings.setDefaultNotebook(notebook);
setDefaultNotebook(notebook);
2023-06-01 20:56:02 +05:00
}
2023-06-05 12:06:22 +05:00
close();
2023-06-01 20:56:02 +05:00
},
2023-06-05 12:06:22 +05:00
on: defaultNotebook?.topic ? false : defaultNotebook?.id === item.id
2023-06-01 20:56:02 +05:00
},
{
id: "default-topic",
title:
defaultNotebook?.id === item.id
2023-06-05 12:06:22 +05:00
? "Remove as default"
: "Set as default",
2023-06-01 20:56:02 +05:00
hidden: item.type !== "topic",
icon: "bookmark",
func: async () => {
2023-06-05 12:06:22 +05:00
if (defaultNotebook?.topic === item.id) {
2023-06-01 20:56:02 +05:00
await db.settings.setDefaultNotebook();
setDefaultNotebook();
} else {
2023-06-05 12:06:22 +05:00
const notebook = {
id: item.notebookId,
topic: item.id
};
await db.settings.setDefaultNotebook(notebook);
setDefaultNotebook(notebook);
2023-06-01 20:56:02 +05:00
}
2023-06-05 12:06:22 +05:00
close();
2023-06-01 20:56:02 +05:00
},
2023-06-05 12:06:22 +05:00
on: defaultNotebook?.topic === item.id
2023-06-01 20:56:02 +05:00
},
2023-02-09 15:34:29 +05:00
{
id: "disable-reminder",
2023-01-03 10:23:48 +05:00
title: !item.disabled ? "Turn off reminder" : "Turn on reminder",
icon: !item.disabled ? "bell-off-outline" : "bell",
func: async () => {
close();
await db.reminders.add({
...item,
disabled: !item.disabled
});
Notifications.scheduleNotification(item);
useRelationStore.getState().update();
2023-04-01 14:06:16 +05:00
Navigation.queueRoutesForUpdate();
2023-01-03 10:23:48 +05:00
}
},
{
2023-02-09 15:34:29 +05:00
id: "remove-from-topic",
title: "Remove from topic",
hidden: !isNoteInTopic(),
icon: "minus-circle-outline",
func: removeNoteFromTopic
},
{
id: "remove-from-notebook",
title: "Remove from notebook",
hidden: !isNoteInNotebook(),
icon: "minus-circle-outline",
func: removeNoteFromNotebook
},
{
2023-02-09 15:34:29 +05:00
id: "trash",
title:
item.type !== "notebook" && item.type !== "note"
? "Delete " + item.type
: "Move to trash",
icon: "delete-outline",
type: "error",
func: deleteItem
},
{
2023-02-09 15:34:29 +05:00
id: "delete",
title: "Delete " + item.itemType,
icon: "delete",
func: deleteTrashItem
2023-01-16 13:44:52 +05:00
}
// {
2023-02-09 15:34:29 +05:00
// id: "ReferencedIn",
// title: "References",
// icon: "link",
// func: async () => {
// close();
// RelationsList.present({
// reference: item,
// referenceType: "note",
// title: "Referenced in",
// relationType: "to",
// });
// }
// }
2022-02-28 13:48:59 +05:00
];
return actions;
};