mirror of
https://github.com/Dasemu/Synapse.git
synced 2026-11-26 23:36:20 +00:00
feat(app): Tags & types view with an emoji picker for types
Sidebar entry and tab route. Types: emoji, count, create, rename, delete. Tags: count and sources; explicit tags can be renamed or deleted, hub and type tags are locked with an explanation. AppState caches type icons. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
1 parent
381e9044c4
commit
a5bee50190
7 files changed
+827
-6
No files matched your search
@@ -16,10 +16,10 @@ class SynapseApp extends StatefulWidget {
|
|||||||
}
|
}
|
||||||
|
|
||||||
class _SynapseAppState extends State<SynapseApp> {
|
class _SynapseAppState extends State<SynapseApp> {
|
||||||
late final AppState _state = AppState(
|
late final AppState _state =
|
||||||
widget.backend,
|
AppState(widget.backend, settings: widget.settings)
|
||||||
settings: widget.settings,
|
..loadRecent()
|
||||||
)..loadRecent();
|
..loadTypeIcons();
|
||||||
|
|
||||||
@override
|
@override
|
||||||
void dispose() {
|
void dispose() {
|
||||||
|
|||||||
@@ -31,6 +31,11 @@ class SettingsRoute extends AppRoute {
|
|||||||
const SettingsRoute();
|
const SettingsRoute();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/// Manage the vocabulary: types (with their emoji) and tags.
|
||||||
|
class TagsTypesRoute extends AppRoute {
|
||||||
|
const TagsTypesRoute();
|
||||||
|
}
|
||||||
|
|
||||||
enum GraphMode {
|
enum GraphMode {
|
||||||
network('Network', Icons.hub_outlined),
|
network('Network', Icons.hub_outlined),
|
||||||
brain('Synapses', Icons.bolt_outlined),
|
brain('Synapses', Icons.bolt_outlined),
|
||||||
@@ -81,6 +86,9 @@ class AppTab {
|
|||||||
/// Title of a page route (the route only has an id); set once the page is shown.
|
/// Title of a page route (the route only has an id); set once the page is shown.
|
||||||
String? label;
|
String? label;
|
||||||
|
|
||||||
|
/// Type of the page shown (for its emoji next to [title]); set with [label].
|
||||||
|
String? pageType;
|
||||||
|
|
||||||
/// Stable identity for widget keys (reordering, closing).
|
/// Stable identity for widget keys (reordering, closing).
|
||||||
final int uid = _nextUid++;
|
final int uid = _nextUid++;
|
||||||
static int _nextUid = 0;
|
static int _nextUid = 0;
|
||||||
@@ -90,6 +98,7 @@ class AppTab {
|
|||||||
TimelineRoute() => 'Timeline',
|
TimelineRoute() => 'Timeline',
|
||||||
AllPagesRoute() => 'All pages',
|
AllPagesRoute() => 'All pages',
|
||||||
SettingsRoute() => 'Settings',
|
SettingsRoute() => 'Settings',
|
||||||
|
TagsTypesRoute() => 'Tags & types',
|
||||||
TagRoute(:final name) => '#$name',
|
TagRoute(:final name) => '#$name',
|
||||||
GraphRoute() => 'Graph',
|
GraphRoute() => 'Graph',
|
||||||
PageTarget(:final title) => label ?? title ?? 'Page',
|
PageTarget(:final title) => label ?? title ?? 'Page',
|
||||||
@@ -100,6 +109,7 @@ class AppTab {
|
|||||||
TimelineRoute() => Icons.timeline_rounded,
|
TimelineRoute() => Icons.timeline_rounded,
|
||||||
AllPagesRoute() => Icons.description_outlined,
|
AllPagesRoute() => Icons.description_outlined,
|
||||||
SettingsRoute() => Icons.settings_outlined,
|
SettingsRoute() => Icons.settings_outlined,
|
||||||
|
TagsTypesRoute() => Icons.style_outlined,
|
||||||
TagRoute() => Icons.sell_outlined,
|
TagRoute() => Icons.sell_outlined,
|
||||||
GraphRoute() => Icons.hub_outlined,
|
GraphRoute() => Icons.hub_outlined,
|
||||||
PageTarget() => Icons.article_outlined,
|
PageTarget() => Icons.article_outlined,
|
||||||
@@ -116,6 +126,7 @@ Map<String, dynamic>? routeToJson(AppRoute r, {String? label}) => switch (r) {
|
|||||||
TimelineRoute() => {'t': 'timeline'},
|
TimelineRoute() => {'t': 'timeline'},
|
||||||
AllPagesRoute() => {'t': 'all'},
|
AllPagesRoute() => {'t': 'all'},
|
||||||
SettingsRoute() => {'t': 'settings'},
|
SettingsRoute() => {'t': 'settings'},
|
||||||
|
TagsTypesRoute() => {'t': 'tags-types'},
|
||||||
TagRoute() => {'t': 'tag', 'name': r.name},
|
TagRoute() => {'t': 'tag', 'name': r.name},
|
||||||
GraphRoute() => {
|
GraphRoute() => {
|
||||||
't': 'graph',
|
't': 'graph',
|
||||||
@@ -142,6 +153,8 @@ AppRoute? routeFromJson(Object? j) {
|
|||||||
return const AllPagesRoute();
|
return const AllPagesRoute();
|
||||||
case 'settings':
|
case 'settings':
|
||||||
return const SettingsRoute();
|
return const SettingsRoute();
|
||||||
|
case 'tags-types':
|
||||||
|
return const TagsTypesRoute();
|
||||||
case 'tag':
|
case 'tag':
|
||||||
final name = j['name'];
|
final name = j['name'];
|
||||||
return name is String && name.isNotEmpty ? TagRoute(name) : null;
|
return name is String && name.isNotEmpty ? TagRoute(name) : null;
|
||||||
@@ -338,6 +351,29 @@ class AppState extends ChangeNotifier {
|
|||||||
/// Bumped to make the current view reload from the core (failed writes, renames).
|
/// Bumped to make the current view reload from the core (failed writes, renames).
|
||||||
int generation = 0;
|
int generation = 0;
|
||||||
|
|
||||||
|
/// Emoji of each type, by lower-cased type name (types are names; see [typeIcon]).
|
||||||
|
final Map<String, String> typeIcons = {};
|
||||||
|
|
||||||
|
/// The emoji of a page type, if it has one.
|
||||||
|
String? typeIcon(String? type) =>
|
||||||
|
type == null ? null : typeIcons[type.trim().toLowerCase()];
|
||||||
|
|
||||||
|
/// The type emoji of the page a tab shows (null for other routes).
|
||||||
|
String? tabTypeIcon(AppTab t) =>
|
||||||
|
t.route is PageTarget ? typeIcon(t.pageType) : null;
|
||||||
|
|
||||||
|
/// Reloads [typeIcons] from the type catalogue (at start and after type edits).
|
||||||
|
Future<void> loadTypeIcons() async {
|
||||||
|
final types = await backend.typeCatalog();
|
||||||
|
typeIcons
|
||||||
|
..clear()
|
||||||
|
..addAll({
|
||||||
|
for (final t in types)
|
||||||
|
if (t.icon != null) t.name.toLowerCase(): t.icon!,
|
||||||
|
});
|
||||||
|
notifyListeners();
|
||||||
|
}
|
||||||
|
|
||||||
/// Hubs expanded in the sidebar tree (kept here so it survives sidebar rebuilds).
|
/// Hubs expanded in the sidebar tree (kept here so it survives sidebar rebuilds).
|
||||||
final expandedHubs = <String>{};
|
final expandedHubs = <String>{};
|
||||||
|
|
||||||
@@ -380,6 +416,7 @@ class AppState extends ChangeNotifier {
|
|||||||
t.forward.clear();
|
t.forward.clear();
|
||||||
t.route = r;
|
t.route = r;
|
||||||
t.label = null;
|
t.label = null;
|
||||||
|
t.pageType = null;
|
||||||
_saveSettings();
|
_saveSettings();
|
||||||
notifyListeners();
|
notifyListeners();
|
||||||
}
|
}
|
||||||
@@ -548,6 +585,7 @@ class AppState extends ChangeNotifier {
|
|||||||
tab.label = label;
|
tab.label = label;
|
||||||
_saveSettings();
|
_saveSettings();
|
||||||
}
|
}
|
||||||
|
tab.pageType = page.pageType;
|
||||||
}
|
}
|
||||||
recent.removeWhere((p) => p.id == page.id);
|
recent.removeWhere((p) => p.id == page.id);
|
||||||
// Hubs are folders, not pages: they never show up in recents.
|
// Hubs are folders, not pages: they never show up in recents.
|
||||||
@@ -559,6 +597,7 @@ class AppState extends ChangeNotifier {
|
|||||||
title: page.title,
|
title: page.title,
|
||||||
isJournal: page.journalDate != null,
|
isJournal: page.journalDate != null,
|
||||||
isHub: false,
|
isHub: false,
|
||||||
|
pageType: page.pageType,
|
||||||
),
|
),
|
||||||
);
|
);
|
||||||
if (recent.length > 12) recent.removeLast();
|
if (recent.length > 12) recent.removeLast();
|
||||||
@@ -572,7 +611,13 @@ class AppState extends ChangeNotifier {
|
|||||||
for (final p in pages) {
|
for (final p in pages) {
|
||||||
if (!p.isHub && !recent.any((r) => r.id == p.id)) {
|
if (!p.isHub && !recent.any((r) => r.id == p.id)) {
|
||||||
recent.add(
|
recent.add(
|
||||||
PageBrief(id: p.id, title: p.title, isJournal: false, isHub: p.isHub),
|
PageBrief(
|
||||||
|
id: p.id,
|
||||||
|
title: p.title,
|
||||||
|
isJournal: false,
|
||||||
|
isHub: p.isHub,
|
||||||
|
pageType: p.pageType,
|
||||||
|
),
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -591,6 +636,7 @@ class AppState extends ChangeNotifier {
|
|||||||
title: title,
|
title: title,
|
||||||
isJournal: recent[i].isJournal,
|
isJournal: recent[i].isJournal,
|
||||||
isHub: recent[i].isHub,
|
isHub: recent[i].isHub,
|
||||||
|
pageType: recent[i].pageType,
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
notifyListeners();
|
notifyListeners();
|
||||||
|
|||||||
@@ -16,6 +16,8 @@ import 'graph_view.dart';
|
|||||||
import 'settings_view.dart';
|
import 'settings_view.dart';
|
||||||
import 'tab_strip.dart';
|
import 'tab_strip.dart';
|
||||||
import 'tag_view.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,
|
/// App frame: sidebar (navigation, hubs, recents), top bar (history, search, theme,
|
||||||
/// settings) and the current view.
|
/// settings) and the current view.
|
||||||
@@ -132,6 +134,7 @@ class _ShellState extends State<Shell> {
|
|||||||
),
|
),
|
||||||
AllPagesRoute() => const AllPagesView(),
|
AllPagesRoute() => const AllPagesView(),
|
||||||
SettingsRoute() => const SettingsView(),
|
SettingsRoute() => const SettingsView(),
|
||||||
|
TagsTypesRoute() => const TagsTypesView(),
|
||||||
TagRoute() => TagView(name: route.name),
|
TagRoute() => TagView(name: route.name),
|
||||||
PageTarget() => PageScreen(target: route),
|
PageTarget() => PageScreen(target: route),
|
||||||
},
|
},
|
||||||
@@ -323,6 +326,13 @@ class _Sidebar extends StatelessWidget {
|
|||||||
onTap: () => go(const AllPagesRoute()),
|
onTap: () => go(const AllPagesRoute()),
|
||||||
onMiddle: () => newTab(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),
|
const SizedBox(height: 22),
|
||||||
Expanded(
|
Expanded(
|
||||||
child: ListView(
|
child: ListView(
|
||||||
@@ -342,6 +352,7 @@ class _Sidebar extends StatelessWidget {
|
|||||||
for (final p in app.recent)
|
for (final p in app.recent)
|
||||||
_NavItem(
|
_NavItem(
|
||||||
label: p.isJournal ? longDate(p.title) : p.title,
|
label: p.isJournal ? longDate(p.title) : p.title,
|
||||||
|
leading: TypeIcon(p.pageType),
|
||||||
selected: route is PageTarget && route.id == p.id,
|
selected: route is PageTarget && route.id == p.id,
|
||||||
dense: true,
|
dense: true,
|
||||||
onTap: () => go(PageTarget(id: p.id)),
|
onTap: () => go(PageTarget(id: p.id)),
|
||||||
@@ -360,6 +371,7 @@ class _Sidebar extends StatelessWidget {
|
|||||||
class _NavItem extends StatefulWidget {
|
class _NavItem extends StatefulWidget {
|
||||||
const _NavItem({
|
const _NavItem({
|
||||||
this.icon,
|
this.icon,
|
||||||
|
this.leading,
|
||||||
required this.label,
|
required this.label,
|
||||||
required this.selected,
|
required this.selected,
|
||||||
required this.onTap,
|
required this.onTap,
|
||||||
@@ -367,6 +379,9 @@ class _NavItem extends StatefulWidget {
|
|||||||
this.dense = false,
|
this.dense = false,
|
||||||
});
|
});
|
||||||
final IconData? icon;
|
final IconData? icon;
|
||||||
|
|
||||||
|
/// Shown before the label (a page's type emoji).
|
||||||
|
final Widget? leading;
|
||||||
final String label;
|
final String label;
|
||||||
final bool selected;
|
final bool selected;
|
||||||
final VoidCallback onTap;
|
final VoidCallback onTap;
|
||||||
@@ -417,6 +432,7 @@ class _NavItemState extends State<_NavItem> {
|
|||||||
),
|
),
|
||||||
const SizedBox(width: 10),
|
const SizedBox(width: 10),
|
||||||
],
|
],
|
||||||
|
?widget.leading,
|
||||||
Expanded(
|
Expanded(
|
||||||
child: Text(
|
child: Text(
|
||||||
widget.label,
|
widget.label,
|
||||||
|
|||||||
@@ -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,
|
||||||
|
],
|
||||||
|
),
|
||||||
|
);
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,327 @@
|
|||||||
|
import 'package:flutter/material.dart';
|
||||||
|
|
||||||
|
import '../theme/theme.dart';
|
||||||
|
|
||||||
|
/// Curated emoji, grouped (no emoji package: a short list covers the usual types, and any
|
||||||
|
/// other emoji can be pasted).
|
||||||
|
const emojiGroups = <(String, List<String>)>[
|
||||||
|
(
|
||||||
|
'People',
|
||||||
|
[
|
||||||
|
'🧑',
|
||||||
|
'👤',
|
||||||
|
'👥',
|
||||||
|
'👩',
|
||||||
|
'👨',
|
||||||
|
'🧒',
|
||||||
|
'👪',
|
||||||
|
'🧑💼',
|
||||||
|
'🧑🔬',
|
||||||
|
'🧑🎨',
|
||||||
|
'🧑🏫',
|
||||||
|
'🧑💻',
|
||||||
|
'🧑⚕️',
|
||||||
|
'🤝',
|
||||||
|
'💬',
|
||||||
|
'🫂',
|
||||||
|
],
|
||||||
|
),
|
||||||
|
(
|
||||||
|
'Places',
|
||||||
|
[
|
||||||
|
'📍',
|
||||||
|
'🏠',
|
||||||
|
'🏢',
|
||||||
|
'🏛️',
|
||||||
|
'🏙️',
|
||||||
|
'🏞️',
|
||||||
|
'🗺️',
|
||||||
|
'🌍',
|
||||||
|
'✈️',
|
||||||
|
'🏫',
|
||||||
|
'🏥',
|
||||||
|
'🏪',
|
||||||
|
'⛪',
|
||||||
|
'🏰',
|
||||||
|
'🏖️',
|
||||||
|
'⛰️',
|
||||||
|
],
|
||||||
|
),
|
||||||
|
(
|
||||||
|
'Things',
|
||||||
|
[
|
||||||
|
'📕',
|
||||||
|
'📚',
|
||||||
|
'📄',
|
||||||
|
'📝',
|
||||||
|
'📎',
|
||||||
|
'💻',
|
||||||
|
'📱',
|
||||||
|
'🖥️',
|
||||||
|
'⚙️',
|
||||||
|
'🔧',
|
||||||
|
'🧰',
|
||||||
|
'💡',
|
||||||
|
'🔑',
|
||||||
|
'📦',
|
||||||
|
'🎁',
|
||||||
|
'🗂️',
|
||||||
|
],
|
||||||
|
),
|
||||||
|
(
|
||||||
|
'Ideas',
|
||||||
|
[
|
||||||
|
'💭',
|
||||||
|
'🧠',
|
||||||
|
'💡',
|
||||||
|
'❓',
|
||||||
|
'❗',
|
||||||
|
'🎯',
|
||||||
|
'🧩',
|
||||||
|
'🔬',
|
||||||
|
'🧪',
|
||||||
|
'📐',
|
||||||
|
'📊',
|
||||||
|
'📈',
|
||||||
|
'🔍',
|
||||||
|
'✨',
|
||||||
|
'🌀',
|
||||||
|
'♾️',
|
||||||
|
],
|
||||||
|
),
|
||||||
|
(
|
||||||
|
'Nature',
|
||||||
|
[
|
||||||
|
'🌱',
|
||||||
|
'🌿',
|
||||||
|
'🌳',
|
||||||
|
'🌸',
|
||||||
|
'🍄',
|
||||||
|
'🌊',
|
||||||
|
'🔥',
|
||||||
|
'⭐',
|
||||||
|
'🌙',
|
||||||
|
'☀️',
|
||||||
|
'⚡',
|
||||||
|
'❄️',
|
||||||
|
'🐱',
|
||||||
|
'🐶',
|
||||||
|
'🐦',
|
||||||
|
'🦋',
|
||||||
|
],
|
||||||
|
),
|
||||||
|
(
|
||||||
|
'Food',
|
||||||
|
[
|
||||||
|
'🍳',
|
||||||
|
'🥗',
|
||||||
|
'🍝',
|
||||||
|
'🍕',
|
||||||
|
'🍰',
|
||||||
|
'🍎',
|
||||||
|
'🥖',
|
||||||
|
'🧀',
|
||||||
|
'☕',
|
||||||
|
'🍵',
|
||||||
|
'🍷',
|
||||||
|
'🍺',
|
||||||
|
'🥘',
|
||||||
|
'🌮',
|
||||||
|
'🍣',
|
||||||
|
'🥕',
|
||||||
|
],
|
||||||
|
),
|
||||||
|
(
|
||||||
|
'Activities',
|
||||||
|
[
|
||||||
|
'📅',
|
||||||
|
'🎉',
|
||||||
|
'🎵',
|
||||||
|
'🎬',
|
||||||
|
'🎮',
|
||||||
|
'🎨',
|
||||||
|
'📷',
|
||||||
|
'⚽',
|
||||||
|
'🏃',
|
||||||
|
'🧘',
|
||||||
|
'✍️',
|
||||||
|
'🎤',
|
||||||
|
'🎓',
|
||||||
|
'💼',
|
||||||
|
'🛠️',
|
||||||
|
'🧳',
|
||||||
|
],
|
||||||
|
),
|
||||||
|
(
|
||||||
|
'Symbols',
|
||||||
|
[
|
||||||
|
'❤️',
|
||||||
|
'⭐',
|
||||||
|
'✅',
|
||||||
|
'⚠️',
|
||||||
|
'🔖',
|
||||||
|
'🏷️',
|
||||||
|
'📌',
|
||||||
|
'🔗',
|
||||||
|
'💰',
|
||||||
|
'⏳',
|
||||||
|
'🔒',
|
||||||
|
'🚩',
|
||||||
|
'🔴',
|
||||||
|
'🟢',
|
||||||
|
'🔵',
|
||||||
|
'🟣',
|
||||||
|
],
|
||||||
|
),
|
||||||
|
];
|
||||||
|
|
||||||
|
/// True when [s] (trimmed) is one emoji: a single user-perceived character that is not plain
|
||||||
|
/// ASCII (so letters, digits and punctuation are refused).
|
||||||
|
bool isSingleEmoji(String s) {
|
||||||
|
final t = s.trim();
|
||||||
|
return t.isNotEmpty &&
|
||||||
|
t.characters.length == 1 &&
|
||||||
|
t.runes.any((r) => r > 0x7f) &&
|
||||||
|
!t.contains(RegExp(r'\s'));
|
||||||
|
}
|
||||||
|
|
||||||
|
/// What the picker returned: an emoji, or `null` to clear the icon.
|
||||||
|
class EmojiChoice {
|
||||||
|
const EmojiChoice(this.emoji);
|
||||||
|
final String? emoji;
|
||||||
|
}
|
||||||
|
|
||||||
|
/// Lets the user pick an emoji from [emojiGroups], paste any other one, or clear it.
|
||||||
|
/// Returns `null` when cancelled.
|
||||||
|
Future<EmojiChoice?> showEmojiPicker(
|
||||||
|
BuildContext context, {
|
||||||
|
required String title,
|
||||||
|
String? current,
|
||||||
|
}) => showDialog<EmojiChoice>(
|
||||||
|
context: context,
|
||||||
|
builder: (_) => _EmojiPicker(title: title, current: current),
|
||||||
|
);
|
||||||
|
|
||||||
|
class _EmojiPicker extends StatefulWidget {
|
||||||
|
const _EmojiPicker({required this.title, this.current});
|
||||||
|
final String title;
|
||||||
|
final String? current;
|
||||||
|
|
||||||
|
@override
|
||||||
|
State<_EmojiPicker> createState() => _EmojiPickerState();
|
||||||
|
}
|
||||||
|
|
||||||
|
class _EmojiPickerState extends State<_EmojiPicker> {
|
||||||
|
final _text = TextEditingController();
|
||||||
|
String? _error;
|
||||||
|
|
||||||
|
@override
|
||||||
|
void dispose() {
|
||||||
|
_text.dispose();
|
||||||
|
super.dispose();
|
||||||
|
}
|
||||||
|
|
||||||
|
void _usePasted() {
|
||||||
|
final t = _text.text.trim();
|
||||||
|
if (t.isEmpty) return;
|
||||||
|
if (!isSingleEmoji(t)) {
|
||||||
|
setState(() => _error = 'Enter a single emoji');
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
Navigator.pop(context, EmojiChoice(t));
|
||||||
|
}
|
||||||
|
|
||||||
|
@override
|
||||||
|
Widget build(BuildContext context) {
|
||||||
|
final colors = context.colors;
|
||||||
|
return AlertDialog(
|
||||||
|
title: Text(widget.title),
|
||||||
|
content: SizedBox(
|
||||||
|
width: 420,
|
||||||
|
child: Column(
|
||||||
|
mainAxisSize: MainAxisSize.min,
|
||||||
|
crossAxisAlignment: CrossAxisAlignment.start,
|
||||||
|
children: [
|
||||||
|
TextField(
|
||||||
|
key: const ValueKey('emoji-input'),
|
||||||
|
controller: _text,
|
||||||
|
decoration: InputDecoration(
|
||||||
|
hintText: 'Paste any emoji',
|
||||||
|
errorText: _error,
|
||||||
|
suffixIcon: IconButton(
|
||||||
|
key: const ValueKey('emoji-use'),
|
||||||
|
tooltip: 'Use this emoji',
|
||||||
|
icon: const Icon(Icons.check_rounded),
|
||||||
|
onPressed: _usePasted,
|
||||||
|
),
|
||||||
|
),
|
||||||
|
onChanged: (_) {
|
||||||
|
if (_error != null) setState(() => _error = null);
|
||||||
|
},
|
||||||
|
onSubmitted: (_) => _usePasted(),
|
||||||
|
),
|
||||||
|
const SizedBox(height: 12),
|
||||||
|
Flexible(
|
||||||
|
child: SingleChildScrollView(
|
||||||
|
child: Column(
|
||||||
|
crossAxisAlignment: CrossAxisAlignment.start,
|
||||||
|
children: [
|
||||||
|
for (final (group, list) in emojiGroups) ...[
|
||||||
|
Padding(
|
||||||
|
padding: const EdgeInsets.only(top: 8, bottom: 4),
|
||||||
|
child: Text(
|
||||||
|
group.toUpperCase(),
|
||||||
|
style: Theme.of(context).textTheme.labelSmall,
|
||||||
|
),
|
||||||
|
),
|
||||||
|
Wrap(
|
||||||
|
spacing: 2,
|
||||||
|
runSpacing: 2,
|
||||||
|
children: [
|
||||||
|
for (final e in list)
|
||||||
|
InkWell(
|
||||||
|
key: ValueKey('emoji-$group-$e'),
|
||||||
|
borderRadius: BorderRadius.circular(6),
|
||||||
|
onTap: () =>
|
||||||
|
Navigator.pop(context, EmojiChoice(e)),
|
||||||
|
child: Container(
|
||||||
|
width: 38,
|
||||||
|
height: 38,
|
||||||
|
alignment: Alignment.center,
|
||||||
|
decoration: BoxDecoration(
|
||||||
|
color: e == widget.current
|
||||||
|
? colors.accentSoft
|
||||||
|
: null,
|
||||||
|
borderRadius: BorderRadius.circular(6),
|
||||||
|
),
|
||||||
|
child: Text(
|
||||||
|
e,
|
||||||
|
style: const TextStyle(fontSize: 20),
|
||||||
|
),
|
||||||
|
),
|
||||||
|
),
|
||||||
|
],
|
||||||
|
),
|
||||||
|
],
|
||||||
|
],
|
||||||
|
),
|
||||||
|
),
|
||||||
|
),
|
||||||
|
],
|
||||||
|
),
|
||||||
|
),
|
||||||
|
actions: [
|
||||||
|
if (widget.current != null)
|
||||||
|
TextButton(
|
||||||
|
key: const ValueKey('emoji-clear'),
|
||||||
|
onPressed: () => Navigator.pop(context, const EmojiChoice(null)),
|
||||||
|
child: const Text('Remove emoji'),
|
||||||
|
),
|
||||||
|
TextButton(
|
||||||
|
onPressed: () => Navigator.pop(context),
|
||||||
|
child: const Text('Cancel'),
|
||||||
|
),
|
||||||
|
],
|
||||||
|
);
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -161,6 +161,7 @@ Future<T?> showNameDialog<T>(
|
|||||||
required String confirm,
|
required String confirm,
|
||||||
required Future<T> Function(String name) submit,
|
required Future<T> Function(String name) submit,
|
||||||
String hint = 'Title',
|
String hint = 'Title',
|
||||||
|
String initial = '',
|
||||||
}) => showDialog<T>(
|
}) => showDialog<T>(
|
||||||
context: context,
|
context: context,
|
||||||
builder: (_) => _NameDialog<T>(
|
builder: (_) => _NameDialog<T>(
|
||||||
@@ -168,6 +169,7 @@ Future<T?> showNameDialog<T>(
|
|||||||
confirm: confirm,
|
confirm: confirm,
|
||||||
submit: submit,
|
submit: submit,
|
||||||
hint: hint,
|
hint: hint,
|
||||||
|
initial: initial,
|
||||||
),
|
),
|
||||||
);
|
);
|
||||||
|
|
||||||
@@ -177,8 +179,10 @@ class _NameDialog<T> extends StatefulWidget {
|
|||||||
required this.confirm,
|
required this.confirm,
|
||||||
required this.submit,
|
required this.submit,
|
||||||
required this.hint,
|
required this.hint,
|
||||||
|
this.initial = '',
|
||||||
});
|
});
|
||||||
final String heading;
|
final String heading;
|
||||||
|
final String initial;
|
||||||
final String confirm;
|
final String confirm;
|
||||||
final String hint;
|
final String hint;
|
||||||
final Future<T> Function(String) submit;
|
final Future<T> Function(String) submit;
|
||||||
@@ -188,7 +192,7 @@ class _NameDialog<T> extends StatefulWidget {
|
|||||||
}
|
}
|
||||||
|
|
||||||
class _NameDialogState<T> extends State<_NameDialog<T>> {
|
class _NameDialogState<T> extends State<_NameDialog<T>> {
|
||||||
final _text = TextEditingController();
|
late final _text = TextEditingController(text: widget.initial);
|
||||||
String? _error;
|
String? _error;
|
||||||
bool _busy = false;
|
bool _busy = false;
|
||||||
|
|
||||||
|
|||||||
@@ -0,0 +1,34 @@
|
|||||||
|
import 'package:flutter/material.dart';
|
||||||
|
|
||||||
|
import '../state/app_state.dart';
|
||||||
|
|
||||||
|
/// The emoji of a page's type, drawn just left of the page's name (titles, lists, tabs, the
|
||||||
|
/// tree view; never in the network graph). Nothing when the type has no emoji. Icons come
|
||||||
|
/// from [AppState.typeIcons], so lists only need the page's type.
|
||||||
|
class TypeIcon extends StatelessWidget {
|
||||||
|
const TypeIcon(this.pageType, {super.key, this.size = 13, this.gap = 5});
|
||||||
|
|
||||||
|
final String? pageType;
|
||||||
|
final double size;
|
||||||
|
|
||||||
|
/// Space between the emoji and the name.
|
||||||
|
final double gap;
|
||||||
|
|
||||||
|
@override
|
||||||
|
Widget build(BuildContext context) {
|
||||||
|
final icon = AppScope.of(context).typeIcon(pageType);
|
||||||
|
if (icon == null) return const SizedBox.shrink();
|
||||||
|
return Padding(
|
||||||
|
padding: EdgeInsets.only(right: gap),
|
||||||
|
child: Text(
|
||||||
|
icon,
|
||||||
|
key: const ValueKey('type-icon'),
|
||||||
|
style: TextStyle(fontSize: size, height: 1.15),
|
||||||
|
),
|
||||||
|
);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/// [title] prefixed with [icon] (for places that only take a string: canvas labels).
|
||||||
|
String withTypeIcon(String? icon, String title) =>
|
||||||
|
icon == null ? title : '$icon $title';
|
||||||
Reference in new issue
Block a user