mirror of
https://github.com/Xevion/paperless-mobile.git
synced 2025-12-09 10:08:00 -06:00
Migrated to flutter master channel, some adaptations to new m3 specs
This commit is contained in:
@@ -1,5 +1,4 @@
|
||||
import 'package:paperless_api/paperless_api.dart';
|
||||
import 'package:paperless_api/src/models/saved_view_model.dart';
|
||||
import 'package:paperless_mobile/core/repository/saved_view_repository.dart';
|
||||
import 'package:rxdart/rxdart.dart';
|
||||
|
||||
@@ -8,20 +7,21 @@ class SavedViewRepositoryImpl implements SavedViewRepository {
|
||||
|
||||
SavedViewRepositoryImpl(this._api);
|
||||
|
||||
final BehaviorSubject<Map<int, SavedView>> _subject =
|
||||
BehaviorSubject.seeded({});
|
||||
final BehaviorSubject<Map<int, SavedView>?> _subject = BehaviorSubject();
|
||||
|
||||
@override
|
||||
Stream<Map<int, SavedView>> get savedViews =>
|
||||
Stream<Map<int, SavedView>?> get savedViews =>
|
||||
_subject.stream.asBroadcastStream();
|
||||
|
||||
@override
|
||||
void clear() {}
|
||||
void clear() {
|
||||
_subject.add(const {});
|
||||
}
|
||||
|
||||
@override
|
||||
Future<SavedView> create(SavedView view) async {
|
||||
final created = await _api.save(view);
|
||||
final updatedState = {..._subject.value}
|
||||
final updatedState = {..._subject.valueOrNull ?? {}}
|
||||
..putIfAbsent(created.id!, () => created);
|
||||
_subject.add(updatedState);
|
||||
return created;
|
||||
@@ -30,7 +30,7 @@ class SavedViewRepositoryImpl implements SavedViewRepository {
|
||||
@override
|
||||
Future<int> delete(SavedView view) async {
|
||||
await _api.delete(view);
|
||||
final updatedState = {..._subject.value}..remove(view.id);
|
||||
final updatedState = {..._subject.valueOrNull ?? {}}..remove(view.id);
|
||||
_subject.add(updatedState);
|
||||
return view.id!;
|
||||
}
|
||||
@@ -38,7 +38,7 @@ class SavedViewRepositoryImpl implements SavedViewRepository {
|
||||
@override
|
||||
Future<SavedView?> find(int id) async {
|
||||
final found = await _api.find(id);
|
||||
final updatedState = {..._subject.value}
|
||||
final updatedState = {..._subject.valueOrNull ?? {}}
|
||||
..update(id, (_) => found, ifAbsent: () => found);
|
||||
_subject.add(updatedState);
|
||||
return found;
|
||||
@@ -48,7 +48,7 @@ class SavedViewRepositoryImpl implements SavedViewRepository {
|
||||
Future<Iterable<SavedView>> findAll([Iterable<int>? ids]) async {
|
||||
final found = await _api.findAll(ids);
|
||||
final updatedState = {
|
||||
..._subject.value,
|
||||
..._subject.valueOrNull ?? {},
|
||||
...{for (final view in found) view.id!: view},
|
||||
};
|
||||
_subject.add(updatedState);
|
||||
|
||||
@@ -1,4 +1,3 @@
|
||||
import 'package:flutter/src/widgets/container.dart';
|
||||
import 'package:flutter/src/widgets/framework.dart';
|
||||
import 'package:flutter_bloc/flutter_bloc.dart';
|
||||
import 'package:paperless_api/paperless_api.dart';
|
||||
|
||||
@@ -1,7 +1,7 @@
|
||||
import 'package:paperless_api/paperless_api.dart';
|
||||
|
||||
abstract class SavedViewRepository {
|
||||
Stream<Map<int, SavedView>> get savedViews;
|
||||
Stream<Map<int, SavedView>?> get savedViews;
|
||||
|
||||
Future<SavedView> create(SavedView view);
|
||||
Future<SavedView?> find(int id);
|
||||
|
||||
Reference in New Issue
Block a user