From a50193dbc0b5afc22eb8e2599ccbea34f3fa4774 Mon Sep 17 00:00:00 2001 From: bvandeusen Date: Sat, 4 Apr 2026 23:52:10 -0400 Subject: [PATCH] feat(knowledge): update Project model, ProjectsApi sort, and NoteEditScreen noteType support --- lib/data/api/projects_api.dart | 8 +++++- lib/data/models/project.dart | 4 +++ .../repositories/projects_repository.dart | 7 +++++- lib/screens/notes/note_edit_screen.dart | 25 +++++++++++++++++-- 4 files changed, 40 insertions(+), 4 deletions(-) diff --git a/lib/data/api/projects_api.dart b/lib/data/api/projects_api.dart index c28dbd4..41edf8a 100644 --- a/lib/data/api/projects_api.dart +++ b/lib/data/api/projects_api.dart @@ -11,7 +11,11 @@ class ProjectsApi { try { final response = await _dio.get( '/api/projects', - queryParameters: status != null ? {'status': status} : null, + queryParameters: { + 'sort': 'updated_at', + 'order': 'desc', + if (status != null) 'status': status, + }, ); final data = response.data as Map; final list = data['projects'] as List; @@ -37,10 +41,12 @@ class ProjectsApi { String? description, String? goal, String? color, + String status = 'active', }) async { try { final response = await _dio.post('/api/projects', data: { 'title': title, + 'status': status, if (description != null && description.isNotEmpty) 'description': description, if (goal != null && goal.isNotEmpty) 'goal': goal, diff --git a/lib/data/models/project.dart b/lib/data/models/project.dart index e66f002..5408c29 100644 --- a/lib/data/models/project.dart +++ b/lib/data/models/project.dart @@ -5,6 +5,7 @@ class Project { final String? goal; final String status; // active | completed | archived final String? color; + final String? autoSummary; final DateTime createdAt; final DateTime updatedAt; @@ -15,6 +16,7 @@ class Project { this.goal, required this.status, this.color, + this.autoSummary, required this.createdAt, required this.updatedAt, }); @@ -26,6 +28,7 @@ class Project { goal: json['goal'] as String?, status: json['status'] as String? ?? 'active', color: json['color'] as String?, + autoSummary: json['auto_summary'] as String?, createdAt: DateTime.parse(json['created_at'] as String), updatedAt: DateTime.parse(json['updated_at'] as String), ); @@ -36,5 +39,6 @@ class Project { 'goal': goal, 'status': status, 'color': color, + 'auto_summary': autoSummary, }; } diff --git a/lib/data/repositories/projects_repository.dart b/lib/data/repositories/projects_repository.dart index a9a0cdd..24f52c2 100644 --- a/lib/data/repositories/projects_repository.dart +++ b/lib/data/repositories/projects_repository.dart @@ -12,9 +12,14 @@ class ProjectsRepository { String? description, String? goal, String? color, + String status = 'active', }) => _api.create( - title: title, description: description, goal: goal, color: color); + title: title, + description: description, + goal: goal, + color: color, + status: status); Future update(int id, Map fields) => _api.update(id, fields); Future delete(int id) => _api.delete(id); diff --git a/lib/screens/notes/note_edit_screen.dart b/lib/screens/notes/note_edit_screen.dart index 0e9eefc..e02477d 100644 --- a/lib/screens/notes/note_edit_screen.dart +++ b/lib/screens/notes/note_edit_screen.dart @@ -11,7 +11,8 @@ import '../../widgets/project_selector.dart'; class NoteEditScreen extends ConsumerStatefulWidget { final int? noteId; - const NoteEditScreen({super.key, this.noteId}); + final String? noteType; // passed when creating a typed note from KnowledgeScreen + const NoteEditScreen({super.key, this.noteId, this.noteType}); @override ConsumerState createState() => _NoteEditScreenState(); @@ -25,12 +26,14 @@ class _NoteEditScreenState extends ConsumerState { int? _projectId; bool _preview = false; bool _saving = false; + late String _noteType; late final Future _initFuture; @override void initState() { super.initState(); + _noteType = widget.noteType ?? 'note'; _initFuture = widget.noteId != null ? _loadExisting() : Future.value(); } @@ -50,6 +53,7 @@ class _NoteEditScreenState extends ConsumerState { _contentController.text = note.body; _tags = List.from(note.tags); _projectId = note.projectId; + _noteType = note.noteType; } void _addTag(String raw) { @@ -108,6 +112,7 @@ class _NoteEditScreenState extends ConsumerState { body, tags: _tags, projectId: _projectId, + noteType: _noteType, ); if (mounted) context.pop(); } else { @@ -118,6 +123,7 @@ class _NoteEditScreenState extends ConsumerState { tags: _tags, projectId: _projectId, clearProject: _projectId == null, + noteType: _noteType, ); if (mounted) context.pop(); } @@ -138,7 +144,22 @@ class _NoteEditScreenState extends ConsumerState { builder: (context, snapshot) { return Scaffold( appBar: AppBar( - title: Text(widget.noteId == null ? 'New Note' : 'Edit Note'), + title: Column( + crossAxisAlignment: CrossAxisAlignment.start, + children: [ + Text(widget.noteId == null ? 'New Note' : 'Edit Note'), + if (_noteType != 'note') + Chip( + label: Text( + _noteType, + style: const TextStyle(fontSize: 11), + ), + padding: EdgeInsets.zero, + visualDensity: VisualDensity.compact, + materialTapTargetSize: MaterialTapTargetSize.shrinkWrap, + ), + ], + ), actions: [ if (widget.noteId != null) IconButton(