From 0b02c79a27ed2d742e3b156f17a717836e1c0d26 Mon Sep 17 00:00:00 2001 From: ThatNerdSquared <72814106+ThatNerdSquared@users.noreply.github.com> Date: Tue, 24 Sep 2024 20:24:13 -0700 Subject: [PATCH] feat: allow encrypting individual entries --- lib/context_menus.dart | 6 ++++++ lib/model/entry_data.dart | 22 ++++++++++++++++++++++ lib/widgets/peregrine_entry_card.dart | 4 ++++ 3 files changed, 32 insertions(+) diff --git a/lib/context_menus.dart b/lib/context_menus.dart index 4cc3555..ffc1355 100644 --- a/lib/context_menus.dart +++ b/lib/context_menus.dart @@ -59,6 +59,8 @@ scm.Menu buildTagButtonContextMenu( scm.Menu buildEntryCardContextMenu({ required String entryId, + required bool isEncrypted, + required VoidCallback toggleEncryptCallback, required Function(String) addAncestorCallback, }) => scm.Menu( @@ -66,6 +68,10 @@ scm.Menu buildEntryCardContextMenu({ scm.MenuAction( title: 'Add as ancestor', callback: () => addAncestorCallback(entryId), + ), + scm.MenuAction( + title: isEncrypted ? 'Decrypt Entry' : 'Encrypt Entry', + callback: () => !isEncrypted ? toggleEncryptCallback() : null, ) ], ); diff --git a/lib/model/entry_data.dart b/lib/model/entry_data.dart index 66b8df5..d9c50da 100644 --- a/lib/model/entry_data.dart +++ b/lib/model/entry_data.dart @@ -100,6 +100,28 @@ class PeregrineEntryList extends StateNotifier> { }); _writeLog(); } + + void toggleEncrypt(String entryID) { + state = state.map((key, value) { + if (key == entryID) { + return MapEntry( + key, + PeregrineEntry( + date: value.date, + input: value.input, + isEncrypted: !value.isEncrypted, + entryType: value.entryType, + tags: value.tags, + mentionedContacts: value.mentionedContacts, + ancestors: value.ancestors, + descendants: value.descendants, + )); + } else { + return MapEntry(key, value); + } + }); + _writeLog(); + } } class PeregrineEntry extends PretDataclass { diff --git a/lib/widgets/peregrine_entry_card.dart b/lib/widgets/peregrine_entry_card.dart index 2c65d20..c7f9dc5 100644 --- a/lib/widgets/peregrine_entry_card.dart +++ b/lib/widgets/peregrine_entry_card.dart @@ -75,6 +75,10 @@ class _PeregrineEntryCardState extends ConsumerState { : Container(), scm.ContextMenuWidget( menuProvider: (_) => buildEntryCardContextMenu( + isEncrypted: entry.isEncrypted, + toggleEncryptCallback: () => ref + .read(entryListProvider.notifier) + .toggleEncrypt(widget.entryId), entryId: widget.entryId, addAncestorCallback: (_) => ref .read(currentAncestorsProvider.notifier)