Fix ghost company when deleting and then restarting

This commit is contained in:
Hillel Coren 2020-07-13 00:04:23 +03:00
parent 54aa120a96
commit 8cd5489bd1
3 changed files with 20 additions and 15 deletions

View File

@ -367,20 +367,25 @@ Middleware<AppState> _createPersistData(
next(action);
_persistDataDebouncer.run(() {
print('## Calling Persist Data');
if (!store.state.isLoaded) {
print('## Not loaded: skipping');
return;
} else {
print('## Loaded: saving data');
}
void saveState() {
final AppState state = store.state;
final index = state.uiState.selectedCompanyIndex;
companyRepositories[index]
.saveCompanyState(state.userCompanyStates[index]);
});
}
// When a company is deleted the app switches to another company
// so we need to save it immediately before the selection changes
if (action is DeleteCompanySuccess) {
saveState();
} else {
_persistDataDebouncer.run(() {
if (!store.state.isLoaded) {
return;
}
saveState();
});
}
};
}

View File

@ -581,9 +581,11 @@ abstract class AppState implements Built<AppState, AppStateBuilder> {
@override
String toString() {
//return 'latestVersion: ${account.latestVersion}';
return 'Last Updated: ${userCompanyStates.map((state) => state.lastUpdated).join(',')}';
//return 'Last Updated: ${userCompanyStates.map((state) => state.lastUpdated).join(',')}';
//return 'Names: ${userCompanyStates.map((state) => state.company.id).join(',')}';
//return 'Client Count: ${userCompanyState.clientState.list.length}, Last Updated: ${userCompanyState.lastUpdated}';
//return 'Token: ${credentials.token} - ${userCompanyStates.map((state) => state?.token?.token ?? '').where((name) => name.isNotEmpty).join(',')}';
//return 'URL: ${authState.url}, Route: ${uiState.currentRoute} Prev: ${uiState.previousRoute}';
return 'URL: ${authState.url}, Route: ${uiState.currentRoute} Prev: ${uiState.previousRoute}';
}
}

View File

@ -29,9 +29,7 @@ import 'package:invoiceninja_flutter/redux/company_gateway/company_gateway_reduc
import 'package:invoiceninja_flutter/redux/group/group_reducer.dart';
UserCompanyState companyReducer(UserCompanyState state, dynamic action) {
if (action is LoadAccountSuccess) {
return UserCompanyState();
} else if (action is DeleteCompanySuccess) {
if (action is DeleteCompanySuccess) {
return UserCompanyState();
}