mirror of
https://github.com/Xevion/paperless-mobile.git
synced 2025-12-10 02:07:57 -06:00
Implemented inbox (still WIP)
This commit is contained in:
@@ -1,27 +0,0 @@
|
||||
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,
|
||||
);
|
||||
}
|
||||
}
|
||||
@@ -1,55 +0,0 @@
|
||||
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/repository/label_repository.dart';
|
||||
|
||||
abstract class LabelCubit<T extends Label> extends Cubit<Map<int, T>> {
|
||||
final LabelRepository labelRepository;
|
||||
|
||||
LabelCubit(this.labelRepository) : super({});
|
||||
|
||||
@protected
|
||||
void loadFrom(Iterable<T> items) =>
|
||||
emit(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 newState = {...state};
|
||||
newState.putIfAbsent(addedItem.id!, () => addedItem);
|
||||
emit(newState);
|
||||
return addedItem;
|
||||
}
|
||||
|
||||
Future<T> replace(T item) async {
|
||||
assert(item.id != null);
|
||||
final updatedItem = await update(item);
|
||||
final newState = {...state};
|
||||
newState[item.id!] = updatedItem;
|
||||
emit(newState);
|
||||
return updatedItem;
|
||||
}
|
||||
|
||||
Future<void> remove(T item) async {
|
||||
assert(item.id != null);
|
||||
if (state.containsKey(item.id)) {
|
||||
final deletedId = await delete(item);
|
||||
final newState = {...state};
|
||||
newState.remove(deletedId);
|
||||
emit(newState);
|
||||
}
|
||||
}
|
||||
|
||||
void reset() => emit({});
|
||||
|
||||
Future<void> initialize();
|
||||
|
||||
@protected
|
||||
Future<T> save(T item);
|
||||
|
||||
@protected
|
||||
Future<T> update(T item);
|
||||
|
||||
@protected
|
||||
Future<int> delete(T item);
|
||||
}
|
||||
@@ -11,7 +11,7 @@ class PaperlessServerInformationCubit
|
||||
PaperlessServerInformationCubit(this.service)
|
||||
: super(PaperlessServerInformation());
|
||||
|
||||
Future<void> updateStatus() async {
|
||||
Future<void> updateInformtion() async {
|
||||
emit(await service.getInformation());
|
||||
}
|
||||
}
|
||||
|
||||
62
lib/core/bloc/paperless_statistics_cubit.dart
Normal file
62
lib/core/bloc/paperless_statistics_cubit.dart
Normal file
@@ -0,0 +1,62 @@
|
||||
import 'dart:math';
|
||||
|
||||
import 'package:flutter_bloc/flutter_bloc.dart';
|
||||
import 'package:injectable/injectable.dart';
|
||||
import 'package:paperless_mobile/core/model/paperless_statistics.dart';
|
||||
import 'package:paperless_mobile/core/model/paperless_statistics_state.dart';
|
||||
import 'package:paperless_mobile/core/service/paperless_statistics_service.dart';
|
||||
|
||||
@singleton
|
||||
class PaperlessStatisticsCubit extends Cubit<PaperlessStatisticsState> {
|
||||
final PaperlessStatisticsService statisticsService;
|
||||
|
||||
PaperlessStatisticsCubit(this.statisticsService)
|
||||
: super(PaperlessStatisticsState(isLoaded: false));
|
||||
|
||||
Future<void> updateStatistics() async {
|
||||
final stats = await statisticsService.getStatistics();
|
||||
emit(PaperlessStatisticsState(isLoaded: true, statistics: stats));
|
||||
}
|
||||
|
||||
void decrementInboxCount() {
|
||||
if (state.isLoaded) {
|
||||
emit(
|
||||
PaperlessStatisticsState(
|
||||
isLoaded: true,
|
||||
statistics: PaperlessStatistics(
|
||||
documentsInInbox: max(0, state.statistics!.documentsInInbox - 1),
|
||||
documentsTotal: state.statistics!.documentsTotal,
|
||||
),
|
||||
),
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
void incrementInboxCount() {
|
||||
if (state.isLoaded) {
|
||||
emit(
|
||||
PaperlessStatisticsState(
|
||||
isLoaded: true,
|
||||
statistics: PaperlessStatistics(
|
||||
documentsInInbox: state.statistics!.documentsInInbox + 1,
|
||||
documentsTotal: state.statistics!.documentsTotal,
|
||||
),
|
||||
),
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
void resetInboxCount() {
|
||||
if (state.isLoaded) {
|
||||
emit(
|
||||
PaperlessStatisticsState(
|
||||
isLoaded: true,
|
||||
statistics: PaperlessStatistics(
|
||||
documentsInInbox: 0,
|
||||
documentsTotal: state.statistics!.documentsTotal,
|
||||
),
|
||||
),
|
||||
);
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user