feat(knowledge): update Project model, ProjectsApi sort, and NoteEditScreen noteType support
This commit is contained in:
@@ -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<String, dynamic>;
|
||||
final list = data['projects'] as List<dynamic>;
|
||||
@@ -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,
|
||||
|
||||
@@ -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,
|
||||
};
|
||||
}
|
||||
|
||||
@@ -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<Project> update(int id, Map<String, dynamic> fields) =>
|
||||
_api.update(id, fields);
|
||||
Future<void> delete(int id) => _api.delete(id);
|
||||
|
||||
@@ -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<NoteEditScreen> createState() => _NoteEditScreenState();
|
||||
@@ -25,12 +26,14 @@ class _NoteEditScreenState extends ConsumerState<NoteEditScreen> {
|
||||
int? _projectId;
|
||||
bool _preview = false;
|
||||
bool _saving = false;
|
||||
late String _noteType;
|
||||
|
||||
late final Future<void> _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<NoteEditScreen> {
|
||||
_contentController.text = note.body;
|
||||
_tags = List<String>.from(note.tags);
|
||||
_projectId = note.projectId;
|
||||
_noteType = note.noteType;
|
||||
}
|
||||
|
||||
void _addTag(String raw) {
|
||||
@@ -108,6 +112,7 @@ class _NoteEditScreenState extends ConsumerState<NoteEditScreen> {
|
||||
body,
|
||||
tags: _tags,
|
||||
projectId: _projectId,
|
||||
noteType: _noteType,
|
||||
);
|
||||
if (mounted) context.pop();
|
||||
} else {
|
||||
@@ -118,6 +123,7 @@ class _NoteEditScreenState extends ConsumerState<NoteEditScreen> {
|
||||
tags: _tags,
|
||||
projectId: _projectId,
|
||||
clearProject: _projectId == null,
|
||||
noteType: _noteType,
|
||||
);
|
||||
if (mounted) context.pop();
|
||||
}
|
||||
@@ -138,7 +144,22 @@ class _NoteEditScreenState extends ConsumerState<NoteEditScreen> {
|
||||
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(
|
||||
|
||||
Reference in New Issue
Block a user