Code refactor
This commit is contained in:
parent
276d267669
commit
657b846d55
|
|
@ -617,7 +617,7 @@ abstract class AppState implements Built<AppState, AppStateBuilder> {
|
|||
//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 'Payment Terms: ${company.settings.defaultPaymentTerms}';
|
||||
return 'Dashboard: ${uiState.dashboardUIState.selectedEntities}';
|
||||
return 'Dashboard: ${uiState.dashboardUIState.selectedEntityType}';
|
||||
return '\n\nURL: ${authState.url}\nRoute: ${uiState.currentRoute}\nPrev: ${uiState.previousRoute}\nis Large: ${(company?.isLarge ?? false) ? 'Yes' : 'No'}\nCompany: $companyUpdated${userCompanyState.isStale ? ' [S]' : ''}\nStatic: $staticUpdated${staticState.isStale ? ' [S]' : ''}\n';
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -35,3 +35,9 @@ class UpdateDashboardSelection implements PersistUI {
|
|||
EntityType entityType;
|
||||
List<String> entityIds;
|
||||
}
|
||||
|
||||
class UpdateDashboardEntityType implements PersistUI {
|
||||
UpdateDashboardEntityType({this.entityType});
|
||||
|
||||
EntityType entityType;
|
||||
}
|
||||
|
|
|
|||
|
|
@ -9,7 +9,9 @@ DashboardUIState dashboardUIReducer(DashboardUIState state, dynamic action) {
|
|||
return state.rebuild((b) => b
|
||||
..settings.replace(dashboardSettingsReducer(state.settings, action))
|
||||
..selectedEntities
|
||||
.replace(selectedEntitiesReducer(state.selectedEntities, action)));
|
||||
.replace(selectedEntitiesReducer(state.selectedEntities, action))
|
||||
..selectedEntityType =
|
||||
selectedEntityTypeReducer(state.selectedEntityType, action));
|
||||
}
|
||||
|
||||
Reducer<BuiltMap<EntityType, BuiltList<String>>> selectedEntitiesReducer =
|
||||
|
|
@ -21,6 +23,12 @@ Reducer<BuiltMap<EntityType, BuiltList<String>>> selectedEntitiesReducer =
|
|||
}),
|
||||
]);
|
||||
|
||||
Reducer<EntityType> selectedEntityTypeReducer = combineReducers([
|
||||
TypedReducer<EntityType, UpdateDashboardEntityType>((state, action) {
|
||||
return action.entityType;
|
||||
}),
|
||||
]);
|
||||
|
||||
DashboardUISettings dashboardSettingsReducer(
|
||||
DashboardUISettings state, dynamic action) {
|
||||
if (action is UpdateDashboardSettings) {
|
||||
|
|
|
|||
|
|
@ -15,6 +15,7 @@ abstract class DashboardUIState
|
|||
return _$DashboardUIState._(
|
||||
settings: DashboardUISettings(),
|
||||
selectedEntities: BuiltMap<EntityType, BuiltList<String>>(),
|
||||
selectedEntityType: EntityType.invoice,
|
||||
);
|
||||
}
|
||||
|
||||
|
|
@ -26,6 +27,8 @@ abstract class DashboardUIState
|
|||
|
||||
DashboardUISettings get settings;
|
||||
|
||||
EntityType get selectedEntityType;
|
||||
|
||||
BuiltMap<EntityType, BuiltList<String>> get selectedEntities;
|
||||
|
||||
static Serializer<DashboardUIState> get serializer =>
|
||||
|
|
|
|||
|
|
@ -25,6 +25,9 @@ class _$DashboardUIStateSerializer
|
|||
'settings',
|
||||
serializers.serialize(object.settings,
|
||||
specifiedType: const FullType(DashboardUISettings)),
|
||||
'selectedEntityType',
|
||||
serializers.serialize(object.selectedEntityType,
|
||||
specifiedType: const FullType(EntityType)),
|
||||
'selectedEntities',
|
||||
serializers.serialize(object.selectedEntities,
|
||||
specifiedType: const FullType(BuiltMap, const [
|
||||
|
|
@ -53,6 +56,10 @@ class _$DashboardUIStateSerializer
|
|||
specifiedType: const FullType(DashboardUISettings))
|
||||
as DashboardUISettings);
|
||||
break;
|
||||
case 'selectedEntityType':
|
||||
result.selectedEntityType = serializers.deserialize(value,
|
||||
specifiedType: const FullType(EntityType)) as EntityType;
|
||||
break;
|
||||
case 'selectedEntities':
|
||||
result.selectedEntities.replace(serializers.deserialize(value,
|
||||
specifiedType: const FullType(BuiltMap, const [
|
||||
|
|
@ -173,16 +180,24 @@ class _$DashboardUIState extends DashboardUIState {
|
|||
@override
|
||||
final DashboardUISettings settings;
|
||||
@override
|
||||
final EntityType selectedEntityType;
|
||||
@override
|
||||
final BuiltMap<EntityType, BuiltList<String>> selectedEntities;
|
||||
|
||||
factory _$DashboardUIState(
|
||||
[void Function(DashboardUIStateBuilder) updates]) =>
|
||||
(new DashboardUIStateBuilder()..update(updates)).build();
|
||||
|
||||
_$DashboardUIState._({this.settings, this.selectedEntities}) : super._() {
|
||||
_$DashboardUIState._(
|
||||
{this.settings, this.selectedEntityType, this.selectedEntities})
|
||||
: super._() {
|
||||
if (settings == null) {
|
||||
throw new BuiltValueNullFieldError('DashboardUIState', 'settings');
|
||||
}
|
||||
if (selectedEntityType == null) {
|
||||
throw new BuiltValueNullFieldError(
|
||||
'DashboardUIState', 'selectedEntityType');
|
||||
}
|
||||
if (selectedEntities == null) {
|
||||
throw new BuiltValueNullFieldError(
|
||||
'DashboardUIState', 'selectedEntities');
|
||||
|
|
@ -202,20 +217,23 @@ class _$DashboardUIState extends DashboardUIState {
|
|||
if (identical(other, this)) return true;
|
||||
return other is DashboardUIState &&
|
||||
settings == other.settings &&
|
||||
selectedEntityType == other.selectedEntityType &&
|
||||
selectedEntities == other.selectedEntities;
|
||||
}
|
||||
|
||||
int __hashCode;
|
||||
@override
|
||||
int get hashCode {
|
||||
return __hashCode ??=
|
||||
$jf($jc($jc(0, settings.hashCode), selectedEntities.hashCode));
|
||||
return __hashCode ??= $jf($jc(
|
||||
$jc($jc(0, settings.hashCode), selectedEntityType.hashCode),
|
||||
selectedEntities.hashCode));
|
||||
}
|
||||
|
||||
@override
|
||||
String toString() {
|
||||
return (newBuiltValueToStringHelper('DashboardUIState')
|
||||
..add('settings', settings)
|
||||
..add('selectedEntityType', selectedEntityType)
|
||||
..add('selectedEntities', selectedEntities))
|
||||
.toString();
|
||||
}
|
||||
|
|
@ -231,6 +249,11 @@ class DashboardUIStateBuilder
|
|||
set settings(DashboardUISettingsBuilder settings) =>
|
||||
_$this._settings = settings;
|
||||
|
||||
EntityType _selectedEntityType;
|
||||
EntityType get selectedEntityType => _$this._selectedEntityType;
|
||||
set selectedEntityType(EntityType selectedEntityType) =>
|
||||
_$this._selectedEntityType = selectedEntityType;
|
||||
|
||||
MapBuilder<EntityType, BuiltList<String>> _selectedEntities;
|
||||
MapBuilder<EntityType, BuiltList<String>> get selectedEntities =>
|
||||
_$this._selectedEntities ??=
|
||||
|
|
@ -244,6 +267,7 @@ class DashboardUIStateBuilder
|
|||
DashboardUIStateBuilder get _$this {
|
||||
if (_$v != null) {
|
||||
_settings = _$v.settings?.toBuilder();
|
||||
_selectedEntityType = _$v.selectedEntityType;
|
||||
_selectedEntities = _$v.selectedEntities?.toBuilder();
|
||||
_$v = null;
|
||||
}
|
||||
|
|
@ -270,12 +294,14 @@ class DashboardUIStateBuilder
|
|||
_$result = _$v ??
|
||||
new _$DashboardUIState._(
|
||||
settings: settings.build(),
|
||||
selectedEntityType: selectedEntityType,
|
||||
selectedEntities: selectedEntities.build());
|
||||
} catch (_) {
|
||||
String _$failedField;
|
||||
try {
|
||||
_$failedField = 'settings';
|
||||
settings.build();
|
||||
|
||||
_$failedField = 'selectedEntities';
|
||||
selectedEntities.build();
|
||||
} catch (e) {
|
||||
|
|
|
|||
|
|
@ -34,27 +34,27 @@ class _DashboardScreenState extends State<DashboardScreen>
|
|||
TabController _mainTabController;
|
||||
TabController _sideTabController;
|
||||
ScrollController _scrollController;
|
||||
final List<EntityType> _tabs = [];
|
||||
|
||||
@override
|
||||
void initState() {
|
||||
super.initState();
|
||||
|
||||
final company = widget.viewModel.state.company;
|
||||
int countTabs = 0;
|
||||
[
|
||||
EntityType.invoice,
|
||||
EntityType.payment,
|
||||
EntityType.quote,
|
||||
].forEach((entityType) {
|
||||
if (company.isModuleEnabled(entityType)) {
|
||||
countTabs++;
|
||||
_tabs.add(entityType);
|
||||
}
|
||||
});
|
||||
|
||||
_mainTabController = TabController(vsync: this, length: 2);
|
||||
_sideTabController = TabController(vsync: this, length: countTabs);
|
||||
_scrollController = ScrollController();
|
||||
_scrollController.addListener(onScrollListener);
|
||||
_sideTabController = TabController(vsync: this, length: _tabs.length)
|
||||
..addListener(onTabListener);
|
||||
_scrollController = ScrollController()..addListener(onScrollListener);
|
||||
}
|
||||
|
||||
void onScrollListener() {
|
||||
|
|
@ -63,15 +63,27 @@ class _DashboardScreenState extends State<DashboardScreen>
|
|||
|
||||
if (_sideTabController.index != offsetIndex) {
|
||||
_sideTabController.index = offsetIndex;
|
||||
|
||||
// This causes a bit of jank
|
||||
//widget.viewModel.onEntityTypeChanged(_tabs[offsetIndex]);
|
||||
}
|
||||
}
|
||||
|
||||
void onTabListener() {
|
||||
final index = _sideTabController.index;
|
||||
_scrollController.jumpTo((index.toDouble() * kDashboardPanelHeight) + 1);
|
||||
widget.viewModel.onEntityTypeChanged(_tabs[index]);
|
||||
}
|
||||
|
||||
@override
|
||||
void dispose() {
|
||||
_mainTabController.dispose();
|
||||
_sideTabController.dispose();
|
||||
_scrollController.removeListener(onScrollListener);
|
||||
_scrollController.dispose();
|
||||
_sideTabController
|
||||
..removeListener(onTabListener)
|
||||
..dispose();
|
||||
_scrollController
|
||||
..removeListener(onScrollListener)
|
||||
..dispose();
|
||||
super.dispose();
|
||||
}
|
||||
|
||||
|
|
@ -149,7 +161,6 @@ class _DashboardScreenState extends State<DashboardScreen>
|
|||
isLeft: true,
|
||||
child: SidebarScaffold(
|
||||
tabController: _sideTabController,
|
||||
scrollController: _scrollController,
|
||||
),
|
||||
),
|
||||
flex: 2,
|
||||
|
|
|
|||
|
|
@ -45,6 +45,7 @@ class DashboardVM {
|
|||
@required this.filter,
|
||||
@required this.filteredList,
|
||||
@required this.onRefreshed,
|
||||
@required this.onEntityTypeChanged,
|
||||
@required this.onSettingsChanged,
|
||||
@required this.onSelectionChanged,
|
||||
@required this.onOffsetChanged,
|
||||
|
|
@ -74,10 +75,11 @@ class DashboardVM {
|
|||
dashboardUIState: state.dashboardUIState,
|
||||
currencyMap: state.staticState.currencyMap,
|
||||
isLoading: state.isLoading,
|
||||
isNextEnabled:
|
||||
DateTime.parse(settings.endDate(state.company))
|
||||
.isBefore(DateTime.now()),
|
||||
isNextEnabled: DateTime.parse(settings.endDate(state.company))
|
||||
.isBefore(DateTime.now()),
|
||||
onRefreshed: (context) => _handleRefresh(context),
|
||||
onEntityTypeChanged: (entityType) =>
|
||||
store.dispatch(UpdateDashboardEntityType(entityType: entityType)),
|
||||
onSettingsChanged: (DashboardSettings settings) =>
|
||||
store.dispatch(UpdateDashboardSettings(settings: settings)),
|
||||
onSelectionChanged: (entityType, entityIds) {
|
||||
|
|
@ -105,6 +107,7 @@ class DashboardVM {
|
|||
final Function(BuildContext) onRefreshed;
|
||||
final Function(DashboardSettings) onSettingsChanged;
|
||||
final Function(EntityType, List<String>) onSelectionChanged;
|
||||
final Function(EntityType) onEntityTypeChanged;
|
||||
final Function(int) onOffsetChanged;
|
||||
final Function(String) onCurrencyChanged;
|
||||
|
||||
|
|
|
|||
|
|
@ -15,11 +15,9 @@ import 'package:invoiceninja_flutter/utils/localization.dart';
|
|||
class SidebarScaffold extends StatelessWidget {
|
||||
const SidebarScaffold({
|
||||
@required this.tabController,
|
||||
@required this.scrollController,
|
||||
});
|
||||
|
||||
final TabController tabController;
|
||||
final ScrollController scrollController;
|
||||
|
||||
@override
|
||||
Widget build(BuildContext context) {
|
||||
|
|
@ -34,10 +32,6 @@ class SidebarScaffold extends StatelessWidget {
|
|||
title: TabBar(
|
||||
isScrollable: true,
|
||||
controller: tabController,
|
||||
onTap: (int index) {
|
||||
scrollController
|
||||
.jumpTo((index.toDouble() * kDashboardPanelHeight) + 1);
|
||||
},
|
||||
tabs: [
|
||||
if (company.isModuleEnabled(EntityType.invoice))
|
||||
Tab(
|
||||
|
|
|
|||
Loading…
Reference in New Issue