mirror of
https://github.com/Dasemu/Synapse.git
synced 2026-11-26 23:36:20 +00:00
feat(app): tag view, single type picker and sorted tag header
Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
This commit is contained in:
1 parent
3b0d4a5f81
commit
9a671a27c4
6 files changed
+543
-247
No files matched your search
@@ -62,23 +62,29 @@ abstract class GraphBackend {
|
|||||||
Future<PageStructure> pageStructure(String pageId);
|
Future<PageStructure> pageStructure(String pageId);
|
||||||
Future<PageDto> createHub(String title, String description);
|
Future<PageDto> createHub(String title, String description);
|
||||||
|
|
||||||
/// Tags are pages of kind `tag` (topics); a page can have any number. Types are plain
|
/// Tags are names (no pages), kept sorted; a page can have any number. A page has at most
|
||||||
/// names saying what a page is.
|
/// one type, a name saying what it is, and the type implies a tag of the same name.
|
||||||
Future<PageDto> setPageTags(String pageId, List<String> tags);
|
Future<PageDto> setPageTags(String pageId, List<String> tags);
|
||||||
Future<PageDto> addPageTag(String pageId, String tag);
|
Future<PageDto> addPageTag(String pageId, String tag);
|
||||||
Future<PageDto> removePageTag(String pageId, String tag);
|
Future<PageDto> removePageTag(String pageId, String tag);
|
||||||
|
|
||||||
Future<PageDto> setPageTypes(String pageId, List<String> types);
|
Future<PageDto> setPageType(String pageId, String? type);
|
||||||
Future<PageDto> addPageType(String pageId, String type);
|
|
||||||
Future<PageDto> removePageType(String pageId, String type);
|
|
||||||
|
|
||||||
/// Types in use (most used first), then the seeded suggestions not used yet.
|
/// Types in use (most used first), then the seeded suggestions not used yet.
|
||||||
Future<List<TagDto>> typeCatalog();
|
Future<List<TagDto>> typeCatalog();
|
||||||
|
|
||||||
/// Tag pages, most used first.
|
/// Every tag in use (listed or implied by a type), most used first.
|
||||||
Future<List<TagDto>> tagCatalog();
|
Future<List<TagDto>> tagCatalog();
|
||||||
|
|
||||||
|
/// Pages carrying a tag, listed or via their type.
|
||||||
Future<List<PageBrief>> pagesWithTag(String tag);
|
Future<List<PageBrief>> pagesWithTag(String tag);
|
||||||
|
|
||||||
|
/// Renames a tag in the tags and types of every page; returns the pages changed.
|
||||||
|
Future<int> renameTag(String old, String new_);
|
||||||
|
|
||||||
|
/// Removes the explicit tag from every page (types stay); returns the pages changed.
|
||||||
|
Future<int> removeTag(String name);
|
||||||
|
|
||||||
/// Id of the hub's template page (opens like a note; may be empty).
|
/// Id of the hub's template page (opens like a note; may be empty).
|
||||||
Future<String> hubTemplate(String hubId);
|
Future<String> hubTemplate(String hubId);
|
||||||
|
|
||||||
@@ -255,14 +261,13 @@ class FfiGraphBackend implements GraphBackend {
|
|||||||
Future<PageDto> removePageTag(String pageId, String tag) =>
|
Future<PageDto> removePageTag(String pageId, String tag) =>
|
||||||
_g.removePageTag(pageId: pageId, tag: tag);
|
_g.removePageTag(pageId: pageId, tag: tag);
|
||||||
@override
|
@override
|
||||||
Future<PageDto> setPageTypes(String pageId, List<String> types) =>
|
Future<PageDto> setPageType(String pageId, String? type) =>
|
||||||
_g.setPageTypes(pageId: pageId, types: types);
|
_g.setPageType(pageId: pageId, pageType: type);
|
||||||
@override
|
@override
|
||||||
Future<PageDto> addPageType(String pageId, String type) =>
|
Future<int> renameTag(String old, String new_) =>
|
||||||
_g.addPageType(pageId: pageId, ty: type);
|
_g.renameTag(old: old, new_: new_);
|
||||||
@override
|
@override
|
||||||
Future<PageDto> removePageType(String pageId, String type) =>
|
Future<int> removeTag(String name) => _g.removeTag(name: name);
|
||||||
_g.removePageType(pageId: pageId, ty: type);
|
|
||||||
@override
|
@override
|
||||||
Future<List<TagDto>> typeCatalog() => _g.typeCatalog();
|
Future<List<TagDto>> typeCatalog() => _g.typeCatalog();
|
||||||
|
|
||||||
|
|||||||
@@ -48,6 +48,19 @@ class GraphRoute extends AppRoute {
|
|||||||
final String? focusId;
|
final String? focusId;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/// A tag (a name, not a page): the pages carrying it, listed or through their type.
|
||||||
|
class TagRoute extends AppRoute {
|
||||||
|
const TagRoute(this.name);
|
||||||
|
final String name;
|
||||||
|
|
||||||
|
@override
|
||||||
|
bool operator ==(Object other) =>
|
||||||
|
other is TagRoute && other.name.toLowerCase() == name.toLowerCase();
|
||||||
|
|
||||||
|
@override
|
||||||
|
int get hashCode => name.toLowerCase().hashCode;
|
||||||
|
}
|
||||||
|
|
||||||
/// A page, by id or (for links that may not exist yet) by title.
|
/// A page, by id or (for links that may not exist yet) by title.
|
||||||
class PageTarget extends AppRoute {
|
class PageTarget extends AppRoute {
|
||||||
const PageTarget({this.id, this.title}) : assert(id != null || title != null);
|
const PageTarget({this.id, this.title}) : assert(id != null || title != null);
|
||||||
@@ -278,6 +291,14 @@ class AppState extends ChangeNotifier {
|
|||||||
notifyListeners();
|
notifyListeners();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/// Swaps the current route without touching history (a tag was renamed).
|
||||||
|
void replaceRoute(AppRoute r) {
|
||||||
|
_route = r;
|
||||||
|
generation++;
|
||||||
|
notifyListeners();
|
||||||
|
}
|
||||||
|
|
||||||
|
void openTag(String name) => go(TagRoute(name));
|
||||||
void openTitle(String title) => go(PageTarget(title: title));
|
void openTitle(String title) => go(PageTarget(title: title));
|
||||||
void openId(String id) => go(PageTarget(id: id));
|
void openId(String id) => go(PageTarget(id: id));
|
||||||
|
|
||||||
|
|||||||
@@ -275,7 +275,6 @@ class _Header extends StatelessWidget {
|
|||||||
),
|
),
|
||||||
const SizedBox(height: 8),
|
const SizedBox(height: 8),
|
||||||
TagBar(page: page),
|
TagBar(page: page),
|
||||||
if (page.isTag) TaggedNotes(tag: page.title),
|
|
||||||
],
|
],
|
||||||
],
|
],
|
||||||
),
|
),
|
||||||
|
|||||||
@@ -12,6 +12,7 @@ import 'hubs_tree.dart';
|
|||||||
import 'quick_switcher.dart';
|
import 'quick_switcher.dart';
|
||||||
import 'graph_view.dart';
|
import 'graph_view.dart';
|
||||||
import 'settings_view.dart';
|
import 'settings_view.dart';
|
||||||
|
import 'tag_view.dart';
|
||||||
|
|
||||||
/// App frame: sidebar (navigation, hubs, recents), top bar (history, search, theme,
|
/// App frame: sidebar (navigation, hubs, recents), top bar (history, search, theme,
|
||||||
/// settings) and the current view.
|
/// settings) and the current view.
|
||||||
@@ -112,6 +113,7 @@ class _ShellState extends State<Shell> {
|
|||||||
),
|
),
|
||||||
AllPagesRoute() => const AllPagesView(),
|
AllPagesRoute() => const AllPagesView(),
|
||||||
SettingsRoute() => const SettingsView(),
|
SettingsRoute() => const SettingsView(),
|
||||||
|
TagRoute() => TagView(name: route.name),
|
||||||
PageTarget() => PageScreen(target: route),
|
PageTarget() => PageScreen(target: route),
|
||||||
},
|
},
|
||||||
),
|
),
|
||||||
|
|||||||
@@ -0,0 +1,200 @@
|
|||||||
|
import 'package:flutter/material.dart';
|
||||||
|
|
||||||
|
import '../backend/graph_backend.dart';
|
||||||
|
import '../state/app_state.dart';
|
||||||
|
import '../theme/theme.dart';
|
||||||
|
import '../widgets/common.dart';
|
||||||
|
import '../widgets/pickers.dart';
|
||||||
|
|
||||||
|
/// A tag: the pages carrying it (listed in their tags or implied by their type), with
|
||||||
|
/// actions to rename it or remove it from every page. A tag is a name, not a page.
|
||||||
|
class TagView extends StatelessWidget {
|
||||||
|
const TagView({super.key, required this.name});
|
||||||
|
final String name;
|
||||||
|
|
||||||
|
Future<void> _rename(BuildContext context) async {
|
||||||
|
final app = AppScope.read(context);
|
||||||
|
final messenger = ScaffoldMessenger.of(context);
|
||||||
|
final next = await showDialog<String>(
|
||||||
|
context: context,
|
||||||
|
builder: (_) => _RenameDialog(name: name),
|
||||||
|
);
|
||||||
|
if (next == null || next.isEmpty || next == name) return;
|
||||||
|
try {
|
||||||
|
await app.queue.run(
|
||||||
|
() => app.backend.renameTag(name, next),
|
||||||
|
report: false,
|
||||||
|
);
|
||||||
|
app.replaceRoute(TagRoute(next));
|
||||||
|
} catch (e) {
|
||||||
|
messenger.showSnackBar(SnackBar(content: Text(errorText(e))));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
Future<void> _remove(BuildContext context) async {
|
||||||
|
final app = AppScope.read(context);
|
||||||
|
final messenger = ScaffoldMessenger.of(context);
|
||||||
|
final ok = await showDialog<bool>(
|
||||||
|
context: context,
|
||||||
|
builder: (ctx) => AlertDialog(
|
||||||
|
title: Text('Remove #$name?'),
|
||||||
|
content: const Text(
|
||||||
|
'The tag is removed from every page that lists it. Pages whose type '
|
||||||
|
'has this name keep it.',
|
||||||
|
),
|
||||||
|
actions: [
|
||||||
|
TextButton(
|
||||||
|
onPressed: () => Navigator.pop(ctx, false),
|
||||||
|
child: const Text('Cancel'),
|
||||||
|
),
|
||||||
|
TextButton(
|
||||||
|
key: const ValueKey('tag-remove-confirm'),
|
||||||
|
onPressed: () => Navigator.pop(ctx, true),
|
||||||
|
child: const Text('Remove'),
|
||||||
|
),
|
||||||
|
],
|
||||||
|
),
|
||||||
|
);
|
||||||
|
if (ok != true) return;
|
||||||
|
try {
|
||||||
|
await app.queue.run(() => app.backend.removeTag(name), report: false);
|
||||||
|
app.reload();
|
||||||
|
} catch (e) {
|
||||||
|
messenger.showSnackBar(SnackBar(content: Text(errorText(e))));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
@override
|
||||||
|
Widget build(BuildContext context) {
|
||||||
|
final app = AppScope.read(context);
|
||||||
|
final colors = context.colors;
|
||||||
|
return FutureBuilder<List<PageBrief>>(
|
||||||
|
future: app.backend.pagesWithTag(name),
|
||||||
|
builder: (context, snap) {
|
||||||
|
final pages = snap.data;
|
||||||
|
return LayoutBuilder(
|
||||||
|
builder: (context, box) => ListView(
|
||||||
|
padding: EdgeInsets.fromLTRB(
|
||||||
|
sidePadding(box.maxWidth),
|
||||||
|
36,
|
||||||
|
sidePadding(box.maxWidth),
|
||||||
|
80,
|
||||||
|
),
|
||||||
|
children: [
|
||||||
|
Text(
|
||||||
|
'#$name',
|
||||||
|
key: const ValueKey('tag-title'),
|
||||||
|
style: Theme.of(context).textTheme.headlineLarge,
|
||||||
|
),
|
||||||
|
const SizedBox(height: 6),
|
||||||
|
Wrap(
|
||||||
|
spacing: 14,
|
||||||
|
runSpacing: 4,
|
||||||
|
crossAxisAlignment: WrapCrossAlignment.center,
|
||||||
|
children: [
|
||||||
|
Text(
|
||||||
|
pages == null
|
||||||
|
? ''
|
||||||
|
: '${pages.length} ${pages.length == 1 ? 'page' : 'pages'}',
|
||||||
|
key: const ValueKey('tag-count'),
|
||||||
|
style: TextStyle(fontSize: 12.5, color: colors.faint),
|
||||||
|
),
|
||||||
|
TextLink(
|
||||||
|
'Rename',
|
||||||
|
key: const ValueKey('tag-rename'),
|
||||||
|
icon: Icons.edit_outlined,
|
||||||
|
onTap: () => _rename(context),
|
||||||
|
style: const TextStyle(fontSize: 12.5),
|
||||||
|
),
|
||||||
|
TextLink(
|
||||||
|
'Remove from all pages',
|
||||||
|
key: const ValueKey('tag-remove'),
|
||||||
|
icon: Icons.delete_outline_rounded,
|
||||||
|
onTap: () => _remove(context),
|
||||||
|
style: const TextStyle(fontSize: 12.5),
|
||||||
|
),
|
||||||
|
],
|
||||||
|
),
|
||||||
|
const SizedBox(height: 24),
|
||||||
|
if (pages != null && pages.isEmpty)
|
||||||
|
Text(
|
||||||
|
'No pages carry this tag.',
|
||||||
|
style: TextStyle(color: colors.muted),
|
||||||
|
),
|
||||||
|
for (final p in pages ?? const <PageBrief>[])
|
||||||
|
InkWell(
|
||||||
|
key: ValueKey('tag-page-${p.id}'),
|
||||||
|
onTap: () => app.openId(p.id),
|
||||||
|
child: Padding(
|
||||||
|
padding: const EdgeInsets.symmetric(vertical: 8),
|
||||||
|
child: Row(
|
||||||
|
children: [
|
||||||
|
Icon(
|
||||||
|
p.isHub
|
||||||
|
? Icons.folder_outlined
|
||||||
|
: Icons.description_outlined,
|
||||||
|
size: 16,
|
||||||
|
color: colors.faint,
|
||||||
|
),
|
||||||
|
const SizedBox(width: 10),
|
||||||
|
Expanded(
|
||||||
|
child: Text(
|
||||||
|
p.title,
|
||||||
|
overflow: TextOverflow.ellipsis,
|
||||||
|
style: TextStyle(fontSize: 15, color: colors.ink),
|
||||||
|
),
|
||||||
|
),
|
||||||
|
],
|
||||||
|
),
|
||||||
|
),
|
||||||
|
),
|
||||||
|
],
|
||||||
|
),
|
||||||
|
);
|
||||||
|
},
|
||||||
|
);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
class _RenameDialog extends StatefulWidget {
|
||||||
|
const _RenameDialog({required this.name});
|
||||||
|
final String name;
|
||||||
|
|
||||||
|
@override
|
||||||
|
State<_RenameDialog> createState() => _RenameDialogState();
|
||||||
|
}
|
||||||
|
|
||||||
|
class _RenameDialogState extends State<_RenameDialog> {
|
||||||
|
late final _text = TextEditingController(text: widget.name);
|
||||||
|
|
||||||
|
@override
|
||||||
|
void dispose() {
|
||||||
|
_text.dispose();
|
||||||
|
super.dispose();
|
||||||
|
}
|
||||||
|
|
||||||
|
String get _value =>
|
||||||
|
_text.text.trim().replaceFirst(RegExp(r'^#+'), '').trim();
|
||||||
|
|
||||||
|
@override
|
||||||
|
Widget build(BuildContext context) => AlertDialog(
|
||||||
|
title: const Text('Rename tag'),
|
||||||
|
content: TextField(
|
||||||
|
key: const ValueKey('tag-rename-input'),
|
||||||
|
controller: _text,
|
||||||
|
autofocus: true,
|
||||||
|
onSubmitted: (_) => Navigator.pop(context, _value),
|
||||||
|
),
|
||||||
|
actions: [
|
||||||
|
TextButton(
|
||||||
|
onPressed: () => Navigator.pop(context),
|
||||||
|
child: const Text('Cancel'),
|
||||||
|
),
|
||||||
|
TextButton(
|
||||||
|
key: const ValueKey('tag-rename-confirm'),
|
||||||
|
onPressed: () => Navigator.pop(context, _value),
|
||||||
|
child: const Text('Rename'),
|
||||||
|
),
|
||||||
|
],
|
||||||
|
);
|
||||||
|
}
|
||||||
+303
-234
@@ -6,9 +6,9 @@ import '../theme/theme.dart';
|
|||||||
import 'common.dart';
|
import 'common.dart';
|
||||||
import 'pickers.dart';
|
import 'pickers.dart';
|
||||||
|
|
||||||
/// Type and tag chips of a page, each with a remove button, and "Type" / "Tag" links that open
|
/// The page's metadata as one compact wrapping line: the type pill, the tag chips (sorted;
|
||||||
/// a picker. Types are plain names; tags are pages (tapping one opens it). Tag pages cannot
|
/// tapping one opens its [TagRoute]) and a "+ tag" link. A page has at most one type; tags
|
||||||
/// be tagged, so they only get types.
|
/// are names, not pages.
|
||||||
class TagBar extends StatelessWidget {
|
class TagBar extends StatelessWidget {
|
||||||
const TagBar({super.key, required this.page});
|
const TagBar({super.key, required this.page});
|
||||||
final PageDto page;
|
final PageDto page;
|
||||||
@@ -27,258 +27,214 @@ class TagBar extends StatelessWidget {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
Future<void> _add(BuildContext context, {required bool type}) async {
|
Future<void> _pickType(BuildContext context) async {
|
||||||
final app = AppScope.read(context);
|
final app = AppScope.read(context);
|
||||||
final catalog = type
|
final catalog = await app.backend.typeCatalog();
|
||||||
? await app.backend.typeCatalog()
|
|
||||||
: await app.backend.tagCatalog();
|
|
||||||
if (!context.mounted) return;
|
if (!context.mounted) return;
|
||||||
final name = await showDialog<String>(
|
final picked = await showDialog<_TypeChoice>(
|
||||||
|
context: context,
|
||||||
|
builder: (_) => _TypePicker(catalog: catalog, current: page.pageType),
|
||||||
|
);
|
||||||
|
if (picked == null || !context.mounted) return;
|
||||||
|
await _run(context, (b) => b.setPageType(page.id, picked.name));
|
||||||
|
}
|
||||||
|
|
||||||
|
Future<void> _addTags(BuildContext context) async {
|
||||||
|
final app = AppScope.read(context);
|
||||||
|
final catalog = await app.backend.tagCatalog();
|
||||||
|
if (!context.mounted) return;
|
||||||
|
await showDialog<void>(
|
||||||
context: context,
|
context: context,
|
||||||
builder: (_) => _TagPicker(
|
builder: (_) => _TagPicker(
|
||||||
catalog: catalog,
|
catalog: catalog,
|
||||||
taken: type ? page.types : page.tags,
|
taken: page.tags,
|
||||||
label: type ? 'type' : 'tag',
|
onAdd: (name) => _run(context, (b) => b.addPageTag(page.id, name)),
|
||||||
),
|
),
|
||||||
);
|
);
|
||||||
if (name == null || !context.mounted) return;
|
|
||||||
await _run(
|
|
||||||
context,
|
|
||||||
(b) => type ? b.addPageType(page.id, name) : b.addPageTag(page.id, name),
|
|
||||||
);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
Widget _chip(
|
@override
|
||||||
BuildContext context,
|
Widget build(BuildContext context) {
|
||||||
String keyId,
|
final app = AppScope.read(context);
|
||||||
String name, {
|
|
||||||
VoidCallback? onTap,
|
|
||||||
required VoidCallback onRemove,
|
|
||||||
}) {
|
|
||||||
final colors = context.colors;
|
final colors = context.colors;
|
||||||
return Container(
|
final type = page.pageType;
|
||||||
key: ValueKey(keyId),
|
return Wrap(
|
||||||
padding: const EdgeInsets.only(left: 9, right: 3),
|
spacing: 6,
|
||||||
|
runSpacing: 6,
|
||||||
|
crossAxisAlignment: WrapCrossAlignment.center,
|
||||||
|
children: [
|
||||||
|
if (type != null)
|
||||||
|
_TypePill(name: type, onTap: () => _pickType(context))
|
||||||
|
else
|
||||||
|
_GhostPill(
|
||||||
|
key: const ValueKey('add-type'),
|
||||||
|
label: 'Add type',
|
||||||
|
onTap: () => _pickType(context),
|
||||||
|
),
|
||||||
|
for (final t in page.tags)
|
||||||
|
_TagChip(
|
||||||
|
name: t,
|
||||||
|
onTap: () => app.openTag(t),
|
||||||
|
onRemove: () => _run(context, (b) => b.removePageTag(page.id, t)),
|
||||||
|
),
|
||||||
|
TextLink(
|
||||||
|
'+ tag',
|
||||||
|
key: const ValueKey('add-tag'),
|
||||||
|
onTap: () => _addTags(context),
|
||||||
|
style: TextStyle(fontSize: 12.5, color: colors.faint),
|
||||||
|
),
|
||||||
|
],
|
||||||
|
);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
class _TypePill extends StatelessWidget {
|
||||||
|
const _TypePill({required this.name, required this.onTap});
|
||||||
|
final String name;
|
||||||
|
final VoidCallback onTap;
|
||||||
|
|
||||||
|
@override
|
||||||
|
Widget build(BuildContext context) {
|
||||||
|
final colors = context.colors;
|
||||||
|
return MouseRegion(
|
||||||
|
cursor: SystemMouseCursors.click,
|
||||||
|
child: GestureDetector(
|
||||||
|
key: const ValueKey('type-pill'),
|
||||||
|
onTap: onTap,
|
||||||
|
child: Container(
|
||||||
|
padding: const EdgeInsets.symmetric(horizontal: 8, vertical: 2),
|
||||||
decoration: BoxDecoration(
|
decoration: BoxDecoration(
|
||||||
color: colors.surface,
|
color: colors.accentSoft,
|
||||||
borderRadius: BorderRadius.circular(20),
|
borderRadius: BorderRadius.circular(6),
|
||||||
|
),
|
||||||
|
child: Text(
|
||||||
|
name,
|
||||||
|
style: TextStyle(
|
||||||
|
fontSize: 12.5,
|
||||||
|
fontWeight: FontWeight.w600,
|
||||||
|
color: colors.accent,
|
||||||
|
),
|
||||||
|
),
|
||||||
|
),
|
||||||
|
),
|
||||||
|
);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/// Faint outlined pill that invites setting the (missing) type.
|
||||||
|
class _GhostPill extends StatelessWidget {
|
||||||
|
const _GhostPill({super.key, required this.label, required this.onTap});
|
||||||
|
final String label;
|
||||||
|
final VoidCallback onTap;
|
||||||
|
|
||||||
|
@override
|
||||||
|
Widget build(BuildContext context) {
|
||||||
|
final colors = context.colors;
|
||||||
|
return MouseRegion(
|
||||||
|
cursor: SystemMouseCursors.click,
|
||||||
|
child: GestureDetector(
|
||||||
|
onTap: onTap,
|
||||||
|
child: Container(
|
||||||
|
padding: const EdgeInsets.symmetric(horizontal: 8, vertical: 2),
|
||||||
|
decoration: BoxDecoration(
|
||||||
|
border: Border.all(color: colors.line),
|
||||||
|
borderRadius: BorderRadius.circular(6),
|
||||||
|
),
|
||||||
|
child: Text(
|
||||||
|
label,
|
||||||
|
style: TextStyle(fontSize: 12.5, color: colors.faint),
|
||||||
|
),
|
||||||
|
),
|
||||||
|
),
|
||||||
|
);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/// `#name` outlined chip; hovering shows the accent border and a remove button.
|
||||||
|
class _TagChip extends StatefulWidget {
|
||||||
|
const _TagChip({
|
||||||
|
required this.name,
|
||||||
|
required this.onTap,
|
||||||
|
required this.onRemove,
|
||||||
|
});
|
||||||
|
final String name;
|
||||||
|
final VoidCallback onTap;
|
||||||
|
final VoidCallback onRemove;
|
||||||
|
|
||||||
|
@override
|
||||||
|
State<_TagChip> createState() => _TagChipState();
|
||||||
|
}
|
||||||
|
|
||||||
|
class _TagChipState extends State<_TagChip> {
|
||||||
|
bool _hover = false;
|
||||||
|
|
||||||
|
@override
|
||||||
|
Widget build(BuildContext context) {
|
||||||
|
final colors = context.colors;
|
||||||
|
return MouseRegion(
|
||||||
|
onEnter: (_) => setState(() => _hover = true),
|
||||||
|
onExit: (_) => setState(() => _hover = false),
|
||||||
|
child: Container(
|
||||||
|
key: ValueKey('tag-${widget.name}'),
|
||||||
|
padding: const EdgeInsets.symmetric(horizontal: 8, vertical: 2),
|
||||||
|
decoration: BoxDecoration(
|
||||||
|
border: Border.all(color: _hover ? colors.accent : colors.line),
|
||||||
|
borderRadius: BorderRadius.circular(999),
|
||||||
),
|
),
|
||||||
child: Row(
|
child: Row(
|
||||||
mainAxisSize: MainAxisSize.min,
|
mainAxisSize: MainAxisSize.min,
|
||||||
children: [
|
children: [
|
||||||
InkWell(
|
GestureDetector(
|
||||||
onTap: onTap,
|
behavior: HitTestBehavior.opaque,
|
||||||
child: Padding(
|
onTap: widget.onTap,
|
||||||
padding: const EdgeInsets.symmetric(vertical: 3),
|
|
||||||
child: Text(
|
child: Text(
|
||||||
name,
|
'#${widget.name}',
|
||||||
style: TextStyle(fontSize: 12, color: colors.muted),
|
style: TextStyle(fontSize: 12.5, color: colors.muted),
|
||||||
),
|
),
|
||||||
),
|
),
|
||||||
),
|
AnimatedSize(
|
||||||
InkResponse(
|
duration: const Duration(milliseconds: 120),
|
||||||
key: ValueKey('un$keyId'),
|
child: _hover
|
||||||
radius: 10,
|
? GestureDetector(
|
||||||
onTap: onRemove,
|
key: ValueKey('untag-${widget.name}'),
|
||||||
|
behavior: HitTestBehavior.opaque,
|
||||||
|
onTap: widget.onRemove,
|
||||||
child: Padding(
|
child: Padding(
|
||||||
padding: const EdgeInsets.all(4),
|
padding: const EdgeInsets.only(left: 4),
|
||||||
child: Icon(Icons.close_rounded, size: 12, color: colors.faint),
|
child: Icon(
|
||||||
|
Icons.close_rounded,
|
||||||
|
size: 12,
|
||||||
|
color: colors.accent,
|
||||||
),
|
),
|
||||||
),
|
),
|
||||||
],
|
)
|
||||||
),
|
: const SizedBox.shrink(),
|
||||||
);
|
|
||||||
}
|
|
||||||
|
|
||||||
Widget _row(
|
|
||||||
BuildContext context,
|
|
||||||
IconData icon,
|
|
||||||
String label,
|
|
||||||
List<Widget> chips,
|
|
||||||
Widget add,
|
|
||||||
) {
|
|
||||||
final colors = context.colors;
|
|
||||||
return Row(
|
|
||||||
crossAxisAlignment: CrossAxisAlignment.start,
|
|
||||||
children: [
|
|
||||||
SizedBox(
|
|
||||||
width: 76,
|
|
||||||
child: Padding(
|
|
||||||
padding: const EdgeInsets.only(top: 4),
|
|
||||||
child: Row(
|
|
||||||
children: [
|
|
||||||
Icon(icon, size: 13, color: colors.faint),
|
|
||||||
const SizedBox(width: 5),
|
|
||||||
Text(
|
|
||||||
label,
|
|
||||||
style: TextStyle(fontSize: 12, color: colors.faint),
|
|
||||||
),
|
),
|
||||||
],
|
],
|
||||||
),
|
),
|
||||||
),
|
),
|
||||||
),
|
|
||||||
Expanded(
|
|
||||||
child: Wrap(
|
|
||||||
spacing: 6,
|
|
||||||
runSpacing: 6,
|
|
||||||
crossAxisAlignment: WrapCrossAlignment.center,
|
|
||||||
children: [...chips, add],
|
|
||||||
),
|
|
||||||
),
|
|
||||||
],
|
|
||||||
);
|
|
||||||
}
|
|
||||||
|
|
||||||
@override
|
|
||||||
Widget build(BuildContext context) {
|
|
||||||
final app = AppScope.read(context);
|
|
||||||
return Column(
|
|
||||||
crossAxisAlignment: CrossAxisAlignment.start,
|
|
||||||
children: [
|
|
||||||
_row(
|
|
||||||
context,
|
|
||||||
Icons.category_outlined,
|
|
||||||
'Type',
|
|
||||||
[
|
|
||||||
for (final t in page.types)
|
|
||||||
_chip(
|
|
||||||
context,
|
|
||||||
'type-$t',
|
|
||||||
t,
|
|
||||||
onRemove: () =>
|
|
||||||
_run(context, (b) => b.removePageType(page.id, t)),
|
|
||||||
),
|
|
||||||
],
|
|
||||||
TextLink(
|
|
||||||
'+ add',
|
|
||||||
key: const ValueKey('add-type'),
|
|
||||||
onTap: () => _add(context, type: true),
|
|
||||||
style: const TextStyle(fontSize: 12),
|
|
||||||
),
|
|
||||||
),
|
|
||||||
if (!page.isTag) ...[
|
|
||||||
const SizedBox(height: 6),
|
|
||||||
_row(
|
|
||||||
context,
|
|
||||||
Icons.sell_outlined,
|
|
||||||
'Tags',
|
|
||||||
[
|
|
||||||
for (final t in page.tags)
|
|
||||||
_chip(
|
|
||||||
context,
|
|
||||||
'tag-$t',
|
|
||||||
'#$t',
|
|
||||||
onTap: () => app.openTitle(t),
|
|
||||||
onRemove: () =>
|
|
||||||
_run(context, (b) => b.removePageTag(page.id, t)),
|
|
||||||
),
|
|
||||||
],
|
|
||||||
TextLink(
|
|
||||||
'+ add',
|
|
||||||
key: const ValueKey('add-tag'),
|
|
||||||
onTap: () => _add(context, type: false),
|
|
||||||
style: const TextStyle(fontSize: 12),
|
|
||||||
),
|
|
||||||
),
|
|
||||||
],
|
|
||||||
],
|
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Notes carrying the tag page `tag`, as links under the header of the tag page.
|
/// Result of the type picker: a name, or `null` to remove the type.
|
||||||
class TaggedNotes extends StatelessWidget {
|
class _TypeChoice {
|
||||||
const TaggedNotes({super.key, required this.tag});
|
const _TypeChoice(this.name);
|
||||||
final String tag;
|
final String? name;
|
||||||
|
|
||||||
@override
|
|
||||||
Widget build(BuildContext context) {
|
|
||||||
final app = AppScope.read(context);
|
|
||||||
final colors = context.colors;
|
|
||||||
return FutureBuilder<List<PageBrief>>(
|
|
||||||
future: app.backend.pagesWithTag(tag),
|
|
||||||
builder: (context, snap) {
|
|
||||||
final pages = snap.data ?? const <PageBrief>[];
|
|
||||||
if (pages.isEmpty) return const SizedBox.shrink();
|
|
||||||
return Padding(
|
|
||||||
padding: const EdgeInsets.only(top: 10),
|
|
||||||
child: Wrap(
|
|
||||||
key: const ValueKey('tagged-notes'),
|
|
||||||
spacing: 14,
|
|
||||||
runSpacing: 4,
|
|
||||||
children: [
|
|
||||||
Text(
|
|
||||||
'Tagged',
|
|
||||||
style: TextStyle(fontSize: 12, color: colors.faint),
|
|
||||||
),
|
|
||||||
for (final p in pages)
|
|
||||||
TextLink(
|
|
||||||
p.title,
|
|
||||||
icon: Icons.description_outlined,
|
|
||||||
onTap: () => app.openId(p.id),
|
|
||||||
style: const TextStyle(fontSize: 12),
|
|
||||||
),
|
|
||||||
],
|
|
||||||
),
|
|
||||||
);
|
|
||||||
},
|
|
||||||
);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Lists the pages carrying `tag`; picking one opens it.
|
/// Single-select type picker: types in use (with counts), suggestions, free text and
|
||||||
Future<void> showTagPages(BuildContext context, String tag) async {
|
/// "Remove type".
|
||||||
final app = AppScope.read(context);
|
class _TypePicker extends StatefulWidget {
|
||||||
final pages = await app.backend.pagesWithTag(tag);
|
const _TypePicker({required this.catalog, required this.current});
|
||||||
if (!context.mounted) return;
|
|
||||||
await showDialog<void>(
|
|
||||||
context: context,
|
|
||||||
builder: (ctx) => AlertDialog(
|
|
||||||
title: Text(tag),
|
|
||||||
content: SizedBox(
|
|
||||||
width: 360,
|
|
||||||
child: pages.isEmpty
|
|
||||||
? const Text('No notes with this tag yet.')
|
|
||||||
: ListView(
|
|
||||||
shrinkWrap: true,
|
|
||||||
children: [
|
|
||||||
for (final p in pages)
|
|
||||||
ListTile(
|
|
||||||
dense: true,
|
|
||||||
leading: Icon(
|
|
||||||
p.isHub
|
|
||||||
? Icons.folder_outlined
|
|
||||||
: Icons.description_outlined,
|
|
||||||
size: 18,
|
|
||||||
),
|
|
||||||
title: Text(p.title),
|
|
||||||
onTap: () {
|
|
||||||
Navigator.pop(ctx);
|
|
||||||
app.openId(p.id);
|
|
||||||
},
|
|
||||||
),
|
|
||||||
],
|
|
||||||
),
|
|
||||||
),
|
|
||||||
),
|
|
||||||
);
|
|
||||||
}
|
|
||||||
|
|
||||||
class _TagPicker extends StatefulWidget {
|
|
||||||
const _TagPicker({
|
|
||||||
required this.catalog,
|
|
||||||
required this.taken,
|
|
||||||
required this.label,
|
|
||||||
});
|
|
||||||
final List<TagDto> catalog;
|
final List<TagDto> catalog;
|
||||||
final List<String> taken;
|
final String? current;
|
||||||
final String label;
|
|
||||||
|
|
||||||
@override
|
@override
|
||||||
State<_TagPicker> createState() => _TagPickerState();
|
State<_TypePicker> createState() => _TypePickerState();
|
||||||
}
|
}
|
||||||
|
|
||||||
class _TagPickerState extends State<_TagPicker> {
|
class _TypePickerState extends State<_TypePicker> {
|
||||||
final _text = TextEditingController();
|
final _text = TextEditingController();
|
||||||
|
|
||||||
@override
|
@override
|
||||||
@@ -292,17 +248,15 @@ class _TagPickerState extends State<_TagPicker> {
|
|||||||
@override
|
@override
|
||||||
Widget build(BuildContext context) {
|
Widget build(BuildContext context) {
|
||||||
final colors = context.colors;
|
final colors = context.colors;
|
||||||
final taken = {for (final t in widget.taken) t.toLowerCase()};
|
|
||||||
final q = _query.toLowerCase();
|
final q = _query.toLowerCase();
|
||||||
|
final cur = widget.current?.toLowerCase();
|
||||||
final options = [
|
final options = [
|
||||||
for (final t in widget.catalog)
|
for (final t in widget.catalog)
|
||||||
if (!taken.contains(t.name.toLowerCase()) &&
|
if (t.name.toLowerCase() != cur && t.name.toLowerCase().contains(q)) t,
|
||||||
t.name.toLowerCase().contains(q))
|
|
||||||
t,
|
|
||||||
];
|
];
|
||||||
final exact = widget.catalog.any((t) => t.name.toLowerCase() == q);
|
final exact = widget.catalog.any((t) => t.name.toLowerCase() == q);
|
||||||
return AlertDialog(
|
return AlertDialog(
|
||||||
title: Text('Add ${widget.label}'),
|
title: const Text('Type'),
|
||||||
content: SizedBox(
|
content: SizedBox(
|
||||||
width: 360,
|
width: 360,
|
||||||
child: Column(
|
child: Column(
|
||||||
@@ -310,15 +264,17 @@ class _TagPickerState extends State<_TagPicker> {
|
|||||||
crossAxisAlignment: CrossAxisAlignment.start,
|
crossAxisAlignment: CrossAxisAlignment.start,
|
||||||
children: [
|
children: [
|
||||||
TextField(
|
TextField(
|
||||||
key: ValueKey('${widget.label}-input'),
|
key: const ValueKey('type-input'),
|
||||||
controller: _text,
|
controller: _text,
|
||||||
autofocus: true,
|
autofocus: true,
|
||||||
decoration: InputDecoration(
|
decoration: const InputDecoration(
|
||||||
hintText: 'Search or type a new ${widget.label}',
|
hintText: 'Search or type a new type',
|
||||||
),
|
),
|
||||||
onChanged: (_) => setState(() {}),
|
onChanged: (_) => setState(() {}),
|
||||||
onSubmitted: (_) {
|
onSubmitted: (_) {
|
||||||
if (_query.isNotEmpty) Navigator.pop(context, _query);
|
if (_query.isNotEmpty) {
|
||||||
|
Navigator.pop(context, _TypeChoice(_query));
|
||||||
|
}
|
||||||
},
|
},
|
||||||
),
|
),
|
||||||
const SizedBox(height: 12),
|
const SizedBox(height: 12),
|
||||||
@@ -328,16 +284,17 @@ class _TagPickerState extends State<_TagPicker> {
|
|||||||
spacing: 6,
|
spacing: 6,
|
||||||
runSpacing: 6,
|
runSpacing: 6,
|
||||||
children: [
|
children: [
|
||||||
if (_query.isNotEmpty && !exact && !taken.contains(q))
|
if (_query.isNotEmpty && !exact && q != cur)
|
||||||
ActionChip(
|
ActionChip(
|
||||||
key: ValueKey('${widget.label}-create'),
|
key: const ValueKey('type-create'),
|
||||||
avatar: const Icon(Icons.add_rounded, size: 14),
|
avatar: const Icon(Icons.add_rounded, size: 14),
|
||||||
label: Text('Create "$_query"'),
|
label: Text('Create "$_query"'),
|
||||||
onPressed: () => Navigator.pop(context, _query),
|
onPressed: () =>
|
||||||
|
Navigator.pop(context, _TypeChoice(_query)),
|
||||||
),
|
),
|
||||||
for (final t in options)
|
for (final t in options)
|
||||||
ActionChip(
|
ActionChip(
|
||||||
key: ValueKey('${widget.label}-opt-${t.name}'),
|
key: ValueKey('type-opt-${t.name}'),
|
||||||
label: Text(
|
label: Text(
|
||||||
t.count > 0 ? '${t.name} · ${t.count}' : t.name,
|
t.count > 0 ? '${t.name} · ${t.count}' : t.name,
|
||||||
style: TextStyle(
|
style: TextStyle(
|
||||||
@@ -345,7 +302,118 @@ class _TagPickerState extends State<_TagPicker> {
|
|||||||
color: t.count > 0 ? colors.ink : colors.muted,
|
color: t.count > 0 ? colors.ink : colors.muted,
|
||||||
),
|
),
|
||||||
),
|
),
|
||||||
onPressed: () => Navigator.pop(context, t.name),
|
onPressed: () =>
|
||||||
|
Navigator.pop(context, _TypeChoice(t.name)),
|
||||||
|
),
|
||||||
|
],
|
||||||
|
),
|
||||||
|
),
|
||||||
|
),
|
||||||
|
],
|
||||||
|
),
|
||||||
|
),
|
||||||
|
actions: [
|
||||||
|
if (widget.current != null)
|
||||||
|
TextButton(
|
||||||
|
key: const ValueKey('type-remove'),
|
||||||
|
onPressed: () => Navigator.pop(context, const _TypeChoice(null)),
|
||||||
|
child: const Text('Remove type'),
|
||||||
|
),
|
||||||
|
TextButton(
|
||||||
|
onPressed: () => Navigator.pop(context),
|
||||||
|
child: const Text('Cancel'),
|
||||||
|
),
|
||||||
|
],
|
||||||
|
);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/// Multi-add tag picker: every choice is applied at once and the dialog stays open.
|
||||||
|
class _TagPicker extends StatefulWidget {
|
||||||
|
const _TagPicker({
|
||||||
|
required this.catalog,
|
||||||
|
required this.taken,
|
||||||
|
required this.onAdd,
|
||||||
|
});
|
||||||
|
final List<TagDto> catalog;
|
||||||
|
final List<String> taken;
|
||||||
|
final Future<void> Function(String name) onAdd;
|
||||||
|
|
||||||
|
@override
|
||||||
|
State<_TagPicker> createState() => _TagPickerState();
|
||||||
|
}
|
||||||
|
|
||||||
|
class _TagPickerState extends State<_TagPicker> {
|
||||||
|
final _text = TextEditingController();
|
||||||
|
late final _taken = {for (final t in widget.taken) t.toLowerCase()};
|
||||||
|
|
||||||
|
@override
|
||||||
|
void dispose() {
|
||||||
|
_text.dispose();
|
||||||
|
super.dispose();
|
||||||
|
}
|
||||||
|
|
||||||
|
String get _query =>
|
||||||
|
_text.text.trim().replaceFirst(RegExp(r'^#+'), '').trim();
|
||||||
|
|
||||||
|
void _add(String name) {
|
||||||
|
if (name.isEmpty || !_taken.add(name.toLowerCase())) return;
|
||||||
|
_text.clear();
|
||||||
|
setState(() {});
|
||||||
|
widget.onAdd(name);
|
||||||
|
}
|
||||||
|
|
||||||
|
@override
|
||||||
|
Widget build(BuildContext context) {
|
||||||
|
final colors = context.colors;
|
||||||
|
final q = _query.toLowerCase();
|
||||||
|
final options = [
|
||||||
|
for (final t in widget.catalog)
|
||||||
|
if (!_taken.contains(t.name.toLowerCase()) &&
|
||||||
|
t.name.toLowerCase().contains(q))
|
||||||
|
t,
|
||||||
|
];
|
||||||
|
final exact = widget.catalog.any((t) => t.name.toLowerCase() == q);
|
||||||
|
return AlertDialog(
|
||||||
|
title: const Text('Add tags'),
|
||||||
|
content: SizedBox(
|
||||||
|
width: 360,
|
||||||
|
child: Column(
|
||||||
|
mainAxisSize: MainAxisSize.min,
|
||||||
|
crossAxisAlignment: CrossAxisAlignment.start,
|
||||||
|
children: [
|
||||||
|
TextField(
|
||||||
|
key: const ValueKey('tag-input'),
|
||||||
|
controller: _text,
|
||||||
|
autofocus: true,
|
||||||
|
decoration: const InputDecoration(
|
||||||
|
hintText: 'Search or type a new tag',
|
||||||
|
),
|
||||||
|
onChanged: (_) => setState(() {}),
|
||||||
|
onSubmitted: (_) => _add(_query),
|
||||||
|
),
|
||||||
|
const SizedBox(height: 12),
|
||||||
|
Flexible(
|
||||||
|
child: SingleChildScrollView(
|
||||||
|
child: Wrap(
|
||||||
|
spacing: 6,
|
||||||
|
runSpacing: 6,
|
||||||
|
children: [
|
||||||
|
if (_query.isNotEmpty && !exact && !_taken.contains(q))
|
||||||
|
ActionChip(
|
||||||
|
key: const ValueKey('tag-create'),
|
||||||
|
avatar: const Icon(Icons.add_rounded, size: 14),
|
||||||
|
label: Text('Create "$_query"'),
|
||||||
|
onPressed: () => _add(_query),
|
||||||
|
),
|
||||||
|
for (final t in options)
|
||||||
|
ActionChip(
|
||||||
|
key: ValueKey('tag-opt-${t.name}'),
|
||||||
|
label: Text(
|
||||||
|
'${t.name} · ${t.count}',
|
||||||
|
style: TextStyle(fontSize: 12.5, color: colors.ink),
|
||||||
|
),
|
||||||
|
onPressed: () => _add(t.name),
|
||||||
),
|
),
|
||||||
],
|
],
|
||||||
),
|
),
|
||||||
@@ -356,8 +424,9 @@ class _TagPickerState extends State<_TagPicker> {
|
|||||||
),
|
),
|
||||||
actions: [
|
actions: [
|
||||||
TextButton(
|
TextButton(
|
||||||
|
key: const ValueKey('tag-done'),
|
||||||
onPressed: () => Navigator.pop(context),
|
onPressed: () => Navigator.pop(context),
|
||||||
child: const Text('Cancel'),
|
child: const Text('Done'),
|
||||||
),
|
),
|
||||||
],
|
],
|
||||||
);
|
);
|
||||||
|
|||||||
Reference in new issue
Block a user