This repository has been archived on 2026-06-02. You can view files and clone it. You cannot open issues or pull requests or push a commit.
Files
FabledApp/lib/screens/notes/note_detail_screen.dart
T
bvandeusen 3c5f932327 Render and navigate [[wikilink]] syntax in notes
- Add WikilinkSyntax (InlineSyntax) that parses [[Note Title]] into
  anchor elements with a wikilink:// href
- wikilinkExtensionSet extends GFM with this syntax; shared by detail
  view and edit preview so rendering is consistent
- NoteDetailScreen handles onTapLink: wikilink:// hrefs look up the
  target note by title (case-insensitive) and push its detail route;
  unresolved links show a "Note not found" snackbar
- Add markdown as an explicit dependency (was previously transitive)

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
2026-03-01 12:55:06 -05:00

103 lines
3.5 KiB
Dart

import 'package:flutter/material.dart';
import 'package:flutter_markdown/flutter_markdown.dart';
import 'package:flutter_riverpod/flutter_riverpod.dart';
import 'package:go_router/go_router.dart';
import '../../core/constants.dart';
import '../../core/wikilink_syntax.dart';
import '../../providers/notes_provider.dart';
class NoteDetailScreen extends ConsumerWidget {
final int noteId;
// Provided when embedded in master-detail: called instead of context.pop().
final VoidCallback? onDeleted;
const NoteDetailScreen({super.key, required this.noteId, this.onDeleted});
@override
Widget build(BuildContext context, WidgetRef ref) {
final noteAsync = ref.watch(noteDetailProvider(noteId));
final allNotes = ref.watch(notesProvider).valueOrNull ?? [];
void navigateByTitle(String title) {
final matches = allNotes.where(
(n) => n.title.toLowerCase() == title.toLowerCase(),
);
if (matches.isNotEmpty) {
context.push(
Routes.noteDetail.replaceFirst(':id', '${matches.first.id}'),
);
} else {
ScaffoldMessenger.of(context).showSnackBar(
SnackBar(content: Text('Note not found: "$title"')),
);
}
}
return Scaffold(
appBar: AppBar(
title: noteAsync.maybeWhen(
data: (n) => Text(n.title),
orElse: () => const Text('Note'),
),
actions: [
noteAsync.maybeWhen(
data: (note) => Row(
children: [
IconButton(
icon: const Icon(Icons.edit),
onPressed: () => context.push(
Routes.noteEdit.replaceFirst(':id', '$noteId'),
),
),
IconButton(
icon: const Icon(Icons.delete),
onPressed: () async {
final confirm = await showDialog<bool>(
context: context,
builder: (_) => AlertDialog(
title: const Text('Delete note?'),
actions: [
TextButton(
onPressed: () => Navigator.pop(context, false),
child: const Text('Cancel'),
),
TextButton(
onPressed: () => Navigator.pop(context, true),
child: const Text('Delete'),
),
],
),
);
if (confirm == true) {
await ref.read(notesProvider.notifier).delete(noteId);
if (context.mounted) {
onDeleted != null ? onDeleted!() : context.pop();
}
}
},
),
],
),
orElse: () => const SizedBox.shrink(),
),
],
),
body: noteAsync.when(
loading: () => const Center(child: CircularProgressIndicator()),
error: (e, _) => Center(child: Text('Error: $e')),
data: (note) => Markdown(
data: note.body,
selectable: true,
extensionSet: wikilinkExtensionSet,
onTapLink: (text, href, _) {
if (href == null) return;
if (href.startsWith('wikilink://')) {
navigateByTitle(Uri.decodeComponent(href.substring(11)));
}
},
),
),
);
}
}