feat: tag bookmarks and sites, and browse the library by tag

This commit is contained in:
randogoth 2026-10-11 13:32:00 +03:00
parent 5cd053c8a9
commit b0b86ef5b1
13 changed files with 445 additions and 21 deletions

View file

@ -45,6 +45,9 @@ class InternalActions {
'unsubscribe' => _withUrl(args, _subscriptions.remove),
'forget-page' => _withUrl(args, _db.forgetPage),
'clear-history' => _clearHistory(),
'add-tag' => _changeTag(args, add: true),
'remove-tag' => _changeTag(args, add: false),
'delete-tag' => _deleteTag(args['tag']),
_ => false,
};
}
@ -64,6 +67,32 @@ class InternalActions {
return true;
}
/// Adds or removes one tag. An empty name is refused, so submitting an
/// empty box does nothing.
Future<bool> _changeTag(Map<String, String> args, {required bool add}) async {
final kind = switch (args['kind']) {
'bookmark' => TagKind.bookmark,
'subscription' => TagKind.subscription,
_ => null,
};
final url = args['url'];
final tag = args['tag']?.trim();
if (kind == null || url == null || url.isEmpty) return false;
if (tag == null || tag.isEmpty) return false;
if (add) {
await _db.addTag(kind, url, tag);
} else {
await _db.removeTag(kind, url, tag);
}
return true;
}
Future<bool> _deleteTag(String? tag) async {
if (tag == null || tag.isEmpty) return false;
await _db.deleteTag(tag);
return true;
}
Future<bool> _clearHistory() async {
await _db.clearHistory();
return true;