Skip to content

A fully open source & end-to-end encrypted note taking alternative to Evernote.

mobile: add option to clear note version history

kashaf-ansari-deve4a7d63e07c5
diff --git a/apps/mobile/app/components/note-history/index.tsx b/apps/mobile/app/components/note-history/index.tsx
index 4b16c191f..2003da413 100644
--- a/apps/mobile/app/components/note-history/index.tsx
+++ b/apps/mobile/app/components/note-history/index.tsx
@@ -29,7 +29,7 @@ import { ActionSheetRef, ScrollView } from "react-native-actions-sheet";
import Icon from "react-native-vector-icons/MaterialCommunityIcons";
import { db } from "../../common/database";
import { useDBItem } from "../../hooks/use-db-item";
-import { presentSheet } from "../../services/event-manager";
+import { presentSheet, ToastManager } from "../../services/event-manager";
import { openLinkInBrowser } from "../../utils/functions";
import { AppFontSize } from "../../utils/size";
import { DefaultAppStyles } from "../../utils/styles";
@@ -39,6 +39,7 @@ import { Pressable } from "../ui/pressable";
import Seperator from "../ui/seperator";
import Paragraph from "../ui/typography/paragraph";
import NotePreview from "./preview";
+import { presentDialog } from "../dialog/functions";
const HistoryItem = ({
index,
@@ -58,9 +59,8 @@ const HistoryItem = ({
const _start_time = getFormattedDate(start, "time");
const _end_time = getFormattedDate(end + 60000, "time");
- return `${_start_date} ${_start_time} - ${
- _end_date === _start_date ? " " : _end_date + " "
- }${_end_time}`;
+ return `${_start_date} ${_start_time} - ${_end_date === _start_date ? " " : _end_date + " "
+ }${_end_time}`;
};
const preview = useCallback(
@@ -112,7 +112,8 @@ const HistoryItem = ({
};
export default function NoteHistory({
- note
+ note,
+ fwdRef
}: {
note: Note;
fwdRef: RefObject<ActionSheetRef>;
@@ -147,7 +148,35 @@ export default function NoteHistory({
return (
<View>
<SheetProvider context="note_history" />
- <DialogHeader title={strings.noteHistory()} padding={12} />
+ <DialogHeader
+ title={strings.noteHistory()}
+ padding={12}
+ button={
+ history?.placeholders.length
+ ? {
+ title: strings.clearHistory(),
+ type: "secondary",
+ onPress: () => {
+ presentDialog({
+ title: strings.clearHistory(),
+ paragraph: strings.clearHistoryConfirmation(1),
+ positiveText: strings.clear(),
+ negativeText: strings.cancel(),
+ positiveType: "errorShade",
+ positivePress: async () => {
+ await db.noteHistory.clearSessions(note.id);
+ fwdRef.current?.hide();
+ ToastManager.show({
+ heading: strings.historyCleared(),
+ type: "success"
+ });
+ }
+ });
+ }
+ }
+ : undefined
+ }
+ />
<Seperator />
diff --git a/apps/mobile/app/components/selection-header/index.tsx b/apps/mobile/app/components/selection-header/index.tsx
index 3bfe6f14f..1417bda1e 100644
--- a/apps/mobile/app/components/selection-header/index.tsx
+++ b/apps/mobile/app/components/selection-header/index.tsx
@@ -170,147 +170,173 @@ export const SelectionHeader = React.memo(
{!selectedItemsList.length
? null
: (focusedRouteId === "Monographs"
- ? [
- {
- title: strings.unpublish(),
- onPress: () => {
- presentDialog({
- title: strings.doActions.unpublish.note(
- selectedItemsList.length
- ),
- positiveText: strings.unpublish(),
- negativeText: strings.cancel(),
- positivePress: async () => {
- for (const id of selectedItemsList) {
- await db.monographs.unpublish(id);
- }
- Navigation.queueRoutesForUpdate();
- clearSelection();
- },
- positiveType: "errorShade"
- });
- },
- visible: true,
- icon: "delete"
- }
- ]
- : [
- {
- title: strings.manageTags(),
- onPress: async () => {
- ManageTags.present(selectedItemsList);
- },
- visible: type === "note",
- icon: "pound"
- },
- {
- title: strings.export(),
- onPress: async () => {
- ExportNotesSheet.present(selectedItemsList);
- },
- visible: type === "note",
- icon: "export"
- },
- {
- title: strings.addToNotebook(),
- onPress: async () => {
- Navigation.navigate("LinkNotebooks", {
- noteIds: selectedItemsList
- });
- },
- visible: type === "note",
- icon: "plus"
- },
- {
- title: strings.unlinkNotebook(),
- onPress: async () => {
- if (!id) return;
- await db.notes.removeFromNotebook(
- id,
- ...selectedItemsList
- );
- updateNotebook(id);
+ ? [
+ {
+ title: strings.unpublish(),
+ onPress: () => {
+ presentDialog({
+ title: strings.doActions.unpublish.note(
+ selectedItemsList.length
+ ),
+ positiveText: strings.unpublish(),
+ negativeText: strings.cancel(),
+ positivePress: async () => {
+ for (const id of selectedItemsList) {
+ await db.monographs.unpublish(id);
+ }
Navigation.queueRoutesForUpdate();
clearSelection();
},
- visible: renderedInRoute === "Notebook",
- icon: "minus"
- },
- {
- title: strings.unfavorite(),
- onPress: addToFavorite,
- visible: focusedRouteId === "Favorites",
- icon: "star-off"
- },
- {
- title: strings.moveToTrash(),
- onPress: async () => {
- const selection = useSelectionStore.getState();
- if (!selection.selectionMode) return;
- await deleteItems(
- selection.selectionMode as ItemType,
- selection.selectedItemsList
- );
- selection.clearSelection();
- selection.setSelectionMode(undefined);
- },
- visible: type === "note" || type === "notebook",
- icon: "delete"
- },
- {
- title: strings.doActions.delete.unknown(
- type!,
+ positiveType: "errorShade"
+ });
+ },
+ visible: true,
+ icon: "delete"
+ }
+ ]
+ : [
+ {
+ title: strings.manageTags(),
+ onPress: async () => {
+ ManageTags.present(selectedItemsList);
+ },
+ visible: type === "note",
+ icon: "pound"
+ },
+ {
+ title: strings.export(),
+ onPress: async () => {
+ ExportNotesSheet.present(selectedItemsList);
+ },
+ visible: type === "note",
+ icon: "export"
+ },
+ {
+ title: strings.clearHistory(),
+ onPress: async () => {
+ presentDialog({
+ title: strings.clearHistory(),
+ paragraph: strings.clearHistoryConfirmation(
selectedItemsList.length
),
- onPress: async () => {
- const selection = useSelectionStore.getState();
- if (!selection.selectionMode) return;
- await deleteItems(
- selection.selectionMode as ItemType,
- selection.selectedItemsList
- );
- selection.clearSelection();
- selection.setSelectionMode(undefined);
- },
- visible:
- type !== "trash" &&
- type !== "note" &&
- type !== "notebook",
- icon: "delete"
- },
- {
- title: strings.restore(),
- onPress: restoreItem,
- visible: type === "trash",
- icon: "delete-restore"
- },
- {
- title: strings.delete(),
- onPress: deleteItem,
- visible: type === "trash",
- icon: "delete"
- }
- ]
- ).map((item) =>
- !item.visible ? null : (
- <IconButton
- size={AppFontSize.lg}
- type="plain"
- tooltipText={item.title}
- tooltipPosition={NativeTooltip.POSITIONS.TOP}
- testID={`select-${item.icon}`}
- name={item.icon}
- key={item.title}
- color={colors.primary.icon}
- onPress={async () => {
- //@ts-ignore
- menuRef.current?.hide();
- if (Platform.OS === "ios") await sleep(300);
- item.onPress();
- }}
- />
- )
- )}
+ positiveText: strings.clear(),
+ negativeText: strings.cancel(),
+ positiveType: "errorShade",
+ positivePress: async () => {
+ await db.noteHistory.clearSessions(...selectedItemsList);
+ Navigation.queueRoutesForUpdate();
+ clearSelection();
+
+ ToastManager.show({
+ heading: strings.historyCleared(),
+ type: "success"
+ });
+ }
+ });
+ },
+ visible: type === "note",
+ icon: "history"
+ },
+ {
+ title: strings.addToNotebook(),
+ onPress: async () => {
+ Navigation.navigate("LinkNotebooks", {
+ noteIds: selectedItemsList
+ });
+ },
+ visible: type === "note",
+ icon: "plus"
+ },
+ {
+ title: strings.unlinkNotebook(),
+ onPress: async () => {
+ if (!id) return;
+ await db.notes.removeFromNotebook(
+ id,
+ ...selectedItemsList
+ );
+ updateNotebook(id);
+ Navigation.queueRoutesForUpdate();
+ clearSelection();
+ },
+ visible: renderedInRoute === "Notebook",
+ icon: "minus"
+ },
+ {
+ title: strings.unfavorite(),
+ onPress: addToFavorite,
+ visible: focusedRouteId === "Favorites",
+ icon: "star-off"
+ },
+ {
+ title: strings.moveToTrash(),
+ onPress: async () => {
+ const selection = useSelectionStore.getState();
+ if (!selection.selectionMode) return;
+ await deleteItems(
+ selection.selectionMode as ItemType,
+ selection.selectedItemsList
+ );
+ selection.clearSelection();
+ selection.setSelectionMode(undefined);
+ },
+ visible: type === "note" || type === "notebook",
+ icon: "delete"
+ },
+ {
+ title: strings.doActions.delete.unknown(
+ type!,
+ selectedItemsList.length
+ ),
+ onPress: async () => {
+ const selection = useSelectionStore.getState();
+ if (!selection.selectionMode) return;
+ await deleteItems(
+ selection.selectionMode as ItemType,
+ selection.selectedItemsList
+ );
+ selection.clearSelection();
+ selection.setSelectionMode(undefined);
+ },
+ visible:
+ type !== "trash" &&
+ type !== "note" &&
+ type !== "notebook",
+ icon: "delete"
+ },
+ {
+ title: strings.restore(),
+ onPress: restoreItem,
+ visible: type === "trash",
+ icon: "delete-restore"
+ },
+ {
+ title: strings.delete(),
+ onPress: deleteItem,
+ visible: type === "trash",
+ icon: "delete"
+ }
+ ]
+ ).map((item) =>
+ !item.visible ? null : (
+ <IconButton
+ size={AppFontSize.lg}
+ type="plain"
+ tooltipText={item.title}
+ tooltipPosition={NativeTooltip.POSITIONS.TOP}
+ testID={`select-${item.icon}`}
+ name={item.icon}
+ key={item.title}
+ color={colors.primary.icon}
+ onPress={async () => {
+ //@ts-ignore
+ menuRef.current?.hide();
+ if (Platform.OS === "ios") await sleep(300);
+ item.onPress();
+ }}
+ />
+ )
+ )}
</View>
<IconButton
diff --git a/packages/intl/locale/en.po b/packages/intl/locale/en.po
index b4c6d71cd..9b9e6eb96 100644
--- a/packages/intl/locale/en.po
+++ b/packages/intl/locale/en.po
@@ -1647,6 +1647,10 @@ msgstr "Clear data & reset account"
msgid "Clear default notebook"
msgstr "Clear default notebook"
+#: src/strings.ts:2800
+msgid "Clear history"
+msgstr "Clear history"
+
#: src/strings.ts:1015
msgid "Clear logs"
msgstr "Clear logs"
@@ -2295,6 +2299,14 @@ msgstr "Delete account"
msgid "Delete all"
msgstr "Delete all"
+#: src/strings.ts:2805
+msgid "Delete all version history for {count} selected notes?"
+msgstr "Delete all version history for {count} selected notes?"
+
+#: src/strings.ts:2804
+msgid "Delete all version history for this note?"
+msgstr "Delete all version history for this note?"
+
#: src/strings.ts:2732
msgid "Delete attachment"
msgstr "Delete attachment"
@@ -7533,6 +7545,10 @@ msgstr "Verifying your email"
msgid "Version"
msgstr "Version"
+#: src/strings.ts:2801
+msgid "Version history cleared"
+msgstr "Version history cleared"
+
#: src/strings.ts:50
msgid "Vibrate"
msgstr "Vibrate"
diff --git a/packages/intl/locale/pseudo-LOCALE.po b/packages/intl/locale/pseudo-LOCALE.po
index ac07060d5..63f83ceed 100644
--- a/packages/intl/locale/pseudo-LOCALE.po
+++ b/packages/intl/locale/pseudo-LOCALE.po
@@ -1647,6 +1647,10 @@ msgstr ""
msgid "Clear default notebook"
msgstr ""
+#: src/strings.ts:2800
+msgid "Clear history"
+msgstr ""
+
#: src/strings.ts:1015
msgid "Clear logs"
msgstr ""
@@ -2284,6 +2288,14 @@ msgstr ""
msgid "Delete all"
msgstr ""
+#: src/strings.ts:2805
+msgid "Delete all version history for {count} selected notes?"
+msgstr ""
+
+#: src/strings.ts:2804
+msgid "Delete all version history for this note?"
+msgstr ""
+
#: src/strings.ts:2732
msgid "Delete attachment"
msgstr ""
@@ -7483,6 +7495,10 @@ msgstr ""
msgid "Version"
msgstr ""
+#: src/strings.ts:2801
+msgid "Version history cleared"
+msgstr ""
+
#: src/strings.ts:50
msgid "Vibrate"
msgstr ""
diff --git a/packages/intl/src/strings.ts b/packages/intl/src/strings.ts
index b4871f2a8..845a09121 100644
--- a/packages/intl/src/strings.ts
+++ b/packages/intl/src/strings.ts
@@ -2799,5 +2799,11 @@ Continue without attachments?`,
deleteItem: () => t`Delete item`,
keepScreenOn: () => t`Keep screen on`,
keepScreenOnDesc: () =>
- t`Prevent the screen from turning off while the editor is focused.`
+ t`Prevent the screen from turning off while the editor is focused.`,
+ clearHistory: () => t`Clear history`,
+ historyCleared: () => t`Version history cleared`,
+ clearHistoryConfirmation: (count: number) =>
+ count === 1
+ ? t`Delete all version history for this note?`
+ : t`Delete all version history for ${count} selected notes?`
};