feat(app): show the type emoji before page names

Page header, All pages, quick switcher, recents, tabs, hub members, tag view,
linked references, related pages, type pill and the tree view; not the network
graph.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
dasemuandClaude Opus 5.5 committed 2026-10-26 06:44:35 +01:00
1 parent a5bee50190
commit 00a64401e0
10 files changed
+430 -46

No files matched your search

+30 -7
View File
@@ -8,13 +8,17 @@ import 'package:flutter/scheduler.dart';
import '../state/app_state.dart';
import '../theme/theme.dart';
import '../widgets/type_icon.dart';
import 'graph_model.dart';
/// A node of the hub / namespace / tag tree.
class TreeItem {
TreeItem(this.label, {this.global, this.isHub = false});
TreeItem(this.label, {this.global, this.isHub = false, this.icon});
final String label;
/// Emoji of the page's type, drawn before [label] (the network view never shows it).
String? icon;
/// Drawn with the folder look.
final bool isHub;
@@ -51,8 +55,13 @@ class TreeItem {
/// split on `/`, straight off the centre) for pages in no hub, then the remaining notes
/// (orphans included) straight off the centre. Journals and tags are left out. Nothing is
/// capped: large branches are collapsed in the canvas instead.
TreeItem buildNamespaceTree(GraphModel g, {String name = 'Graph'}) {
TreeItem buildNamespaceTree(
GraphModel g, {
String name = 'Graph',
String? Function(String? type)? typeIcon,
}) {
final root = TreeItem(name);
String? icon(int i) => typeIcon?.call(g.node(i).pageType);
final placed = <int>{};
bool page(int i) => !g.isJournal(i) && !g.isTag(i);
@@ -61,14 +70,19 @@ TreeItem buildNamespaceTree(GraphModel g, {String name = 'Graph'}) {
final nested = {for (final m in members.values) ...m};
TreeItem? build(int hub) {
if (!placed.add(hub)) return null;
final item = TreeItem(g.node(hub).title, global: hub, isHub: true);
final item = TreeItem(
g.node(hub).title,
global: hub,
isHub: true,
icon: icon(hub),
);
for (final m in members[hub] ?? const <int>{}) {
if (!page(m)) continue;
if (g.isHub(m)) {
final sub = build(m);
if (sub != null) item.children.add(sub);
} else if (placed.add(m)) {
item.children.add(TreeItem(g.node(m).title, global: m));
item.children.add(TreeItem(g.node(m).title, global: m, icon: icon(m)));
}
}
return item;
@@ -101,6 +115,7 @@ TreeItem buildNamespaceTree(GraphModel g, {String name = 'Graph'}) {
final p = byTitle[parts.sublist(0, k + 1).join('/').toLowerCase()];
if (p != null && !placed.contains(p)) {
at.global = p;
at.icon = icon(p);
placed.add(p);
}
}
@@ -110,7 +125,7 @@ TreeItem buildNamespaceTree(GraphModel g, {String name = 'Graph'}) {
// Everything else hangs straight off the centre.
for (var i = 0; i < g.nodeCount; i++) {
if (page(i) && !g.isHub(i) && placed.add(i)) {
root.children.add(TreeItem(g.node(i).title, global: i));
root.children.add(TreeItem(g.node(i).title, global: i, icon: icon(i)));
}
}
_measure(root, 0, null);
@@ -241,9 +256,13 @@ class TreeCanvas extends StatefulWidget {
required this.model,
required this.onTap,
this.name = 'Graph',
this.typeIcon,
});
final GraphModel model;
/// Emoji of a page type, shown before page labels.
final String? Function(String? type)? typeIcon;
/// Label of the centre: the name of the notes store.
final String name;
final void Function(int global) onTap;
@@ -306,7 +325,11 @@ class TreeCanvasState extends State<TreeCanvas> {
}
void _build() {
_root = buildNamespaceTree(widget.model, name: widget.name);
_root = buildNamespaceTree(
widget.model,
name: widget.name,
typeIcon: widget.typeIcon,
);
expandInitial(_root);
_items = const [];
_userMoved = false;
@@ -850,7 +873,7 @@ class _TreePainter extends CustomPainter {
ink,
TextPainter(
text: TextSpan(
text: t.label,
text: withTypeIcon(t.icon, t.label),
style: TextStyle(
fontFamily: uiFont,
fontSize: t.parent == null ? 14 : (branch ? 12.5 : 11.5),
+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;
@@ -303,6 +304,7 @@ class _AllPagesViewState extends State<AllPagesView> {
: colors.faint,
),
),
TypeIcon(p.pageType, size: 14, gap: 6),
Expanded(
child: Text(
p.title,
+1
View File
@@ -442,6 +442,7 @@ class _GraphViewState extends State<GraphView> {
model: m,
onTap: _open,
name: AppScope.read(context).backend.graphName,
typeIcon: AppScope.read(context).typeIcon,
);
}
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),
+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,
+13 -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';
@@ -81,10 +82,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 +145,7 @@ class TagView extends StatelessWidget {
color: colors.faint,
),
const SizedBox(width: 10),
TypeIcon(p.pageType, size: 14, gap: 6),
Expanded(
child: Text(
p.title,
+15 -7
View File
@@ -5,6 +5,7 @@ import '../state/app_state.dart';
import '../theme/theme.dart';
import 'common.dart';
import 'pickers.dart';
import 'type_icon.dart';
/// The page's metadata as one compact wrapping line: the type pill, the tag chips (sorted;
/// tapping one opens its [TagRoute]) and a "+ tag" link. A page has at most one type; tags
@@ -107,13 +108,19 @@ class _TypePill extends StatelessWidget {
color: colors.accentSoft,
borderRadius: BorderRadius.circular(6),
),
child: Text(
name,
style: TextStyle(
fontSize: 12.5,
fontWeight: FontWeight.w600,
color: colors.accent,
),
child: Row(
mainAxisSize: MainAxisSize.min,
children: [
TypeIcon(name, size: 12, gap: 4),
Text(
name,
style: TextStyle(
fontSize: 12.5,
fontWeight: FontWeight.w600,
color: colors.accent,
),
),
],
),
),
),
@@ -295,6 +302,7 @@ class _TypePickerState extends State<_TypePicker> {
for (final t in options)
ActionChip(
key: ValueKey('type-opt-${t.name}'),
avatar: t.icon == null ? null : Text(t.icon!),
label: Text(
t.count > 0 ? '${t.name} · ${t.count}' : t.name,
style: TextStyle(
+288
View File
@@ -0,0 +1,288 @@
import 'package:flutter/material.dart';
import 'package:flutter_test/flutter_test.dart';
import 'package:synapse/src/backend/graph_backend.dart';
import 'package:synapse/src/graph/graph_model.dart';
import 'package:synapse/src/graph/tree_canvas.dart';
import 'package:synapse/src/state/app_state.dart';
import 'package:synapse/src/theme/theme.dart';
import 'package:synapse/src/views/all_pages_view.dart';
import 'package:synapse/src/views/graph_view.dart';
import 'package:synapse/src/views/quick_switcher.dart';
import 'package:synapse/src/views/shell.dart';
import 'package:synapse/src/views/tags_types_view.dart';
import 'package:synapse/src/widgets/emoji_picker.dart';
import 'package:synapse/src/widgets/type_icon.dart';
import 'support/memory_backend.dart';
/// Ada (persona, tag "math"), Bob (persona), Rome (lugar), Notes (untyped).
Future<MemoryBackend> demo() async {
final b = MemoryBackend();
final ada = b.createPage('Ada');
await b.setPageType(ada.id, 'persona');
await b.addPageTag(ada.id, 'math');
await b.setPageType(b.createPage('Bob').id, 'persona');
await b.setPageType(b.createPage('Rome').id, 'lugar');
b.createPage('Notes');
await b.setTypeIcon('persona', '🧑');
return b;
}
Future<AppState> pump(
WidgetTester tester,
MemoryBackend b, {
Widget home = const Shell(),
AppRoute? route,
}) async {
tester.view.physicalSize = const Size(1600, 1000);
tester.view.devicePixelRatio = 1;
addTearDown(tester.view.reset);
final app = AppState(b);
await app.loadTypeIcons();
if (route != null) app.go(route);
await tester.pumpWidget(
AppScope(
state: app,
child: MaterialApp(theme: buildTheme(Brightness.light), home: home),
),
);
await settle(tester);
return app;
}
Future<void> settle(WidgetTester tester) async {
for (var i = 0; i < 6; i++) {
await tester.pump(const Duration(milliseconds: 50));
}
}
PageDto byTitle(MemoryBackend b, String t) =>
b.pages.values.firstWhere((p) => p.title == t);
void main() {
test('single emoji validation', () {
expect(isSingleEmoji('🧑'), isTrue);
expect(isSingleEmoji(' 👨‍👩‍👧 '), isTrue);
expect(isSingleEmoji('🇪🇸'), isTrue);
expect(isSingleEmoji('a'), isFalse);
expect(isSingleEmoji('🧑🧑'), isFalse);
expect(isSingleEmoji(''), isFalse);
});
test(
'memory backend keeps icons through rename and drops them on delete',
() async {
final b = await demo();
expect(await b.renameType('persona', 'Gente'), 2);
var cat = await b.typeCatalog();
expect(cat.firstWhere((t) => t.name == 'Gente').icon, '🧑');
expect(cat.any((t) => t.name == 'persona'), isFalse);
expect(await b.removeType('gente'), 2);
cat = await b.typeCatalog();
expect(cat.any((t) => t.name.toLowerCase() == 'gente'), isFalse);
expect(await b.createType('Libro'), 'Libro');
cat = await b.typeCatalog();
expect(cat.firstWhere((t) => t.name == 'Libro').count, 0);
},
);
testWidgets('sidebar opens Tags & types, also in a tab', (tester) async {
final app = await pump(tester, await demo());
await tester.tap(find.text('Tags & types'));
await settle(tester);
expect(app.route, isA<TagsTypesRoute>());
expect(find.byType(TagsTypesView), findsOneWidget);
expect(app.tab.title, 'Tags & types');
expect(
routeFromJson(routeToJson(const TagsTypesRoute())),
isA<TagsTypesRoute>(),
);
});
testWidgets('types list emoji, counts and unused suggestions', (
tester,
) async {
final b = await demo();
final app = await pump(
tester,
b,
home: const Scaffold(body: TagsTypesView()),
);
final persona = find.byKey(const ValueKey('type-row-persona'));
expect(
find.descendant(of: persona, matching: find.text('🧑')),
findsOneWidget,
);
expect(
find.descendant(of: persona, matching: find.text('2 pages')),
findsOneWidget,
);
expect(find.byKey(const ValueKey('type-row-empresa')), findsOneWidget);
// Pick an emoji for "lugar" from the grid.
await tester.tap(find.byKey(const ValueKey('type-icon-btn-lugar')));
await settle(tester);
await tester.tap(find.byKey(const ValueKey('emoji-Places-📍')));
await settle(tester);
expect(app.typeIcon('Lugar'), '📍');
// A pasted emoji is validated.
await tester.tap(find.byKey(const ValueKey('type-icon-btn-lugar')));
await settle(tester);
await tester.enterText(find.byKey(const ValueKey('emoji-input')), 'xy');
await tester.tap(find.byKey(const ValueKey('emoji-use')));
await settle(tester);
expect(find.text('Enter a single emoji'), findsOneWidget);
await tester.enterText(find.byKey(const ValueKey('emoji-input')), '🗺️');
await tester.tap(find.byKey(const ValueKey('emoji-use')));
await settle(tester);
expect(app.typeIcon('lugar'), '🗺️');
// Clearing it.
await tester.tap(find.byKey(const ValueKey('type-icon-btn-lugar')));
await settle(tester);
await tester.tap(find.byKey(const ValueKey('emoji-clear')));
await settle(tester);
expect(app.typeIcon('lugar'), isNull);
// New type with no pages.
await tester.tap(find.byKey(const ValueKey('new-type')));
await settle(tester);
await tester.enterText(find.byType(TextField).last, 'Libro');
await tester.tap(find.text('Create'));
await settle(tester);
expect(find.byKey(const ValueKey('type-row-Libro')), findsOneWidget);
});
testWidgets('renaming a type keeps its emoji; deleting says what is lost', (
tester,
) async {
final b = await demo();
final app = await pump(
tester,
b,
home: const Scaffold(body: TagsTypesView()),
);
await tester.tap(find.byKey(const ValueKey('type-menu-persona')));
await settle(tester);
await tester.tap(find.text('Rename…'));
await settle(tester);
await tester.enterText(find.byType(TextField).last, 'Gente');
await tester.tap(find.text('Rename').last);
await settle(tester);
expect(byTitle(b, 'Ada').pageType, 'Gente');
expect(app.typeIcon('gente'), '🧑');
await tester.tap(find.byKey(const ValueKey('type-menu-Gente')));
await settle(tester);
await tester.tap(find.text('Delete…'));
await settle(tester);
expect(find.textContaining('2 pages lose this type'), findsOneWidget);
await tester.tap(find.byKey(const ValueKey('tt-confirm')));
await settle(tester);
expect(byTitle(b, 'Ada').pageType, isNull);
expect(byTitle(b, 'Ada').tags, ['math']);
expect(app.typeIcon('gente'), isNull);
expect(find.byKey(const ValueKey('type-row-Gente')), findsNothing);
});
testWidgets('tags: explicit ones can be renamed, hub tags are locked', (
tester,
) async {
final b = await demo();
final hub = b.addHub('Anime');
b.hubsOfPage[byTitle(b, 'Notes').id] = {hub.id};
await pump(tester, b, home: const Scaffold(body: TagsTypesView()));
await tester.tap(find.byKey(const ValueKey('tt-tab-tags')));
await settle(tester);
expect(find.byKey(const ValueKey('tag-menu-math')), findsOneWidget);
expect(find.byKey(const ValueKey('tag-locked-Anime')), findsOneWidget);
expect(find.byKey(const ValueKey('tag-locked-persona')), findsOneWidget);
final tip = tester.widget<Tooltip>(
find.byKey(const ValueKey('tag-locked-Anime')),
);
expect(tip.message, contains('hub'));
await tester.tap(find.byKey(const ValueKey('tag-menu-math')));
await settle(tester);
await tester.tap(find.text('Rename…'));
await settle(tester);
await tester.enterText(find.byType(TextField).last, 'maths');
await tester.tap(find.text('Rename').last);
await settle(tester);
expect(byTitle(b, 'Ada').tags, ['maths']);
// Still on the Tags section after the reload.
expect(find.byKey(const ValueKey('tag-row-maths')), findsOneWidget);
await tester.tap(find.byKey(const ValueKey('tag-menu-maths')));
await settle(tester);
await tester.tap(find.text('Delete…'));
await settle(tester);
await tester.tap(find.byKey(const ValueKey('tt-confirm')));
await settle(tester);
expect(byTitle(b, 'Ada').tags, isEmpty);
});
testWidgets('type emoji sits before page names across the app', (
tester,
) async {
final b = await demo();
final app = await pump(tester, b, route: const AllPagesRoute());
// All pages: Ada and Bob are personas.
expect(
find.descendant(of: find.byType(AllPagesView), matching: find.text('🧑')),
findsNWidgets(2),
);
// Page header, tab strip and recents.
app.go(PageTarget(id: byTitle(b, 'Ada').id));
await settle(tester);
expect(app.tab.pageType, 'persona');
expect(app.tabTypeIcon(app.tab), '🧑');
expect(find.text('🧑'), findsAtLeastNWidgets(3));
// Tag view lists.
app.go(const TagRoute('persona'));
await settle(tester);
expect(find.text('🧑'), findsAtLeastNWidgets(3));
});
testWidgets('quick switcher hits show the emoji', (tester) async {
final b = await demo();
await pump(tester, b, home: const Scaffold(body: QuickSwitcher()));
await tester.enterText(find.byType(TextField), 'Ad');
await settle(tester);
expect(find.text('🧑'), findsOneWidget);
});
testWidgets('network view draws no emoji; the tree does', (tester) async {
final b = await demo();
final app = await pump(
tester,
b,
route: const GraphRoute(GraphMode.network),
);
expect(find.byType(GraphView), findsOneWidget);
expect(find.byKey(const ValueKey('type-icon')), findsNothing);
expect(find.text('🧑'), findsNothing);
final data = await b.graphData();
final ada = data.nodes.firstWhere((n) => n.title == 'Ada');
expect(ada.title, 'Ada', reason: 'network labels are plain titles');
final root = buildNamespaceTree(GraphModel(data), typeIcon: app.typeIcon);
final items = <TreeItem>[];
void walk(TreeItem t) {
items.add(t);
t.children.forEach(walk);
}
walk(root);
expect(items.firstWhere((t) => t.label == 'Ada').icon, '🧑');
expect(items.firstWhere((t) => t.label == 'Rome').icon, isNull);
expect(withTypeIcon('🧑', 'Ada'), '🧑 Ada');
});
test('graph nodes from the memory backend carry the page type', () async {
final b = await demo();
final data = await b.graphData();
expect(data.nodes.firstWhere((n) => n.title == 'Rome').pageType, 'lugar');
});
}