Skip to content

Commit

Permalink
feat: allow encrypting individual entries
Browse files Browse the repository at this point in the history
  • Loading branch information
ThatNerdSquared committed Sep 25, 2024
1 parent c391f7a commit 0b02c79
Show file tree
Hide file tree
Showing 3 changed files with 32 additions and 0 deletions.
6 changes: 6 additions & 0 deletions lib/context_menus.dart
Original file line number Diff line number Diff line change
Expand Up @@ -59,13 +59,19 @@ scm.Menu buildTagButtonContextMenu(

scm.Menu buildEntryCardContextMenu({
required String entryId,
required bool isEncrypted,
required VoidCallback toggleEncryptCallback,
required Function(String) addAncestorCallback,
}) =>
scm.Menu(
children: [
scm.MenuAction(
title: 'Add as ancestor',
callback: () => addAncestorCallback(entryId),
),
scm.MenuAction(
title: isEncrypted ? 'Decrypt Entry' : 'Encrypt Entry',
callback: () => !isEncrypted ? toggleEncryptCallback() : null,
)
],
);
22 changes: 22 additions & 0 deletions lib/model/entry_data.dart
Original file line number Diff line number Diff line change
Expand Up @@ -100,6 +100,28 @@ class PeregrineEntryList extends StateNotifier<Map<String, PeregrineEntry>> {
});
_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 {
Expand Down
4 changes: 4 additions & 0 deletions lib/widgets/peregrine_entry_card.dart
Original file line number Diff line number Diff line change
Expand Up @@ -75,6 +75,10 @@ class _PeregrineEntryCardState extends ConsumerState<PeregrineEntryCard> {
: Container(),
scm.ContextMenuWidget(
menuProvider: (_) => buildEntryCardContextMenu(
isEncrypted: entry.isEncrypted,
toggleEncryptCallback: () => ref
.read(entryListProvider.notifier)
.toggleEncrypt(widget.entryId),
entryId: widget.entryId,
addAncestorCallback: (_) => ref
.read(currentAncestorsProvider.notifier)
Expand Down

0 comments on commit 0b02c79

Please sign in to comment.