mirror of
https://github.com/Xevion/paperless-mobile.git
synced 2025-12-10 06:07:57 -06:00
WIP - More decoupling of data layer from ui layer
This commit is contained in:
31
lib/features/edit_label/cubit/edit_label_cubit.dart
Normal file
31
lib/features/edit_label/cubit/edit_label_cubit.dart
Normal file
@@ -0,0 +1,31 @@
|
||||
import 'dart:async';
|
||||
|
||||
import 'package:bloc/bloc.dart';
|
||||
import 'package:paperless_api/paperless_api.dart';
|
||||
import 'package:paperless_mobile/core/repository/label_repository.dart';
|
||||
import 'package:paperless_mobile/features/edit_label/cubit/edit_label_state.dart';
|
||||
|
||||
class EditLabelCubit<T extends Label> extends Cubit<EditLabelState<T>> {
|
||||
final LabelRepository<T> _repository;
|
||||
|
||||
StreamSubscription<Map<int, T>>? _subscription;
|
||||
|
||||
EditLabelCubit(LabelRepository<T> repository)
|
||||
: _repository = repository,
|
||||
super(const EditLabelInitial()) {
|
||||
_subscription = _repository.labels
|
||||
.listen((labels) => emit(EditLabelState(labels: labels)));
|
||||
}
|
||||
|
||||
Future<void> create(T label) => _repository.create(label);
|
||||
|
||||
Future<void> update(T label) => _repository.update(label);
|
||||
|
||||
Future<void> delete(T label) => _repository.delete(label);
|
||||
|
||||
@override
|
||||
Future<void> close() {
|
||||
_subscription?.cancel();
|
||||
return super.close();
|
||||
}
|
||||
}
|
||||
16
lib/features/edit_label/cubit/edit_label_state.dart
Normal file
16
lib/features/edit_label/cubit/edit_label_state.dart
Normal file
@@ -0,0 +1,16 @@
|
||||
import 'package:equatable/equatable.dart';
|
||||
import 'package:flutter/widgets.dart';
|
||||
|
||||
@immutable
|
||||
class EditLabelState<T> extends Equatable {
|
||||
final Map<int, T> labels;
|
||||
|
||||
const EditLabelState({required this.labels});
|
||||
|
||||
@override
|
||||
List<Object> get props => [labels];
|
||||
}
|
||||
|
||||
class EditLabelInitial<T> extends EditLabelState<T> {
|
||||
const EditLabelInitial() : super(labels: const {});
|
||||
}
|
||||
Reference in New Issue
Block a user