Persist client preview tab and table page
This commit is contained in:
parent
5b0a8d4837
commit
db2f9bc570
|
|
@ -455,3 +455,15 @@ class SaveClientDocumentFailure implements StopSaving {
|
|||
|
||||
final Object error;
|
||||
}
|
||||
|
||||
class UpdateClientTab implements PersistUI {
|
||||
UpdateClientTab({this.tabIndex});
|
||||
|
||||
final int tabIndex;
|
||||
}
|
||||
|
||||
class UpdateClientTablePage implements PersistUI {
|
||||
UpdateClientTablePage({this.tableIndex});
|
||||
|
||||
final int tableIndex;
|
||||
}
|
||||
|
|
|
|||
|
|
@ -17,10 +17,27 @@ EntityUIState clientUIReducer(ClientUIState state, dynamic action) {
|
|||
..editingContact
|
||||
.replace(editingContactReducer(state.editingContact, action))
|
||||
..selectedId = selectedIdReducer(state.selectedId, action)
|
||||
..tabIndex = tabIndexReducer(state.tabIndex, action)
|
||||
..tablePage = tablePageIndexReducer(state.tablePage, action)
|
||||
..saveCompleter = saveCompleterReducer(state.saveCompleter, action)
|
||||
..cancelCompleter = cancelCompleterReducer(state.cancelCompleter, action));
|
||||
}
|
||||
|
||||
final tabIndexReducer = combineReducers<int>([
|
||||
TypedReducer<int, UpdateClientTab>((completer, action) {
|
||||
return action.tabIndex;
|
||||
}),
|
||||
TypedReducer<int, PreviewEntity>((completer, action) {
|
||||
return null;
|
||||
}),
|
||||
]);
|
||||
|
||||
final tablePageIndexReducer = combineReducers<int>([
|
||||
TypedReducer<int, UpdateClientTablePage>((completer, action) {
|
||||
return action.tableIndex;
|
||||
}),
|
||||
]);
|
||||
|
||||
final saveCompleterReducer = combineReducers<Completer<SelectableEntity>>([
|
||||
TypedReducer<Completer<SelectableEntity>, EditClient>((completer, action) {
|
||||
return action.completer;
|
||||
|
|
|
|||
|
|
@ -34,6 +34,7 @@ class ClientListBuilder extends StatelessWidget {
|
|||
onRefreshed: viewModel.onRefreshed,
|
||||
onSortColumn: viewModel.onSortColumn,
|
||||
onClearMultiselect: viewModel.onClearMultielsect,
|
||||
onPageChanged: viewModel.onPageChanged,
|
||||
itemBuilder: (BuildContext context, index) {
|
||||
final state = viewModel.state;
|
||||
final clientId = viewModel.clientList[index];
|
||||
|
|
@ -65,6 +66,7 @@ class ClientListVM {
|
|||
@required this.onEntityAction,
|
||||
@required this.onSortColumn,
|
||||
@required this.onClearMultielsect,
|
||||
@required this.onPageChanged,
|
||||
});
|
||||
|
||||
final AppState state;
|
||||
|
|
@ -77,6 +79,7 @@ class ClientListVM {
|
|||
final List<String> tableColumns;
|
||||
final Function(String) onSortColumn;
|
||||
final Function onClearMultielsect;
|
||||
final Function(int) onPageChanged;
|
||||
|
||||
static ClientListVM fromStore(Store<AppState> store) {
|
||||
Future<Null> _handleRefresh(BuildContext context) {
|
||||
|
|
@ -114,6 +117,8 @@ class ClientListVM {
|
|||
ClientPresenter.getDefaultTableFields(state.userCompany),
|
||||
onSortColumn: (field) => store.dispatch(SortClients(field)),
|
||||
onClearMultielsect: () => store.dispatch(ClearClientMultiselect()),
|
||||
onPageChanged: (index) =>
|
||||
store.dispatch(UpdateClientTablePage(tableIndex: index)),
|
||||
);
|
||||
} //
|
||||
}
|
||||
|
|
|
|||
|
|
@ -37,11 +37,23 @@ class _ClientViewState extends State<ClientView>
|
|||
@override
|
||||
void initState() {
|
||||
super.initState();
|
||||
_controller = TabController(vsync: this, length: 6);
|
||||
|
||||
final state = widget.viewModel.state;
|
||||
_controller = TabController(
|
||||
vsync: this,
|
||||
length: 6,
|
||||
initialIndex: state.clientUIState.tabIndex ?? 0);
|
||||
_controller.addListener(_onTabChanged);
|
||||
}
|
||||
|
||||
void _onTabChanged() {
|
||||
final store = StoreProvider.of<AppState>(context);
|
||||
store.dispatch(UpdateClientTab(tabIndex: _controller.index));
|
||||
}
|
||||
|
||||
@override
|
||||
void dispose() {
|
||||
_controller.removeListener(_onTabChanged);
|
||||
_controller.dispose();
|
||||
super.dispose();
|
||||
}
|
||||
|
|
|
|||
Loading…
Reference in New Issue