mirror of
https://github.com/Xevion/paperless-mobile.git
synced 2025-12-08 04:07:51 -06:00
feat: Add tests, update notes implementation
This commit is contained in:
@@ -311,4 +311,17 @@ class DocumentDetailsCubit extends Cubit<DocumentDetailsState> {
|
||||
_notifier.removeListener(this);
|
||||
await super.close();
|
||||
}
|
||||
|
||||
Future<void> addNote(String text) async {
|
||||
assert(state.status == LoadingStatus.loaded);
|
||||
try {
|
||||
final updatedDocument = await _api.addNote(
|
||||
document: state.document!,
|
||||
text: text,
|
||||
);
|
||||
_notifier.notifyUpdated(updatedDocument);
|
||||
} on PaperlessApiException catch (err) {
|
||||
addError(TransientPaperlessApiError(code: err.code));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,37 +0,0 @@
|
||||
import 'package:flutter/material.dart';
|
||||
import 'package:flutter/widgets.dart';
|
||||
import 'package:paperless_api/paperless_api.dart';
|
||||
import 'package:paperless_mobile/generated/l10n/app_localizations.dart';
|
||||
|
||||
class AddNotePage extends StatefulWidget {
|
||||
final DocumentModel document;
|
||||
|
||||
const AddNotePage({super.key, required this.document});
|
||||
|
||||
@override
|
||||
State<AddNotePage> createState() => _AddNotePageState();
|
||||
}
|
||||
|
||||
class _AddNotePageState extends State<AddNotePage> {
|
||||
@override
|
||||
Widget build(BuildContext context) {
|
||||
return Scaffold(
|
||||
appBar: AppBar(
|
||||
title: Text(S.of(context)!.addNote),
|
||||
),
|
||||
body: Column(
|
||||
children: [
|
||||
TextField(
|
||||
decoration: InputDecoration(
|
||||
labelText: S.of(context)!.content,
|
||||
),
|
||||
),
|
||||
ElevatedButton(
|
||||
onPressed: () {},
|
||||
child: Text(S.of(context)!.save),
|
||||
),
|
||||
],
|
||||
),
|
||||
);
|
||||
}
|
||||
}
|
||||
@@ -8,18 +8,65 @@ import 'package:paperless_mobile/features/document_details/cubit/document_detail
|
||||
import 'package:paperless_mobile/generated/l10n/app_localizations.dart';
|
||||
import 'package:paperless_mobile/helpers/message_helpers.dart';
|
||||
|
||||
class DocumentNotesWidget extends StatelessWidget {
|
||||
class DocumentNotesWidget extends StatefulWidget {
|
||||
final DocumentModel document;
|
||||
const DocumentNotesWidget({super.key, required this.document});
|
||||
|
||||
@override
|
||||
State<DocumentNotesWidget> createState() => _DocumentNotesWidgetState();
|
||||
}
|
||||
|
||||
class _DocumentNotesWidgetState extends State<DocumentNotesWidget> {
|
||||
final _noteContentController = TextEditingController();
|
||||
final _formKey = GlobalKey<FormState>();
|
||||
|
||||
@override
|
||||
Widget build(BuildContext context) {
|
||||
return SliverMainAxisGroup(
|
||||
slivers: [
|
||||
SliverToBoxAdapter(
|
||||
child: Form(
|
||||
key: _formKey,
|
||||
child: Column(
|
||||
children: [
|
||||
TextFormField(
|
||||
controller: _noteContentController,
|
||||
maxLines: null,
|
||||
validator: (value) {
|
||||
if (value?.isEmpty ?? true) {
|
||||
return S.of(context)!.thisFieldIsRequired;
|
||||
}
|
||||
return null;
|
||||
},
|
||||
decoration: InputDecoration(
|
||||
hintText: 'Your note here...',
|
||||
labelText: 'New note',
|
||||
floatingLabelBehavior: FloatingLabelBehavior.always,
|
||||
),
|
||||
).padded(),
|
||||
Align(
|
||||
alignment: Alignment.centerRight,
|
||||
child: FilledButton.icon(
|
||||
icon: Icon(Icons.note_add_outlined),
|
||||
label: Text("Add note"),
|
||||
onPressed: () {
|
||||
_formKey.currentState?.save();
|
||||
if (_formKey.currentState?.validate() ?? false) {
|
||||
context
|
||||
.read<DocumentDetailsCubit>()
|
||||
.addNote(_noteContentController.text);
|
||||
}
|
||||
},
|
||||
).padded(),
|
||||
),
|
||||
],
|
||||
).padded(),
|
||||
),
|
||||
),
|
||||
SliverList.separated(
|
||||
separatorBuilder: (context, index) => const SizedBox(height: 16),
|
||||
itemBuilder: (context, index) {
|
||||
final note = document.notes.elementAt(index);
|
||||
final note = widget.document.notes.elementAt(index);
|
||||
return Card(
|
||||
// borderRadius: BorderRadius.circular(8),
|
||||
// elevation: 1,
|
||||
@@ -51,13 +98,6 @@ class DocumentNotesWidget extends StatelessWidget {
|
||||
Row(
|
||||
mainAxisAlignment: MainAxisAlignment.end,
|
||||
children: [
|
||||
Spacer(),
|
||||
IconButton(
|
||||
icon: Icon(Icons.edit),
|
||||
onPressed: () {
|
||||
// Push edit page
|
||||
},
|
||||
),
|
||||
IconButton(
|
||||
icon: Icon(Icons.delete),
|
||||
onPressed: () {
|
||||
@@ -74,7 +114,7 @@ class DocumentNotesWidget extends StatelessWidget {
|
||||
).padded(16),
|
||||
);
|
||||
},
|
||||
itemCount: document.notes.length,
|
||||
itemCount: widget.document.notes.length,
|
||||
),
|
||||
],
|
||||
);
|
||||
|
||||
@@ -1,15 +0,0 @@
|
||||
import 'package:flutter/material.dart';
|
||||
|
||||
class EditNotePage extends StatefulWidget {
|
||||
const EditNotePage({super.key});
|
||||
|
||||
@override
|
||||
State<EditNotePage> createState() => _EditNotePageState();
|
||||
}
|
||||
|
||||
class _EditNotePageState extends State<EditNotePage> {
|
||||
@override
|
||||
Widget build(BuildContext context) {
|
||||
return const Placeholder();
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user