Fix ghost company when deleting and then restarting
This commit is contained in:
parent
54aa120a96
commit
8cd5489bd1
|
|
@ -367,20 +367,25 @@ Middleware<AppState> _createPersistData(
|
||||||
|
|
||||||
next(action);
|
next(action);
|
||||||
|
|
||||||
_persistDataDebouncer.run(() {
|
void saveState() {
|
||||||
print('## Calling Persist Data');
|
|
||||||
if (!store.state.isLoaded) {
|
|
||||||
print('## Not loaded: skipping');
|
|
||||||
return;
|
|
||||||
} else {
|
|
||||||
print('## Loaded: saving data');
|
|
||||||
}
|
|
||||||
|
|
||||||
final AppState state = store.state;
|
final AppState state = store.state;
|
||||||
final index = state.uiState.selectedCompanyIndex;
|
final index = state.uiState.selectedCompanyIndex;
|
||||||
companyRepositories[index]
|
companyRepositories[index]
|
||||||
.saveCompanyState(state.userCompanyStates[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();
|
||||||
|
});
|
||||||
|
}
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -581,9 +581,11 @@ abstract class AppState implements Built<AppState, AppStateBuilder> {
|
||||||
@override
|
@override
|
||||||
String toString() {
|
String toString() {
|
||||||
//return 'latestVersion: ${account.latestVersion}';
|
//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 '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}';
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -29,9 +29,7 @@ import 'package:invoiceninja_flutter/redux/company_gateway/company_gateway_reduc
|
||||||
import 'package:invoiceninja_flutter/redux/group/group_reducer.dart';
|
import 'package:invoiceninja_flutter/redux/group/group_reducer.dart';
|
||||||
|
|
||||||
UserCompanyState companyReducer(UserCompanyState state, dynamic action) {
|
UserCompanyState companyReducer(UserCompanyState state, dynamic action) {
|
||||||
if (action is LoadAccountSuccess) {
|
if (action is DeleteCompanySuccess) {
|
||||||
return UserCompanyState();
|
|
||||||
} else if (action is DeleteCompanySuccess) {
|
|
||||||
return UserCompanyState();
|
return UserCompanyState();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue