This commit is contained in:
Hillel Coren 2019-11-17 00:34:17 +02:00
parent 0375c275b6
commit 9f7466246a
6 changed files with 141 additions and 132 deletions

View File

@ -1,7 +1,7 @@
import 'package:flutter/material.dart'; import 'package:flutter/material.dart';
// This version must be updated in tandem with the pubspec version. // 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 kSiteUrl = 'https://invoiceninja.com';
const String kAppUrl = 'https://admin.invoiceninja.com'; const String kAppUrl = 'https://admin.invoiceninja.com';
//const String kAppUrl = 'https://staging.invoicing.co'; //const String kAppUrl = 'https://staging.invoicing.co';
@ -24,7 +24,6 @@ const String kSharedPrefUrl = 'url';
const String kSharedPrefSecret = 'secret'; const String kSharedPrefSecret = 'secret';
const String kSharedPrefToken = 'api_token'; const String kSharedPrefToken = 'api_token';
// TODO remove these // TODO remove these
const String kSharedPrefAddDocumentsToInvoice = 'add_documents_to_invoice'; const String kSharedPrefAddDocumentsToInvoice = 'add_documents_to_invoice';
const String kSharedPrefEmailPayment = 'email_payment'; const String kSharedPrefEmailPayment = 'email_payment';

View File

@ -21,8 +21,11 @@ import 'package:invoiceninja_flutter/redux/user/user_actions.dart';
import 'package:invoiceninja_flutter/redux/vendor/vendor_actions.dart'; import 'package:invoiceninja_flutter/redux/vendor/vendor_actions.dart';
import 'package:redux/redux.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 return state.rebuild((b) => b
..companyPrefs[selectedCompanyIndex] =
companyPrefReducer(state.companyPrefs[selectedCompanyIndex], action)
..layout = layoutReducer(state.layout, action) ..layout = layoutReducer(state.layout, action)
..menuSidebarMode = manuSidebarReducer(state.menuSidebarMode, action) ..menuSidebarMode = manuSidebarReducer(state.menuSidebarMode, action)
..historySidebarMode = ..historySidebarMode =
@ -30,8 +33,6 @@ PrefState prefReducer(PrefState state, dynamic action) {
..isMenuVisible = menuVisibleReducer(state.isMenuVisible, action) ..isMenuVisible = menuVisibleReducer(state.isMenuVisible, action)
..isHistoryVisible = historyVisibleReducer(state.isHistoryVisible, action) ..isHistoryVisible = historyVisibleReducer(state.isHistoryVisible, action)
..enableDarkMode = darkModeReducer(state.enableDarkMode, action) ..enableDarkMode = darkModeReducer(state.enableDarkMode, action)
//..accentColor = accentColorReducer(state.accentColor, action)
//..historyList.replace(historyReducer(state.historyList, action))
..longPressSelectionIsDefault = ..longPressSelectionIsDefault =
longPressReducer(state.longPressSelectionIsDefault, action) longPressReducer(state.longPressSelectionIsDefault, action)
..autoStartTasks = autoStartTasksReducer(state.autoStartTasks, action) ..autoStartTasks = autoStartTasksReducer(state.autoStartTasks, action)
@ -42,118 +43,6 @@ PrefState prefReducer(PrefState state, dynamic action) {
addDocumentsToInvoiceReducer(state.addDocumentsToInvoice, action)); addDocumentsToInvoiceReducer(state.addDocumentsToInvoice, action));
} }
Reducer<BuiltList<HistoryRecord>> historyReducer = combineReducers([
TypedReducer<BuiltList<HistoryRecord>, ViewClient>((historyList, action) =>
_addToHistory(historyList,
HistoryRecord(id: action.clientId, entityType: EntityType.client))),
TypedReducer<BuiltList<HistoryRecord>, EditClient>((historyList, action) =>
_addToHistory(historyList,
HistoryRecord(id: action.client.id, entityType: EntityType.client))),
TypedReducer<BuiltList<HistoryRecord>, ViewProduct>((historyList, action) =>
_addToHistory(historyList,
HistoryRecord(id: action.productId, entityType: EntityType.product))),
TypedReducer<BuiltList<HistoryRecord>, EditProduct>((historyList, action) =>
_addToHistory(
historyList,
HistoryRecord(
id: action.product.id, entityType: EntityType.product))),
TypedReducer<BuiltList<HistoryRecord>, ViewInvoice>((historyList, action) =>
_addToHistory(historyList,
HistoryRecord(id: action.invoiceId, entityType: EntityType.invoice))),
TypedReducer<BuiltList<HistoryRecord>, EditInvoice>((historyList, action) =>
_addToHistory(
historyList,
HistoryRecord(
id: action.invoice.id, entityType: EntityType.invoice))),
TypedReducer<BuiltList<HistoryRecord>, ViewPayment>((historyList, action) =>
_addToHistory(historyList,
HistoryRecord(id: action.paymentId, entityType: EntityType.payment))),
TypedReducer<BuiltList<HistoryRecord>, EditPayment>((historyList, action) =>
_addToHistory(
historyList,
HistoryRecord(
id: action.payment.id, entityType: EntityType.payment))),
TypedReducer<BuiltList<HistoryRecord>, ViewQuote>((historyList, action) =>
_addToHistory(historyList,
HistoryRecord(id: action.quoteId, entityType: EntityType.quote))),
TypedReducer<BuiltList<HistoryRecord>, EditQuote>((historyList, action) =>
_addToHistory(historyList,
HistoryRecord(id: action.quote.id, entityType: EntityType.quote))),
TypedReducer<BuiltList<HistoryRecord>, ViewTask>((historyList, action) =>
_addToHistory(historyList,
HistoryRecord(id: action.taskId, entityType: EntityType.task))),
TypedReducer<BuiltList<HistoryRecord>, EditTask>((historyList, action) =>
_addToHistory(historyList,
HistoryRecord(id: action.task.id, entityType: EntityType.task))),
TypedReducer<BuiltList<HistoryRecord>, ViewProject>((historyList, action) =>
_addToHistory(historyList,
HistoryRecord(id: action.projectId, entityType: EntityType.project))),
TypedReducer<BuiltList<HistoryRecord>, EditProject>((historyList, action) =>
_addToHistory(
historyList,
HistoryRecord(
id: action.project.id, entityType: EntityType.project))),
TypedReducer<BuiltList<HistoryRecord>, ViewVendor>((historyList, action) =>
_addToHistory(historyList,
HistoryRecord(id: action.vendorId, entityType: EntityType.vendor))),
TypedReducer<BuiltList<HistoryRecord>, EditVendor>((historyList, action) =>
_addToHistory(historyList,
HistoryRecord(id: action.vendor.id, entityType: EntityType.vendor))),
TypedReducer<BuiltList<HistoryRecord>, ViewExpense>((historyList, action) =>
_addToHistory(historyList,
HistoryRecord(id: action.expenseId, entityType: EntityType.expense))),
TypedReducer<BuiltList<HistoryRecord>, EditExpense>((historyList, action) =>
_addToHistory(
historyList,
HistoryRecord(
id: action.expense.id, entityType: EntityType.expense))),
TypedReducer<BuiltList<HistoryRecord>, ViewCompanyGateway>(
(historyList, action) => _addToHistory(
historyList,
HistoryRecord(
id: action.companyGatewayId,
entityType: EntityType.companyGateway))),
TypedReducer<BuiltList<HistoryRecord>, EditCompanyGateway>(
(historyList, action) => _addToHistory(
historyList,
HistoryRecord(
id: action.companyGateway.id,
entityType: EntityType.companyGateway))),
TypedReducer<BuiltList<HistoryRecord>, ViewUser>((historyList, action) =>
_addToHistory(historyList,
HistoryRecord(id: action.userId, entityType: EntityType.user))),
TypedReducer<BuiltList<HistoryRecord>, EditUser>((historyList, action) =>
_addToHistory(historyList,
HistoryRecord(id: action.user.id, entityType: EntityType.user))),
TypedReducer<BuiltList<HistoryRecord>, ViewGroup>((historyList, action) =>
_addToHistory(historyList,
HistoryRecord(id: action.groupId, entityType: EntityType.group))),
TypedReducer<BuiltList<HistoryRecord>, EditGroup>((historyList, action) =>
_addToHistory(historyList,
HistoryRecord(id: action.group.id, entityType: EntityType.group))),
// TODO add to starter.sh
]);
BuiltList<HistoryRecord> _addToHistory(
BuiltList<HistoryRecord> 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<bool> menuVisibleReducer = combineReducers([ Reducer<bool> menuVisibleReducer = combineReducers([
TypedReducer<bool, UserSettingsChanged>((value, action) { TypedReducer<bool, UserSettingsChanged>((value, action) {
return action.sidebar == AppSidebar.menu ? !value : value; return action.sidebar == AppSidebar.menu ? !value : value;
@ -220,12 +109,6 @@ Reducer<bool> darkModeReducer = combineReducers([
}), }),
]); ]);
Reducer<String> accentColorReducer = combineReducers([
TypedReducer<String, UserSettingsChanged>((accentColor, action) {
return action.accentColor ?? accentColor;
}),
]);
Reducer<bool> longPressReducer = combineReducers([ Reducer<bool> longPressReducer = combineReducers([
TypedReducer<bool, UserSettingsChanged>( TypedReducer<bool, UserSettingsChanged>(
(longPressSelectionIsDefault, action) { (longPressSelectionIsDefault, action) {
@ -349,3 +232,127 @@ Reducer<SettingsUIState> settingsUIReducer = combineReducers([
: state.filterClearedAt); : 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<String> accentColorReducer = combineReducers([
TypedReducer<String, UserSettingsChanged>((accentColor, action) {
return action.accentColor ?? accentColor;
}),
]);
Reducer<BuiltList<HistoryRecord>> historyReducer = combineReducers([
TypedReducer<BuiltList<HistoryRecord>, ViewClient>((historyList, action) =>
_addToHistory(historyList,
HistoryRecord(id: action.clientId, entityType: EntityType.client))),
TypedReducer<BuiltList<HistoryRecord>, EditClient>((historyList, action) =>
_addToHistory(historyList,
HistoryRecord(id: action.client.id, entityType: EntityType.client))),
TypedReducer<BuiltList<HistoryRecord>, ViewProduct>((historyList, action) =>
_addToHistory(historyList,
HistoryRecord(id: action.productId, entityType: EntityType.product))),
TypedReducer<BuiltList<HistoryRecord>, EditProduct>((historyList, action) =>
_addToHistory(
historyList,
HistoryRecord(
id: action.product.id, entityType: EntityType.product))),
TypedReducer<BuiltList<HistoryRecord>, ViewInvoice>((historyList, action) =>
_addToHistory(historyList,
HistoryRecord(id: action.invoiceId, entityType: EntityType.invoice))),
TypedReducer<BuiltList<HistoryRecord>, EditInvoice>((historyList, action) =>
_addToHistory(
historyList,
HistoryRecord(
id: action.invoice.id, entityType: EntityType.invoice))),
TypedReducer<BuiltList<HistoryRecord>, ViewPayment>((historyList, action) =>
_addToHistory(historyList,
HistoryRecord(id: action.paymentId, entityType: EntityType.payment))),
TypedReducer<BuiltList<HistoryRecord>, EditPayment>((historyList, action) =>
_addToHistory(
historyList,
HistoryRecord(
id: action.payment.id, entityType: EntityType.payment))),
TypedReducer<BuiltList<HistoryRecord>, ViewQuote>((historyList, action) =>
_addToHistory(historyList,
HistoryRecord(id: action.quoteId, entityType: EntityType.quote))),
TypedReducer<BuiltList<HistoryRecord>, EditQuote>((historyList, action) =>
_addToHistory(historyList,
HistoryRecord(id: action.quote.id, entityType: EntityType.quote))),
TypedReducer<BuiltList<HistoryRecord>, ViewTask>((historyList, action) =>
_addToHistory(historyList,
HistoryRecord(id: action.taskId, entityType: EntityType.task))),
TypedReducer<BuiltList<HistoryRecord>, EditTask>((historyList, action) =>
_addToHistory(historyList,
HistoryRecord(id: action.task.id, entityType: EntityType.task))),
TypedReducer<BuiltList<HistoryRecord>, ViewProject>((historyList, action) =>
_addToHistory(historyList,
HistoryRecord(id: action.projectId, entityType: EntityType.project))),
TypedReducer<BuiltList<HistoryRecord>, EditProject>((historyList, action) =>
_addToHistory(
historyList,
HistoryRecord(
id: action.project.id, entityType: EntityType.project))),
TypedReducer<BuiltList<HistoryRecord>, ViewVendor>((historyList, action) =>
_addToHistory(historyList,
HistoryRecord(id: action.vendorId, entityType: EntityType.vendor))),
TypedReducer<BuiltList<HistoryRecord>, EditVendor>((historyList, action) =>
_addToHistory(historyList,
HistoryRecord(id: action.vendor.id, entityType: EntityType.vendor))),
TypedReducer<BuiltList<HistoryRecord>, ViewExpense>((historyList, action) =>
_addToHistory(historyList,
HistoryRecord(id: action.expenseId, entityType: EntityType.expense))),
TypedReducer<BuiltList<HistoryRecord>, EditExpense>((historyList, action) =>
_addToHistory(
historyList,
HistoryRecord(
id: action.expense.id, entityType: EntityType.expense))),
TypedReducer<BuiltList<HistoryRecord>, ViewCompanyGateway>(
(historyList, action) => _addToHistory(
historyList,
HistoryRecord(
id: action.companyGatewayId,
entityType: EntityType.companyGateway))),
TypedReducer<BuiltList<HistoryRecord>, EditCompanyGateway>(
(historyList, action) => _addToHistory(
historyList,
HistoryRecord(
id: action.companyGateway.id,
entityType: EntityType.companyGateway))),
TypedReducer<BuiltList<HistoryRecord>, ViewUser>((historyList, action) =>
_addToHistory(historyList,
HistoryRecord(id: action.userId, entityType: EntityType.user))),
TypedReducer<BuiltList<HistoryRecord>, EditUser>((historyList, action) =>
_addToHistory(historyList,
HistoryRecord(id: action.user.id, entityType: EntityType.user))),
TypedReducer<BuiltList<HistoryRecord>, ViewGroup>((historyList, action) =>
_addToHistory(historyList,
HistoryRecord(id: action.groupId, entityType: EntityType.group))),
TypedReducer<BuiltList<HistoryRecord>, EditGroup>((historyList, action) =>
_addToHistory(historyList,
HistoryRecord(id: action.group.id, entityType: EntityType.group))),
// TODO add to starter.sh
]);
BuiltList<HistoryRecord> _addToHistory(
BuiltList<HistoryRecord> 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)));
}
}

View File

@ -47,7 +47,8 @@ import 'package:invoiceninja_flutter/redux/group/group_reducer.dart';
UIState uiReducer(UIState state, dynamic action) { UIState uiReducer(UIState state, dynamic action) {
final currentRoute = currentRouteReducer(state.currentRoute, action); final currentRoute = currentRouteReducer(state.currentRoute, action);
return state.rebuild((b) => b return state.rebuild((b) => b
..prefState.replace(prefReducer(state.prefState, action)) ..prefState.replace(
prefReducer(state.prefState, action, state.selectedCompanyIndex))
..filter = filterReducer(state.filter, action) ..filter = filterReducer(state.filter, action)
..filterClearedAt = filterClearedAtReducer(state.filterClearedAt, action) ..filterClearedAt = filterClearedAtReducer(state.filterClearedAt, action)
..selectedCompanyIndex = ..selectedCompanyIndex =
@ -76,8 +77,8 @@ UIState uiReducer(UIState state, dynamic action) {
..projectUIState.replace(projectUIReducer(state.projectUIState, action)) ..projectUIState.replace(projectUIReducer(state.projectUIState, action))
..paymentUIState.replace(paymentUIReducer(state.paymentUIState, action)) ..paymentUIState.replace(paymentUIReducer(state.paymentUIState, action))
..quoteUIState.replace(quoteUIReducer(state.quoteUIState, action)) ..quoteUIState.replace(quoteUIReducer(state.quoteUIState, action))
..settingsUIState.replace(settingsUIReducer(state.settingsUIState, action)) ..settingsUIState
); .replace(settingsUIReducer(state.settingsUIState, action)));
} }
Reducer<BuiltList<HistoryRecord>> historyReducer = combineReducers([ Reducer<BuiltList<HistoryRecord>> historyReducer = combineReducers([

View File

@ -100,11 +100,8 @@ class _FormColorPickerState extends State<FormColorPicker> {
FlatButton( FlatButton(
child: Text(localization.done.toUpperCase()), child: Text(localization.done.toUpperCase()),
onPressed: () { onPressed: () {
widget.onSelected(_pendingColor); _selectColor(_pendingColor);
_textController.text = _pendingColor; _textController.text = _pendingColor;
setState(() {
_selectedColor = _pendingColor;
});
Navigator.of(context).pop(); Navigator.of(context).pop();
}, },
), ),

View File

@ -26,6 +26,7 @@ class SaveCancelButtons extends StatelessWidget {
return FlatButton( return FlatButton(
child: Text( child: Text(
localization.cancel, localization.cancel,
style: TextStyle(color: Colors.white),
), ),
onPressed: () => onCancelPressed(context), onPressed: () => onCancelPressed(context),
); );

View File

@ -77,9 +77,13 @@ class HistoryDrawer extends StatelessWidget {
) )
else else
FlatButton( FlatButton(
child: Text(localization.close), child: Text(
localization.close,
style: TextStyle(color: Colors.white),
),
onPressed: () { onPressed: () {
store.dispatch(UserSettingsChanged(sidebar: AppSidebar.history)); store.dispatch(
UserSettingsChanged(sidebar: AppSidebar.history));
}, },
) )
], ],