mirror of
https://github.com/Xevion/paperless-mobile.git
synced 2025-12-15 00:12:22 -06:00
Implemented inbox (still WIP)
This commit is contained in:
27
lib/features/labels/bloc/label_bloc_provider.dart
Normal file
27
lib/features/labels/bloc/label_bloc_provider.dart
Normal file
@@ -0,0 +1,27 @@
|
||||
import 'package:flutter/widgets.dart';
|
||||
import 'package:flutter_bloc/flutter_bloc.dart';
|
||||
import 'package:paperless_mobile/di_initializer.dart';
|
||||
import 'package:paperless_mobile/features/documents/bloc/saved_view_cubit.dart';
|
||||
import 'package:paperless_mobile/features/labels/correspondent/bloc/correspondents_cubit.dart';
|
||||
import 'package:paperless_mobile/features/labels/document_type/bloc/document_type_cubit.dart';
|
||||
import 'package:paperless_mobile/features/labels/storage_path/bloc/storage_path_cubit.dart';
|
||||
import 'package:paperless_mobile/features/labels/tags/bloc/tags_cubit.dart';
|
||||
|
||||
class LabelBlocProvider extends StatelessWidget {
|
||||
final Widget child;
|
||||
const LabelBlocProvider({super.key, required this.child});
|
||||
|
||||
@override
|
||||
Widget build(BuildContext context) {
|
||||
return MultiBlocProvider(
|
||||
providers: [
|
||||
BlocProvider.value(value: getIt<DocumentTypeCubit>()),
|
||||
BlocProvider.value(value: getIt<CorrespondentCubit>()),
|
||||
BlocProvider.value(value: getIt<TagCubit>()),
|
||||
BlocProvider.value(value: getIt<StoragePathCubit>()),
|
||||
BlocProvider.value(value: getIt<SavedViewCubit>()),
|
||||
],
|
||||
child: child,
|
||||
);
|
||||
}
|
||||
}
|
||||
75
lib/features/labels/bloc/label_cubit.dart
Normal file
75
lib/features/labels/bloc/label_cubit.dart
Normal file
@@ -0,0 +1,75 @@
|
||||
import 'package:flutter/foundation.dart';
|
||||
import 'package:flutter_bloc/flutter_bloc.dart';
|
||||
import 'package:paperless_mobile/features/labels/model/label.model.dart';
|
||||
import 'package:paperless_mobile/features/labels/model/label_state.dart';
|
||||
import 'package:paperless_mobile/features/labels/repository/label_repository.dart';
|
||||
|
||||
abstract class LabelCubit<T extends Label> extends Cubit<LabelState<T>> {
|
||||
final LabelRepository labelRepository;
|
||||
|
||||
LabelCubit(this.labelRepository) : super(LabelState.initial());
|
||||
|
||||
@protected
|
||||
void loadFrom(Iterable<T> items) {
|
||||
emit(
|
||||
LabelState(
|
||||
isLoaded: true,
|
||||
labels: Map.fromIterable(items, key: (e) => (e as T).id!),
|
||||
),
|
||||
);
|
||||
}
|
||||
|
||||
Future<T> add(T item) async {
|
||||
assert(item.id == null);
|
||||
final addedItem = await save(item);
|
||||
final newValues = {...state.labels};
|
||||
newValues.putIfAbsent(addedItem.id!, () => addedItem);
|
||||
emit(
|
||||
LabelState(
|
||||
isLoaded: true,
|
||||
labels: newValues,
|
||||
),
|
||||
);
|
||||
return addedItem;
|
||||
}
|
||||
|
||||
Future<T> replace(T item) async {
|
||||
assert(item.id != null);
|
||||
final updatedItem = await update(item);
|
||||
final updatedValues = {...state.labels};
|
||||
updatedValues[item.id!] = updatedItem;
|
||||
emit(
|
||||
LabelState(
|
||||
isLoaded: state.isLoaded,
|
||||
labels: updatedValues,
|
||||
),
|
||||
);
|
||||
return updatedItem;
|
||||
}
|
||||
|
||||
Future<void> remove(T item) async {
|
||||
assert(item.id != null);
|
||||
if (state.labels.containsKey(item.id)) {
|
||||
final deletedId = await delete(item);
|
||||
final updatedValues = {...state.labels}..remove(deletedId);
|
||||
emit(
|
||||
LabelState(isLoaded: true, labels: updatedValues),
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
void reset() {
|
||||
emit(LabelState(isLoaded: false, labels: {}));
|
||||
}
|
||||
|
||||
Future<void> initialize();
|
||||
|
||||
@protected
|
||||
Future<T> save(T item);
|
||||
|
||||
@protected
|
||||
Future<T> update(T item);
|
||||
|
||||
@protected
|
||||
Future<int> delete(T item);
|
||||
}
|
||||
Reference in New Issue
Block a user