A framework for building convergent cross-platform Nextcloud clients using Flutter.
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.

92 lines
1.9 KiB

part of '../neon_notes.dart';
2 years ago
abstract class NotesBlocEvents {
void createNote({
final String title = '',
final String category = '',
});
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 {
BehaviorSubject<Result<List<NotesNote>>> get notes;
2 years ago
}
class NotesBloc extends InteractiveBloc implements NotesBlocEvents, NotesBlocStates {
2 years ago
NotesBloc(
this.options,
this.account,
2 years ago
) {
unawaited(refresh());
2 years ago
}
final NotesAppSpecificOptions options;
final Account account;
2 years ago
@override
void dispose() {
unawaited(notes.close());
2 years ago
super.dispose();
}
@override
BehaviorSubject<Result<List<NotesNote>>> notes = BehaviorSubject<Result<List<NotesNote>>>();
@override
Future<void> refresh() async {
await RequestManager.instance.wrapNextcloud<List<NotesNote>, BuiltList<NotesNote>>(
account.id,
'notes-notes',
notes,
() async => account.client.notes.getNotes(),
List<NotesNote>.from,
);
}
2 years ago
@override
void createNote({final String title = '', final String category = ''}) {
wrapAction(
() async => account.client.notes.createNote(
title: title,
category: category,
),
);
}
@override
void deleteNote(final int id) {
wrapAction(() async => account.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 => account.client.notes.updateNote(
id: id,
title: title,
category: category,
content: content,
favorite: favorite ?? false ? 1 : 0,
ifMatch: '"$etag"',
),
);
}
2 years ago
}