Improve documents

This commit is contained in:
Hillel Coren 2023-08-09 15:56:31 +03:00
parent a9288f19b7
commit e58815d8cd
4 changed files with 16 additions and 7 deletions

View File

@ -169,12 +169,13 @@ Middleware<AppState> _downloadDocuments(DocumentRepository repository) {
Middleware<AppState> _deleteDocument(DocumentRepository repository) { Middleware<AppState> _deleteDocument(DocumentRepository repository) {
return (Store<AppState> store, dynamic dynamicAction, NextDispatcher next) { return (Store<AppState> store, dynamic dynamicAction, NextDispatcher next) {
final action = dynamicAction as DeleteDocumentRequest; final action = dynamicAction as DeleteDocumentRequest;
final documentId = action.documentIds.first;
repository repository
.delete(store.state.credentials, action.documentIds.first, .delete(store.state.credentials, documentId, action.password,
action.password, action.idToken) action.idToken)
.then((value) { .then((value) {
store.dispatch(DeleteDocumentSuccess()); store.dispatch(DeleteDocumentSuccess(documentId: documentId));
if (action.completer != null) { if (action.completer != null) {
action.completer.complete(null); action.completer.complete(null);
} }

View File

@ -184,7 +184,9 @@ DocumentState _archiveDocumentSuccess(
DocumentState _deleteDocumentSuccess( DocumentState _deleteDocumentSuccess(
DocumentState documentState, DeleteDocumentSuccess action) { DocumentState documentState, DeleteDocumentSuccess action) {
return documentState.rebuild((b) => b..map.remove(action.documentId)); return documentState.rebuild((b) => b
..map.remove(action.documentId)
..list.remove(action.documentId));
} }
DocumentState _restoreDocumentSuccess( DocumentState _restoreDocumentSuccess(

View File

@ -1,4 +1,5 @@
// Package imports: // Package imports:
import 'package:invoiceninja_flutter/redux/document/document_actions.dart';
import 'package:invoiceninja_flutter/redux/settings/settings_state.dart'; import 'package:invoiceninja_flutter/redux/settings/settings_state.dart';
import 'package:redux/redux.dart'; import 'package:redux/redux.dart';
@ -78,6 +79,11 @@ Reducer<SettingsUIState> settingsUIReducer = combineReducers([
..updatedAt = DateTime.now().millisecondsSinceEpoch ..updatedAt = DateTime.now().millisecondsSinceEpoch
..isChanged = false); ..isChanged = false);
}), }),
TypedReducer<SettingsUIState, DeleteDocumentSuccess>((state, action) {
return state.rebuild(
(b) => b..updatedAt = DateTime.now().millisecondsSinceEpoch,
);
}),
TypedReducer<SettingsUIState, SaveGroupSuccess>((state, action) { TypedReducer<SettingsUIState, SaveGroupSuccess>((state, action) {
return state.rebuild((b) => b return state.rebuild((b) => b
..group.replace(action.group) ..group.replace(action.group)

View File

@ -251,9 +251,9 @@ class _CompanyDetailsState extends State<CompanyDetails>
), ),
if (!state.settingsUIState.isFiltered) if (!state.settingsUIState.isFiltered)
Tab( Tab(
text: company.documents.isEmpty text: state.company.documents.isEmpty
? localization.documents ? localization.documents
: '${localization.documents} (${company.documents.length})', : '${localization.documents} (${state.company.documents.length})',
), ),
], ],
), ),
@ -700,7 +700,7 @@ class _CompanyDetailsState extends State<CompanyDetails>
), ),
if (!state.settingsUIState.isFiltered) if (!state.settingsUIState.isFiltered)
DocumentGrid( DocumentGrid(
documents: company.documents.toList(), documents: state.company.documents.toList(),
onUploadDocument: (path) => onUploadDocument: (path) =>
viewModel.onUploadDocuments(context, path), viewModel.onUploadDocuments(context, path),
onDeleteDocument: (document, password, idToken) => viewModel onDeleteDocument: (document, password, idToken) => viewModel