You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
94 lines
2.0 KiB
94 lines
2.0 KiB
2 years ago
|
part of '../neon_notes.dart';
|
||
2 years ago
|
|
||
|
abstract class NotesBlocEvents {
|
||
2 years ago
|
void createNote({
|
||
2 years ago
|
final String title = '',
|
||
|
final String category = '',
|
||
2 years ago
|
});
|
||
|
|
||
|
void updateNote(
|
||
|
final int id,
|
||
|
final String etag, {
|
||
|
final String? title,
|
||
|
final String? category,
|
||
|
final String? content,
|
||
|
final bool? favorite,
|
||
|
});
|
||
|
|
||
|
void deleteNote(final int id);
|
||
2 years ago
|
}
|
||
|
|
||
|
abstract class NotesBlocStates {
|
||
2 years ago
|
BehaviorSubject<Result<List<NextcloudNotesNote>>> get notes;
|
||
2 years ago
|
}
|
||
|
|
||
2 years ago
|
class NotesBloc extends InteractiveBloc implements NotesBlocEvents, NotesBlocStates {
|
||
2 years ago
|
NotesBloc(
|
||
|
this.options,
|
||
|
this.requestManager,
|
||
|
this.client,
|
||
|
) {
|
||
2 years ago
|
unawaited(refresh());
|
||
2 years ago
|
}
|
||
|
|
||
|
final NotesAppSpecificOptions options;
|
||
|
final RequestManager requestManager;
|
||
|
final NextcloudClient client;
|
||
|
|
||
|
@override
|
||
|
void dispose() {
|
||
2 years ago
|
unawaited(notes.close());
|
||
2 years ago
|
super.dispose();
|
||
|
}
|
||
|
|
||
|
@override
|
||
2 years ago
|
BehaviorSubject<Result<List<NextcloudNotesNote>>> notes = BehaviorSubject<Result<List<NextcloudNotesNote>>>();
|
||
2 years ago
|
|
||
|
@override
|
||
|
Future refresh() async {
|
||
2 years ago
|
await requestManager.wrapNextcloud<List<NextcloudNotesNote>, List<NextcloudNotesNote>>(
|
||
2 years ago
|
client.id,
|
||
|
'notes-notes',
|
||
|
notes,
|
||
|
() async => client.notes.getNotes(),
|
||
|
(final response) => response,
|
||
|
);
|
||
|
}
|
||
2 years ago
|
|
||
|
@override
|
||
2 years ago
|
void createNote({final String title = '', final String category = ''}) {
|
||
|
wrapAction(
|
||
|
() async => client.notes.createNote(
|
||
|
title: title,
|
||
|
category: category,
|
||
|
),
|
||
|
);
|
||
|
}
|
||
|
|
||
|
@override
|
||
|
void deleteNote(final int id) {
|
||
|
wrapAction(() async => client.notes.deleteNote(id: id));
|
||
|
}
|
||
|
|
||
|
@override
|
||
|
void updateNote(
|
||
|
final int id,
|
||
|
final String etag, {
|
||
|
final String? title,
|
||
|
final String? category,
|
||
|
final String? content,
|
||
|
final bool? favorite,
|
||
|
}) {
|
||
|
wrapAction(
|
||
|
() async => client.notes.updateNote(
|
||
|
id: id,
|
||
|
title: title,
|
||
|
category: category,
|
||
|
content: content,
|
||
|
favorite: favorite ?? false ? 1 : 0,
|
||
|
ifMatch: '"$etag"',
|
||
|
),
|
||
|
);
|
||
|
}
|
||
2 years ago
|
}
|