Merge branch 'feat/tags-types-view' into feat/settings-theme-tree

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
dasemuandClaude Opus 5.5 committed 2026-10-26 06:56:25 +01:00
commit 12c3cd463b
45 files changed
+3142 -248

No files matched your search

+2
View File
@@ -3,6 +3,7 @@ import 'package:flutter/material.dart';
import '../backend/graph_backend.dart';
import '../state/app_state.dart';
import '../theme/theme.dart';
import '../widgets/type_icon.dart';
import '../widgets/common.dart';
import '../widgets/dates.dart';
import '../widgets/pickers.dart' show errorText;
@@ -309,6 +310,7 @@ class _AllPagesViewState extends State<AllPagesView> {
: colors.faint,
),
),
TypeIcon(p.pageType, size: 14, gap: 6),
Expanded(
child: Text(
p.title,
+3
View File
@@ -442,6 +442,9 @@ class _GraphViewState extends State<GraphView> {
model: m,
onTap: _open,
name: AppScope.read(context).backend.graphName,
typeIcon: AppScope.read(context).typeIcon,
// Subscribes: icon edits (or icons loaded after a cold start) reach the labels.
iconsVersion: AppScope.of(context).iconsVersion,
);
}
final sub = _sub;
+2
View File
@@ -3,6 +3,7 @@ import 'package:flutter/material.dart';
import '../backend/graph_backend.dart';
import '../state/app_state.dart';
import '../theme/theme.dart';
import '../widgets/type_icon.dart';
import '../widgets/common.dart';
import '../widgets/dates.dart';
import '../widgets/pickers.dart';
@@ -296,6 +297,7 @@ class _MemberRowState extends State<_MemberRow> {
color: colors.accent.withAlpha(0xCC),
),
const SizedBox(width: 10),
TypeIcon(m.pageType, size: 14, gap: 6),
Expanded(
child: Text(
m.title,
+42 -17
View File
@@ -5,6 +5,7 @@ import '../editor/outline_view.dart';
import '../state/app_state.dart';
import '../state/outline_controller.dart';
import '../theme/theme.dart';
import '../widgets/type_icon.dart';
import '../widgets/common.dart';
import '../widgets/dates.dart';
import '../widgets/pickers.dart';
@@ -239,6 +240,10 @@ class _Header extends StatelessWidget {
Row(
crossAxisAlignment: CrossAxisAlignment.start,
children: [
Padding(
padding: const EdgeInsets.only(top: 4),
child: TypeIcon(page.pageType, size: 26, gap: 10),
),
Expanded(child: TitleField(page: page)),
IconButton(
key: const ValueKey('page-sidebar-toggle'),
@@ -471,16 +476,24 @@ class _LinkedReferences extends StatelessWidget {
child: Column(
crossAxisAlignment: CrossAxisAlignment.start,
children: [
TextLink(
group.isJournal
? longDate(group.pageTitle)
: group.pageTitle,
onTap: () => app.openId(group.pageId),
style: TextStyle(
fontSize: 13,
fontWeight: FontWeight.w600,
color: colors.ink,
),
Row(
mainAxisSize: MainAxisSize.min,
children: [
TypeIcon(group.pageType),
Flexible(
child: TextLink(
group.isJournal
? longDate(group.pageTitle)
: group.pageTitle,
onTap: () => app.openId(group.pageId),
style: TextStyle(
fontSize: 13,
fontWeight: FontWeight.w600,
color: colors.ink,
),
),
),
],
),
const SizedBox(height: 4),
for (final b in group.blocks)
@@ -544,13 +557,25 @@ class RelatedPanel extends StatelessWidget {
child: Column(
crossAxisAlignment: CrossAxisAlignment.start,
children: [
TextLink(
x.page.isJournal ? longDate(x.page.title) : x.page.title,
icon: x.page.isJournal
? Icons.calendar_today_outlined
: Icons.description_outlined,
onTap: () => app.openId(x.page.id),
style: TextStyle(fontSize: 13.5, color: colors.ink),
Row(
mainAxisSize: MainAxisSize.min,
children: [
TypeIcon(x.page.pageType),
Flexible(
child: TextLink(
x.page.isJournal
? longDate(x.page.title)
: x.page.title,
icon: app.typeIcon(x.page.pageType) != null
? null
: x.page.isJournal
? Icons.calendar_today_outlined
: Icons.description_outlined,
onTap: () => app.openId(x.page.id),
style: TextStyle(fontSize: 13.5, color: colors.ink),
),
),
],
),
const SizedBox(height: 4),
ClipRRect(
+18 -5
View File
@@ -4,6 +4,7 @@ import 'package:flutter/services.dart';
import '../backend/graph_backend.dart';
import '../state/app_state.dart';
import '../theme/theme.dart';
import '../widgets/type_icon.dart';
/// Ctrl+K: jump to a page by title or alias, to a page whose blocks contain the text, or
/// create it.
@@ -168,6 +169,7 @@ class _QuickSwitcherState extends State<QuickSwitcher> {
onMiddle: () => _open(i, newTab: true),
icon: Icons.description_outlined,
title: _hits[i].title,
pageType: _hits[i].pageType,
detail: _hits[i].isAlias ? 'alias' : null,
),
if (_blocks.isNotEmpty)
@@ -217,6 +219,7 @@ class _Item extends StatelessWidget {
required this.onMiddle,
this.detail,
this.snippet,
this.pageType,
});
final bool selected;
final VoidCallback onTap;
@@ -225,6 +228,9 @@ class _Item extends StatelessWidget {
final String title;
final String? detail;
/// Type of the page hit (its emoji goes before the title).
final String? pageType;
/// Matching text shown under the title (content results).
final Widget? snippet;
@@ -254,11 +260,18 @@ class _Item extends StatelessWidget {
child: Column(
crossAxisAlignment: CrossAxisAlignment.start,
children: [
Text(
title,
maxLines: 1,
overflow: TextOverflow.ellipsis,
style: TextStyle(fontSize: 14, color: colors.ink),
Row(
children: [
TypeIcon(pageType),
Expanded(
child: Text(
title,
maxLines: 1,
overflow: TextOverflow.ellipsis,
style: TextStyle(fontSize: 14, color: colors.ink),
),
),
],
),
if (snippet != null) ...[
const SizedBox(height: 2),
+16
View File
@@ -16,6 +16,8 @@ import 'graph_view.dart';
import 'settings_view.dart';
import 'tab_strip.dart';
import 'tag_view.dart';
import 'tags_types_view.dart';
import '../widgets/type_icon.dart';
/// App frame: sidebar (navigation, hubs, recents), top bar (history, search, theme,
/// settings) and the current view.
@@ -132,6 +134,7 @@ class _ShellState extends State<Shell> {
),
AllPagesRoute() => const AllPagesView(),
SettingsRoute() => const SettingsView(),
TagsTypesRoute() => const TagsTypesView(),
TagRoute() => TagView(name: route.name),
PageTarget() => PageScreen(target: route),
},
@@ -323,6 +326,13 @@ class _Sidebar extends StatelessWidget {
onTap: () => go(const AllPagesRoute()),
onMiddle: () => newTab(const AllPagesRoute()),
),
_NavItem(
icon: Icons.style_outlined,
label: 'Tags & types',
selected: route is TagsTypesRoute,
onTap: () => go(const TagsTypesRoute()),
onMiddle: () => newTab(const TagsTypesRoute()),
),
const SizedBox(height: 22),
Expanded(
child: ListView(
@@ -342,6 +352,7 @@ class _Sidebar extends StatelessWidget {
for (final p in app.recent)
_NavItem(
label: p.isJournal ? longDate(p.title) : p.title,
leading: TypeIcon(p.pageType),
selected: route is PageTarget && route.id == p.id,
dense: true,
onTap: () => go(PageTarget(id: p.id)),
@@ -360,6 +371,7 @@ class _Sidebar extends StatelessWidget {
class _NavItem extends StatefulWidget {
const _NavItem({
this.icon,
this.leading,
required this.label,
required this.selected,
required this.onTap,
@@ -367,6 +379,9 @@ class _NavItem extends StatefulWidget {
this.dense = false,
});
final IconData? icon;
/// Shown before the label (a page's type emoji).
final Widget? leading;
final String label;
final bool selected;
final VoidCallback onTap;
@@ -417,6 +432,7 @@ class _NavItemState extends State<_NavItem> {
),
const SizedBox(width: 10),
],
?widget.leading,
Expanded(
child: Text(
widget.label,
+19 -6
View File
@@ -115,11 +115,18 @@ class _TabItemState extends State<_TabItem> {
),
child: Row(
children: [
Icon(
widget.tab.icon,
size: 13,
color: active ? colors.accent : colors.faint,
),
if (app.tabTypeIcon(widget.tab) case final emoji?)
Text(
emoji,
key: const ValueKey('type-icon'),
style: const TextStyle(fontSize: 12.5, height: 1.15),
)
else
Icon(
widget.tab.icon,
size: 13,
color: active ? colors.accent : colors.faint,
),
const SizedBox(width: 7),
Expanded(
child: Text(
@@ -215,7 +222,13 @@ Future<void> showTabsSheet(BuildContext context) {
dense: true,
selected: i == app.activeTab,
selectedColor: colors.accent,
leading: Icon(tabs[i].icon, size: 18),
leading: switch (app.tabTypeIcon(tabs[i])) {
final String emoji => Text(
emoji,
style: const TextStyle(fontSize: 16),
),
null => Icon(tabs[i].icon, size: 18),
},
title: Text(
tabs[i].title,
maxLines: 1,
+16 -4
View File
@@ -3,6 +3,7 @@ import 'package:flutter/material.dart';
import '../backend/graph_backend.dart';
import '../state/app_state.dart';
import '../theme/theme.dart';
import '../widgets/type_icon.dart';
import '../widgets/common.dart';
import '../widgets/pickers.dart';
@@ -25,6 +26,8 @@ class TagView extends StatelessWidget {
() => app.backend.renameTag(name, next),
report: false,
);
// A type of that name moves its emoji to the new name.
await app.loadTypeIcons();
app.replaceRoute(TagRoute(next));
} catch (e) {
messenger.showSnackBar(SnackBar(content: Text(errorText(e))));
@@ -58,6 +61,7 @@ class TagView extends StatelessWidget {
if (ok != true) return;
try {
await app.queue.run(() => app.backend.removeTag(name), report: false);
await app.loadTypeIcons();
app.reload();
} catch (e) {
messenger.showSnackBar(SnackBar(content: Text(errorText(e))));
@@ -81,10 +85,17 @@ class TagView extends StatelessWidget {
80,
),
children: [
Text(
'#$name',
key: const ValueKey('tag-title'),
style: Theme.of(context).textTheme.headlineLarge,
Row(
children: [
TypeIcon(name, size: 26, gap: 10),
Expanded(
child: Text(
'#$name',
key: const ValueKey('tag-title'),
style: Theme.of(context).textTheme.headlineLarge,
),
),
],
),
const SizedBox(height: 6),
Wrap(
@@ -137,6 +148,7 @@ class TagView extends StatelessWidget {
color: colors.faint,
),
const SizedBox(width: 10),
TypeIcon(p.pageType, size: 14, gap: 6),
Expanded(
child: Text(
p.title,
+394
View File
@@ -0,0 +1,394 @@
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/emoji_picker.dart';
import '../widgets/pickers.dart';
/// Manages the vocabulary. Types: emoji (shown before the names of their pages), name and
/// page count; create, rename, delete. Tags: name, page count and where they come from
/// (listed on pages, a type, a hub); explicit ones can be renamed or removed. Tapping a name
/// opens its tag view.
class TagsTypesView extends StatefulWidget {
const TagsTypesView({super.key});
@override
State<TagsTypesView> createState() => _TagsTypesViewState();
}
class _TagsTypesViewState extends State<TagsTypesView> {
bool _tags = false;
late Future<(List<TagDto>, List<TagDto>)> _data = _load();
Future<(List<TagDto>, List<TagDto>)> _load() async {
final backend = AppScope.read(context).backend;
return (await backend.typeCatalog(), await backend.tagCatalog());
}
void _reload() {
AppScope.read(context).loadTypeIcons().ignore();
setState(() {
_data = _load();
});
}
/// Runs a write through the queue (errors become a snack bar), then reloads the lists.
Future<void> _run(Future<void> Function(GraphBackend b) op) async {
final app = AppScope.read(context);
final messenger = ScaffoldMessenger.of(context);
try {
await app.queue.run(() => op(app.backend), report: false);
} catch (e) {
messenger.showSnackBar(SnackBar(content: Text(errorText(e))));
} finally {
if (mounted) _reload();
}
}
Future<void> _newType() async {
final app = AppScope.read(context);
await showNameDialog<String>(
context,
heading: 'New type',
confirm: 'Create',
hint: 'Type name',
submit: (name) =>
app.queue.run(() => app.backend.createType(name), report: false),
);
if (mounted) _reload();
}
Future<void> _pickIcon(TagDto t) async {
final picked = await showEmojiPicker(
context,
title: 'Emoji for ${t.name}',
current: t.icon,
);
if (picked == null || picked.emoji == t.icon) return;
await _run((b) => b.setTypeIcon(t.name, picked.emoji));
}
Future<void> _renameType(TagDto t) async {
final app = AppScope.read(context);
await showNameDialog<int>(
context,
heading: 'Rename type',
confirm: 'Rename',
hint: 'Type name',
initial: t.name,
submit: (name) => app.queue.run(
() => app.backend.renameType(t.name, name),
report: false,
),
);
if (mounted) _reload();
}
Future<void> _deleteType(TagDto t) async {
final ok = await _confirm(
title: 'Delete type “${t.name}”?',
body: t.count == 0
? 'No page has this type. Its emoji is removed too.'
: '${_pages(t.count)} lose this type (their tags stay). '
'Its emoji is removed too.',
action: 'Delete',
);
if (ok) await _run((b) => b.removeType(t.name));
}
Future<void> _renameTag(TagDto t) async {
final app = AppScope.read(context);
await showNameDialog<int>(
context,
heading: 'Rename tag',
confirm: 'Rename',
hint: 'Tag name',
initial: t.name,
submit: (name) => app.queue.run(
() => app.backend.renameTag(t.name, name),
report: false,
),
);
if (mounted) _reload();
}
Future<void> _deleteTag(TagDto t) async {
final ok = await _confirm(
title: 'Delete tag #${t.name}?',
body:
'It is removed from the ${_pages(t.explicit)} that list it.'
'${t.typed > 0 ? ' Pages with the type “${t.name}” keep it.' : ''}'
'${t.fromHub > 0 ? ' Members of the hub “${t.name}” keep it.' : ''}',
action: 'Delete',
);
if (ok) await _run((b) => b.removeTag(t.name));
}
Future<bool> _confirm({
required String title,
required String body,
required String action,
}) async =>
await showDialog<bool>(
context: context,
builder: (ctx) => AlertDialog(
title: Text(title),
content: Text(body),
actions: [
TextButton(
onPressed: () => Navigator.pop(ctx, false),
child: const Text('Cancel'),
),
TextButton(
key: const ValueKey('tt-confirm'),
onPressed: () => Navigator.pop(ctx, true),
child: Text(action),
),
],
),
) ??
false;
@override
Widget build(BuildContext context) {
final colors = context.colors;
return FutureBuilder<(List<TagDto>, List<TagDto>)>(
future: _data,
builder: (context, snap) {
final data = snap.data;
return LayoutBuilder(
builder: (context, box) => ListView(
padding: EdgeInsets.fromLTRB(
sidePadding(box.maxWidth),
36,
sidePadding(box.maxWidth),
80,
),
children: [
Text(
'Tags & types',
style: Theme.of(context).textTheme.headlineLarge,
),
const SizedBox(height: 6),
Text(
'A type says what a page is (one per page) and shows its emoji '
'before the page’s name. Tags file pages under topics.',
style: TextStyle(fontSize: 12.5, color: colors.faint),
),
const SizedBox(height: 16),
Row(
children: [
SegmentedButton<bool>(
showSelectedIcon: false,
segments: [
ButtonSegment(
value: false,
label: Text(
'Types',
key: const ValueKey('tt-tab-types'),
),
),
ButtonSegment(
value: true,
label: Text('Tags', key: const ValueKey('tt-tab-tags')),
),
],
selected: {_tags},
onSelectionChanged: (s) => setState(() => _tags = s.first),
),
const Spacer(),
if (!_tags)
TextButton.icon(
key: const ValueKey('new-type'),
onPressed: _newType,
icon: const Icon(Icons.add_rounded, size: 18),
label: const Text('New type'),
),
],
),
const SizedBox(height: 12),
if (data == null)
const SizedBox.shrink()
else if (_tags)
..._tagRows(data.$2)
else
..._typeRows(data.$1),
],
),
);
},
);
}
Iterable<Widget> _typeRows(List<TagDto> types) sync* {
final colors = context.colors;
final app = AppScope.read(context);
if (types.isEmpty) {
yield Text('No types yet.', style: TextStyle(color: colors.muted));
}
for (final t in types) {
yield _Row(
key: ValueKey('type-row-${t.name}'),
leading: Tooltip(
message: t.icon == null ? 'Choose an emoji' : 'Change the emoji',
child: InkWell(
key: ValueKey('type-icon-btn-${t.name}'),
borderRadius: BorderRadius.circular(8),
onTap: () => _pickIcon(t),
child: Container(
width: 34,
height: 34,
alignment: Alignment.center,
decoration: BoxDecoration(
color: colors.surface,
border: Border.all(color: colors.line),
borderRadius: BorderRadius.circular(8),
),
child: t.icon == null
? Icon(
Icons.add_reaction_outlined,
size: 17,
color: colors.faint,
)
: Text(t.icon!, style: const TextStyle(fontSize: 18)),
),
),
),
name: t.name,
detail: t.count == 0
? (t.suggested ? 'suggested · no pages' : 'no pages')
: _pages(t.count),
onOpen: () => app.navigate(TagRoute(t.name)),
menu: PopupMenuButton<String>(
key: ValueKey('type-menu-${t.name}'),
tooltip: 'Type actions',
icon: Icon(Icons.more_horiz_rounded, color: colors.muted, size: 20),
onSelected: (v) => switch (v) {
'icon' => _pickIcon(t),
'rename' => _renameType(t),
_ => _deleteType(t),
},
itemBuilder: (_) => const [
PopupMenuItem(value: 'icon', child: Text('Emoji…')),
PopupMenuItem(value: 'rename', child: Text('Rename…')),
PopupMenuItem(value: 'delete', child: Text('Delete…')),
],
),
);
}
}
Iterable<Widget> _tagRows(List<TagDto> tags) sync* {
final colors = context.colors;
final app = AppScope.read(context);
if (tags.isEmpty) {
yield Text('No tags yet.', style: TextStyle(color: colors.muted));
}
for (final t in tags) {
final sources = [
if (t.explicit > 0) 'listed on ${t.explicit}',
if (t.typed > 0) 'type',
if (t.fromHub > 0) 'hub',
];
final String? locked = t.explicit > 0
? null
: t.fromHub > 0
? 'Comes from the hub “${t.name}”: rename or delete the hub instead.'
: 'Comes from the type “${t.name}”: manage it under Types.';
yield _Row(
key: ValueKey('tag-row-${t.name}'),
leading: Icon(Icons.sell_outlined, size: 17, color: colors.faint),
name: '#${t.name}',
detail: '${_pages(t.count)} · ${sources.join(', ')}',
onOpen: () => app.navigate(TagRoute(t.name)),
menu: locked != null
? Tooltip(
key: ValueKey('tag-locked-${t.name}'),
message: locked,
child: Padding(
padding: const EdgeInsets.all(12),
child: Icon(
Icons.lock_outline_rounded,
size: 17,
color: colors.faint,
),
),
)
: PopupMenuButton<String>(
key: ValueKey('tag-menu-${t.name}'),
tooltip: 'Tag actions',
icon: Icon(
Icons.more_horiz_rounded,
color: colors.muted,
size: 20,
),
onSelected: (v) =>
v == 'rename' ? _renameTag(t) : _deleteTag(t),
itemBuilder: (_) => const [
PopupMenuItem(value: 'rename', child: Text('Rename…')),
PopupMenuItem(value: 'delete', child: Text('Delete…')),
],
),
);
}
}
}
String _pages(int n) => '$n ${n == 1 ? 'page' : 'pages'}';
class _Row extends StatelessWidget {
const _Row({
super.key,
required this.leading,
required this.name,
required this.detail,
required this.onOpen,
required this.menu,
});
final Widget leading;
final String name;
final String detail;
final VoidCallback onOpen;
final Widget menu;
@override
Widget build(BuildContext context) {
final colors = context.colors;
return Padding(
padding: const EdgeInsets.symmetric(vertical: 3),
child: Row(
children: [
leading,
const SizedBox(width: 12),
Expanded(
child: InkWell(
borderRadius: BorderRadius.circular(6),
onTap: onOpen,
child: Padding(
padding: const EdgeInsets.symmetric(vertical: 6),
child: Column(
crossAxisAlignment: CrossAxisAlignment.start,
children: [
Text(
name,
maxLines: 1,
overflow: TextOverflow.ellipsis,
style: TextStyle(fontSize: 14.5, color: colors.ink),
),
Text(
detail,
style: TextStyle(fontSize: 12, color: colors.faint),
),
],
),
),
),
),
menu,
],
),
);
}
}