Skip to content

Commit

Permalink
feat: add ability to completely delete a tag
Browse files Browse the repository at this point in the history
useful because right now tags are auto-detected when an entry is
submitted, which means anything following a hashtag (i.e. things
in URLs, etc) might be mistakenly detected as a tag
  • Loading branch information
ThatNerdSquared committed Aug 20, 2024
1 parent 42d2632 commit eda70c8
Show file tree
Hide file tree
Showing 8 changed files with 125 additions and 6 deletions.
2 changes: 1 addition & 1 deletion ios/Flutter/AppFrameworkInfo.plist
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,6 @@
<key>CFBundleVersion</key>
<string>1.0</string>
<key>MinimumOSVersion</key>
<string>11.0</string>
<string>12.0</string>
</dict>
</plist>
8 changes: 4 additions & 4 deletions ios/Runner.xcodeproj/project.pbxproj
Original file line number Diff line number Diff line change
Expand Up @@ -214,7 +214,7 @@
97C146E61CF9000F007C117D /* Project object */ = {
isa = PBXProject;
attributes = {
LastUpgradeCheck = 1430;
LastUpgradeCheck = 1510;
ORGANIZATIONNAME = "";
TargetAttributes = {
331C8080294A63A400263BE5 = {
Expand Down Expand Up @@ -451,7 +451,7 @@
GCC_WARN_UNINITIALIZED_AUTOS = YES_AGGRESSIVE;
GCC_WARN_UNUSED_FUNCTION = YES;
GCC_WARN_UNUSED_VARIABLE = YES;
IPHONEOS_DEPLOYMENT_TARGET = 11.0;
IPHONEOS_DEPLOYMENT_TARGET = 12.0;
MTL_ENABLE_DEBUG_INFO = NO;
SDKROOT = iphoneos;
SUPPORTED_PLATFORMS = iphoneos;
Expand Down Expand Up @@ -579,7 +579,7 @@
GCC_WARN_UNINITIALIZED_AUTOS = YES_AGGRESSIVE;
GCC_WARN_UNUSED_FUNCTION = YES;
GCC_WARN_UNUSED_VARIABLE = YES;
IPHONEOS_DEPLOYMENT_TARGET = 11.0;
IPHONEOS_DEPLOYMENT_TARGET = 12.0;
MTL_ENABLE_DEBUG_INFO = YES;
ONLY_ACTIVE_ARCH = YES;
SDKROOT = iphoneos;
Expand Down Expand Up @@ -628,7 +628,7 @@
GCC_WARN_UNINITIALIZED_AUTOS = YES_AGGRESSIVE;
GCC_WARN_UNUSED_FUNCTION = YES;
GCC_WARN_UNUSED_VARIABLE = YES;
IPHONEOS_DEPLOYMENT_TARGET = 11.0;
IPHONEOS_DEPLOYMENT_TARGET = 12.0;
MTL_ENABLE_DEBUG_INFO = NO;
SDKROOT = iphoneos;
SUPPORTED_PLATFORMS = iphoneos;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
<?xml version="1.0" encoding="UTF-8"?>
<Scheme
LastUpgradeVersion = "1430"
LastUpgradeVersion = "1510"
version = "1.3">
<BuildAction
parallelizeBuildables = "YES"
Expand Down
23 changes: 23 additions & 0 deletions lib/context_menus.dart
Original file line number Diff line number Diff line change
@@ -1,14 +1,19 @@
import 'package:flutter/material.dart';
import 'package:super_context_menu/super_context_menu.dart' as scm;

import 'export_utils.dart';
import 'model/entry_data.dart';
import 'model/tag_data.dart';
import 'widgets/confirmation_modal.dart';

scm.Menu buildTagButtonContextMenu(
BuildContext context,
String tagName,
PeregrineTag tagInfo,
Function(String) autoEncryptToggleCallback,
List<PeregrineEntry> entries,
void Function(String) stripTagFromEntriesCallback,
void Function(String) deleteTagCallback,
) =>
scm.Menu(
children: [
Expand All @@ -31,6 +36,24 @@ scm.Menu buildTagButtonContextMenu(
),
],
),
scm.MenuAction(
title: 'Delete Tag',
image: scm.MenuImage.icon(Icons.delete),
attributes: const scm.MenuActionAttributes(
destructive: true,
),
callback: () async {
final confirmation = await showModalBottomSheet<bool>(
context: context,
isDismissible: false,
builder: (context) => ConfirmationModal(count: tagInfo.count),
);
// TODO: why is this nullable?
if (confirmation != null && confirmation) {
stripTagFromEntriesCallback(tagName);
deleteTagCallback(tagName);
}
})
],
);

Expand Down
22 changes: 22 additions & 0 deletions lib/model/entry_data.dart
Original file line number Diff line number Diff line change
Expand Up @@ -78,6 +78,28 @@ class PeregrineEntryList extends StateNotifier<Map<String, PeregrineEntry>> {
};
_writeLog();
}

void stripTagFromEntries(String tag) {
state = state.map((key, value) {
if (value.tags.contains(tag)) {
return MapEntry(
key,
PeregrineEntry(
date: value.date,
input: value.input,
isEncrypted: value.isEncrypted,
entryType: value.entryType,
tags: value.tags.where((x) => x != tag).toList(),
mentionedContacts: value.mentionedContacts,
ancestors: value.ancestors,
descendants: value.descendants,
));
} else {
return MapEntry(key, value);
}
});
_writeLog();
}
}

class PeregrineEntry extends PretDataclass {
Expand Down
7 changes: 7 additions & 0 deletions lib/model/tag_data.dart
Original file line number Diff line number Diff line change
Expand Up @@ -62,6 +62,13 @@ class TagsList extends StateNotifier<Map<String, PeregrineTag>> {
}
return false;
}

void deleteTag(String tag) {
state = Map.fromEntries(
state.entries.where((x) => x.key != tag),
);
_writeTags();
}
}

Map<String, PeregrineTag> sortTags(Map<String, PeregrineTag> tags) {
Expand Down
62 changes: 62 additions & 0 deletions lib/widgets/confirmation_modal.dart
Original file line number Diff line number Diff line change
@@ -0,0 +1,62 @@
import 'package:flutter/material.dart';
import 'package:pret_a_porter/pret_a_porter.dart';

class ConfirmationModal extends StatelessWidget {
final int count;

const ConfirmationModal({super.key, required this.count});

@override
Widget build(BuildContext context) {
return SizedBox(
height: 300,
child: Center(
child: Column(
mainAxisAlignment: MainAxisAlignment.center,
children: [
Text(
'Are you sure you want to delete this tag, and remove it from $count entries?',
textAlign: TextAlign.center,
),
const Padding(
padding: EdgeInsets.only(
top: PretConfig.defaultElementSpacing,
),
),
const Text(
'Warning: this is an irreversible + highly destructive action!',
textAlign: TextAlign.center,
style: TextStyle(color: Colors.red)),
const Padding(
padding: EdgeInsets.only(
top: PretConfig.defaultElementSpacing,
),
),
Row(
mainAxisAlignment: MainAxisAlignment.center,
children: [
OutlinedButton(
autofocus: true,
child: const Text('Cancel'),
onPressed: () => Navigator.pop(context, false),
),
const Padding(
padding: EdgeInsets.only(
left: PretConfig.defaultElementSpacing,
),
),
OutlinedButton(
style: const ButtonStyle(
backgroundColor: MaterialStatePropertyAll(Colors.red),
),
onPressed: () => Navigator.pop(context, true),
child: const Text('Delete'),
)
],
)
],
),
),
);
}
}
5 changes: 5 additions & 0 deletions lib/widgets/sidebar.dart
Original file line number Diff line number Diff line change
Expand Up @@ -77,11 +77,16 @@ class Sidebar extends ConsumerWidget {
right: PretConfig.defaultElementSpacing),
child: ContextMenuWidget(
menuProvider: (_) => buildTagButtonContextMenu(
context,
tagName,
tags[tagName]!,
(name) =>
ref.read(tagsProvider.notifier).toggleAutoEncrypt(name),
ref.watch(filteredListProvider).values.toList(),
(tag) => ref
.read(entryListProvider.notifier)
.stripTagFromEntries(tag),
(tag) => ref.read(tagsProvider.notifier).deleteTag(tag),
),
child: PretSidebarButton(
color:
Expand Down

0 comments on commit eda70c8

Please sign in to comment.