diff --git a/lib/constants.dart b/lib/constants.dart index c444b6412..5877c930d 100644 --- a/lib/constants.dart +++ b/lib/constants.dart @@ -1,7 +1,7 @@ import 'package:flutter/material.dart'; // This version must be updated in tandem with the pubspec version. -const String kAppVersion = '2.0.1'; +const String kAppVersion = '2.0.0'; const String kSiteUrl = 'https://invoiceninja.com'; const String kAppUrl = 'https://admin.invoiceninja.com'; //const String kAppUrl = 'https://staging.invoicing.co'; @@ -24,7 +24,6 @@ const String kSharedPrefUrl = 'url'; const String kSharedPrefSecret = 'secret'; const String kSharedPrefToken = 'api_token'; - // TODO remove these const String kSharedPrefAddDocumentsToInvoice = 'add_documents_to_invoice'; const String kSharedPrefEmailPayment = 'email_payment'; diff --git a/lib/redux/ui/pref_reducer.dart b/lib/redux/ui/pref_reducer.dart index 2a2dce458..2c8d1e58e 100644 --- a/lib/redux/ui/pref_reducer.dart +++ b/lib/redux/ui/pref_reducer.dart @@ -21,8 +21,11 @@ import 'package:invoiceninja_flutter/redux/user/user_actions.dart'; import 'package:invoiceninja_flutter/redux/vendor/vendor_actions.dart'; import 'package:redux/redux.dart'; -PrefState prefReducer(PrefState state, dynamic action) { +PrefState prefReducer( + PrefState state, dynamic action, int selectedCompanyIndex) { return state.rebuild((b) => b + ..companyPrefs[selectedCompanyIndex] = + companyPrefReducer(state.companyPrefs[selectedCompanyIndex], action) ..layout = layoutReducer(state.layout, action) ..menuSidebarMode = manuSidebarReducer(state.menuSidebarMode, action) ..historySidebarMode = @@ -30,8 +33,6 @@ PrefState prefReducer(PrefState state, dynamic action) { ..isMenuVisible = menuVisibleReducer(state.isMenuVisible, action) ..isHistoryVisible = historyVisibleReducer(state.isHistoryVisible, action) ..enableDarkMode = darkModeReducer(state.enableDarkMode, action) - //..accentColor = accentColorReducer(state.accentColor, action) - //..historyList.replace(historyReducer(state.historyList, action)) ..longPressSelectionIsDefault = longPressReducer(state.longPressSelectionIsDefault, action) ..autoStartTasks = autoStartTasksReducer(state.autoStartTasks, action) @@ -42,118 +43,6 @@ PrefState prefReducer(PrefState state, dynamic action) { addDocumentsToInvoiceReducer(state.addDocumentsToInvoice, action)); } -Reducer> historyReducer = combineReducers([ - TypedReducer, ViewClient>((historyList, action) => - _addToHistory(historyList, - HistoryRecord(id: action.clientId, entityType: EntityType.client))), - TypedReducer, EditClient>((historyList, action) => - _addToHistory(historyList, - HistoryRecord(id: action.client.id, entityType: EntityType.client))), - TypedReducer, ViewProduct>((historyList, action) => - _addToHistory(historyList, - HistoryRecord(id: action.productId, entityType: EntityType.product))), - TypedReducer, EditProduct>((historyList, action) => - _addToHistory( - historyList, - HistoryRecord( - id: action.product.id, entityType: EntityType.product))), - TypedReducer, ViewInvoice>((historyList, action) => - _addToHistory(historyList, - HistoryRecord(id: action.invoiceId, entityType: EntityType.invoice))), - TypedReducer, EditInvoice>((historyList, action) => - _addToHistory( - historyList, - HistoryRecord( - id: action.invoice.id, entityType: EntityType.invoice))), - TypedReducer, ViewPayment>((historyList, action) => - _addToHistory(historyList, - HistoryRecord(id: action.paymentId, entityType: EntityType.payment))), - TypedReducer, EditPayment>((historyList, action) => - _addToHistory( - historyList, - HistoryRecord( - id: action.payment.id, entityType: EntityType.payment))), - TypedReducer, ViewQuote>((historyList, action) => - _addToHistory(historyList, - HistoryRecord(id: action.quoteId, entityType: EntityType.quote))), - TypedReducer, EditQuote>((historyList, action) => - _addToHistory(historyList, - HistoryRecord(id: action.quote.id, entityType: EntityType.quote))), - TypedReducer, ViewTask>((historyList, action) => - _addToHistory(historyList, - HistoryRecord(id: action.taskId, entityType: EntityType.task))), - TypedReducer, EditTask>((historyList, action) => - _addToHistory(historyList, - HistoryRecord(id: action.task.id, entityType: EntityType.task))), - TypedReducer, ViewProject>((historyList, action) => - _addToHistory(historyList, - HistoryRecord(id: action.projectId, entityType: EntityType.project))), - TypedReducer, EditProject>((historyList, action) => - _addToHistory( - historyList, - HistoryRecord( - id: action.project.id, entityType: EntityType.project))), - TypedReducer, ViewVendor>((historyList, action) => - _addToHistory(historyList, - HistoryRecord(id: action.vendorId, entityType: EntityType.vendor))), - TypedReducer, EditVendor>((historyList, action) => - _addToHistory(historyList, - HistoryRecord(id: action.vendor.id, entityType: EntityType.vendor))), - TypedReducer, ViewExpense>((historyList, action) => - _addToHistory(historyList, - HistoryRecord(id: action.expenseId, entityType: EntityType.expense))), - TypedReducer, EditExpense>((historyList, action) => - _addToHistory( - historyList, - HistoryRecord( - id: action.expense.id, entityType: EntityType.expense))), - TypedReducer, ViewCompanyGateway>( - (historyList, action) => _addToHistory( - historyList, - HistoryRecord( - id: action.companyGatewayId, - entityType: EntityType.companyGateway))), - TypedReducer, EditCompanyGateway>( - (historyList, action) => _addToHistory( - historyList, - HistoryRecord( - id: action.companyGateway.id, - entityType: EntityType.companyGateway))), - TypedReducer, ViewUser>((historyList, action) => - _addToHistory(historyList, - HistoryRecord(id: action.userId, entityType: EntityType.user))), - TypedReducer, EditUser>((historyList, action) => - _addToHistory(historyList, - HistoryRecord(id: action.user.id, entityType: EntityType.user))), - TypedReducer, ViewGroup>((historyList, action) => - _addToHistory(historyList, - HistoryRecord(id: action.groupId, entityType: EntityType.group))), - TypedReducer, EditGroup>((historyList, action) => - _addToHistory(historyList, - HistoryRecord(id: action.group.id, entityType: EntityType.group))), - // TODO add to starter.sh -]); - -BuiltList _addToHistory( - BuiltList list, HistoryRecord record) { - // don't track new records - if (record.id.startsWith('-')) { - return list; - } - - final old = - list.firstWhere((item) => item.matchesRecord(record), orElse: () => null); - if (old != null) { - return list.rebuild((b) => b - ..remove(old) - ..insert(0, record)); - } else { - return list.rebuild((b) => b - ..insert(0, record) - ..sublist(0, min(200, list.length + 1))); - } -} - Reducer menuVisibleReducer = combineReducers([ TypedReducer((value, action) { return action.sidebar == AppSidebar.menu ? !value : value; @@ -220,12 +109,6 @@ Reducer darkModeReducer = combineReducers([ }), ]); -Reducer accentColorReducer = combineReducers([ - TypedReducer((accentColor, action) { - return action.accentColor ?? accentColor; - }), -]); - Reducer longPressReducer = combineReducers([ TypedReducer( (longPressSelectionIsDefault, action) { @@ -349,3 +232,127 @@ Reducer settingsUIReducer = combineReducers([ : state.filterClearedAt); }), ]); + +CompanyPrefState companyPrefReducer(CompanyPrefState state, dynamic action) { + return state.rebuild((b) => b + ..accentColor = accentColorReducer(state.accentColor, action) + ..historyList.replace(historyReducer(state.historyList, action))); +} + +Reducer accentColorReducer = combineReducers([ + TypedReducer((accentColor, action) { + return action.accentColor ?? accentColor; + }), +]); + +Reducer> historyReducer = combineReducers([ + TypedReducer, ViewClient>((historyList, action) => + _addToHistory(historyList, + HistoryRecord(id: action.clientId, entityType: EntityType.client))), + TypedReducer, EditClient>((historyList, action) => + _addToHistory(historyList, + HistoryRecord(id: action.client.id, entityType: EntityType.client))), + TypedReducer, ViewProduct>((historyList, action) => + _addToHistory(historyList, + HistoryRecord(id: action.productId, entityType: EntityType.product))), + TypedReducer, EditProduct>((historyList, action) => + _addToHistory( + historyList, + HistoryRecord( + id: action.product.id, entityType: EntityType.product))), + TypedReducer, ViewInvoice>((historyList, action) => + _addToHistory(historyList, + HistoryRecord(id: action.invoiceId, entityType: EntityType.invoice))), + TypedReducer, EditInvoice>((historyList, action) => + _addToHistory( + historyList, + HistoryRecord( + id: action.invoice.id, entityType: EntityType.invoice))), + TypedReducer, ViewPayment>((historyList, action) => + _addToHistory(historyList, + HistoryRecord(id: action.paymentId, entityType: EntityType.payment))), + TypedReducer, EditPayment>((historyList, action) => + _addToHistory( + historyList, + HistoryRecord( + id: action.payment.id, entityType: EntityType.payment))), + TypedReducer, ViewQuote>((historyList, action) => + _addToHistory(historyList, + HistoryRecord(id: action.quoteId, entityType: EntityType.quote))), + TypedReducer, EditQuote>((historyList, action) => + _addToHistory(historyList, + HistoryRecord(id: action.quote.id, entityType: EntityType.quote))), + TypedReducer, ViewTask>((historyList, action) => + _addToHistory(historyList, + HistoryRecord(id: action.taskId, entityType: EntityType.task))), + TypedReducer, EditTask>((historyList, action) => + _addToHistory(historyList, + HistoryRecord(id: action.task.id, entityType: EntityType.task))), + TypedReducer, ViewProject>((historyList, action) => + _addToHistory(historyList, + HistoryRecord(id: action.projectId, entityType: EntityType.project))), + TypedReducer, EditProject>((historyList, action) => + _addToHistory( + historyList, + HistoryRecord( + id: action.project.id, entityType: EntityType.project))), + TypedReducer, ViewVendor>((historyList, action) => + _addToHistory(historyList, + HistoryRecord(id: action.vendorId, entityType: EntityType.vendor))), + TypedReducer, EditVendor>((historyList, action) => + _addToHistory(historyList, + HistoryRecord(id: action.vendor.id, entityType: EntityType.vendor))), + TypedReducer, ViewExpense>((historyList, action) => + _addToHistory(historyList, + HistoryRecord(id: action.expenseId, entityType: EntityType.expense))), + TypedReducer, EditExpense>((historyList, action) => + _addToHistory( + historyList, + HistoryRecord( + id: action.expense.id, entityType: EntityType.expense))), + TypedReducer, ViewCompanyGateway>( + (historyList, action) => _addToHistory( + historyList, + HistoryRecord( + id: action.companyGatewayId, + entityType: EntityType.companyGateway))), + TypedReducer, EditCompanyGateway>( + (historyList, action) => _addToHistory( + historyList, + HistoryRecord( + id: action.companyGateway.id, + entityType: EntityType.companyGateway))), + TypedReducer, ViewUser>((historyList, action) => + _addToHistory(historyList, + HistoryRecord(id: action.userId, entityType: EntityType.user))), + TypedReducer, EditUser>((historyList, action) => + _addToHistory(historyList, + HistoryRecord(id: action.user.id, entityType: EntityType.user))), + TypedReducer, ViewGroup>((historyList, action) => + _addToHistory(historyList, + HistoryRecord(id: action.groupId, entityType: EntityType.group))), + TypedReducer, EditGroup>((historyList, action) => + _addToHistory(historyList, + HistoryRecord(id: action.group.id, entityType: EntityType.group))), + // TODO add to starter.sh +]); + +BuiltList _addToHistory( + BuiltList list, HistoryRecord record) { + // don't track new records + if (record.id.startsWith('-')) { + return list; + } + + final old = + list.firstWhere((item) => item.matchesRecord(record), orElse: () => null); + if (old != null) { + return list.rebuild((b) => b + ..remove(old) + ..insert(0, record)); + } else { + return list.rebuild((b) => b + ..insert(0, record) + ..sublist(0, min(200, list.length + 1))); + } +} diff --git a/lib/redux/ui/ui_reducer.dart b/lib/redux/ui/ui_reducer.dart index d36a4b04f..06ccd9998 100644 --- a/lib/redux/ui/ui_reducer.dart +++ b/lib/redux/ui/ui_reducer.dart @@ -47,7 +47,8 @@ import 'package:invoiceninja_flutter/redux/group/group_reducer.dart'; UIState uiReducer(UIState state, dynamic action) { final currentRoute = currentRouteReducer(state.currentRoute, action); return state.rebuild((b) => b - ..prefState.replace(prefReducer(state.prefState, action)) + ..prefState.replace( + prefReducer(state.prefState, action, state.selectedCompanyIndex)) ..filter = filterReducer(state.filter, action) ..filterClearedAt = filterClearedAtReducer(state.filterClearedAt, action) ..selectedCompanyIndex = @@ -76,8 +77,8 @@ UIState uiReducer(UIState state, dynamic action) { ..projectUIState.replace(projectUIReducer(state.projectUIState, action)) ..paymentUIState.replace(paymentUIReducer(state.paymentUIState, action)) ..quoteUIState.replace(quoteUIReducer(state.quoteUIState, action)) - ..settingsUIState.replace(settingsUIReducer(state.settingsUIState, action)) - ); + ..settingsUIState + .replace(settingsUIReducer(state.settingsUIState, action))); } Reducer> historyReducer = combineReducers([ diff --git a/lib/ui/app/forms/color_picker.dart b/lib/ui/app/forms/color_picker.dart index 6cd5feb83..b72542713 100644 --- a/lib/ui/app/forms/color_picker.dart +++ b/lib/ui/app/forms/color_picker.dart @@ -100,11 +100,8 @@ class _FormColorPickerState extends State { FlatButton( child: Text(localization.done.toUpperCase()), onPressed: () { - widget.onSelected(_pendingColor); + _selectColor(_pendingColor); _textController.text = _pendingColor; - setState(() { - _selectedColor = _pendingColor; - }); Navigator.of(context).pop(); }, ), diff --git a/lib/ui/app/forms/save_cancel_buttons.dart b/lib/ui/app/forms/save_cancel_buttons.dart index 98b8fb98e..79ee6427d 100644 --- a/lib/ui/app/forms/save_cancel_buttons.dart +++ b/lib/ui/app/forms/save_cancel_buttons.dart @@ -26,6 +26,7 @@ class SaveCancelButtons extends StatelessWidget { return FlatButton( child: Text( localization.cancel, + style: TextStyle(color: Colors.white), ), onPressed: () => onCancelPressed(context), ); diff --git a/lib/ui/app/history_drawer.dart b/lib/ui/app/history_drawer.dart index e987ad0bf..0d1202b2d 100644 --- a/lib/ui/app/history_drawer.dart +++ b/lib/ui/app/history_drawer.dart @@ -77,9 +77,13 @@ class HistoryDrawer extends StatelessWidget { ) else FlatButton( - child: Text(localization.close), + child: Text( + localization.close, + style: TextStyle(color: Colors.white), + ), onPressed: () { - store.dispatch(UserSettingsChanged(sidebar: AppSidebar.history)); + store.dispatch( + UserSettingsChanged(sidebar: AppSidebar.history)); }, ) ],