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