diff --git a/lib/redux/expense/expense_selectors.dart b/lib/redux/expense/expense_selectors.dart index bb0d4ac6c..821633f35 100644 --- a/lib/redux/expense/expense_selectors.dart +++ b/lib/redux/expense/expense_selectors.dart @@ -111,11 +111,13 @@ List filteredExpensesSelector( return list; } -String expenseStatsForVendor( +var memoizedExpenseStatsForVendor = memo2((String vendorId, + BuiltMap expenseMap) => + expenseStatsForVendor(vendorId, expenseMap)); + +EntityStats expenseStatsForVendor( String vendorId, - BuiltMap expenseMap, - String activeLabel, - String archivedLabel) { + BuiltMap expenseMap) { int countActive = 0; int countArchived = 0; expenseMap.forEach((expenseId, expense) { @@ -128,31 +130,16 @@ String expenseStatsForVendor( } }); - String str = ''; - if (countActive > 0) { - str = '$countActive $activeLabel'; - if (countArchived > 0) { - str += ' • '; - } - } - if (countArchived > 0) { - str += '$countArchived $archivedLabel'; - } - - return str; + return EntityStats(countActive: countActive, countArchived: countArchived); } -var memoizedExpenseStatsForClient = memo4((String clientId, - BuiltMap expenseMap, - String activeLabel, - String archivedLabel) => - expenseStatsForClient(clientId, expenseMap, activeLabel, archivedLabel)); +var memoizedExpenseStatsForClient = memo2((String clientId, + BuiltMap expenseMap) => + expenseStatsForClient(clientId, expenseMap)); -String expenseStatsForClient( +EntityStats expenseStatsForClient( String clientId, - BuiltMap expenseMap, - String activeLabel, - String archivedLabel) { + BuiltMap expenseMap) { int countActive = 0; int countArchived = 0; expenseMap.forEach((expenseId, expense) { @@ -165,26 +152,9 @@ String expenseStatsForClient( } }); - String str = ''; - if (countActive > 0) { - str = '$countActive $activeLabel'; - if (countArchived > 0) { - str += ' • '; - } - } - if (countArchived > 0) { - str += '$countArchived $archivedLabel'; - } - - return str; + return EntityStats(countActive: countActive, countArchived: countArchived); } -var memoizedExpenseStatsForVendor = memo4((String vendorId, - BuiltMap expenseMap, - String activeLabel, - String archivedLabel) => - expenseStatsForVendor(vendorId, expenseMap, activeLabel, archivedLabel)); - var memoizedClientExpenseList = memo2( (BuiltMap expenseMap, String clientId) => clientExpenseList(expenseMap, clientId)); diff --git a/lib/redux/group/group_selectors.dart b/lib/redux/group/group_selectors.dart index 4b4bc506e..33b1d5726 100644 --- a/lib/redux/group/group_selectors.dart +++ b/lib/redux/group/group_selectors.dart @@ -1,4 +1,5 @@ import 'package:invoiceninja_flutter/data/models/client_model.dart'; +import 'package:invoiceninja_flutter/data/models/entities.dart'; import 'package:invoiceninja_flutter/data/models/group_model.dart'; import 'package:memoize/memoize.dart'; import 'package:built_collection/built_collection.dart'; @@ -62,13 +63,12 @@ List filteredGroupsSelector(BuiltMap groupMap, return list; } -var memoizedClientStatsForGroup = memo4( - (BuiltMap clientMap, String groupId, - String activeLabel, String archivedLabel) => - clientStatsForGroup(clientMap, groupId, activeLabel, archivedLabel)); +var memoizedClientStatsForGroup = memo2( + (BuiltMap clientMap, String groupId) => + clientStatsForGroup(clientMap, groupId)); -String clientStatsForGroup(BuiltMap clientMap, - String groupId, String activeLabel, String archivedLabel) { +EntityStats clientStatsForGroup(BuiltMap clientMap, + String groupId) { int countActive = 0; int countArchived = 0; clientMap.forEach((clientId, client) { @@ -81,18 +81,7 @@ String clientStatsForGroup(BuiltMap clientMap, } }); - String str = ''; - if (countActive > 0) { - str = '$countActive $activeLabel'; - if (countArchived > 0) { - str += ' • '; - } - } - if (countArchived > 0) { - str += '$countArchived $archivedLabel'; - } - - return str; + return EntityStats(countActive: countActive, countArchived: countArchived); } bool hasGroupChanges( diff --git a/lib/redux/invoice/invoice_selectors.dart b/lib/redux/invoice/invoice_selectors.dart index 59220ba0e..eed60ad2b 100644 --- a/lib/redux/invoice/invoice_selectors.dart +++ b/lib/redux/invoice/invoice_selectors.dart @@ -106,17 +106,13 @@ List filteredInvoicesSelector( return list; } -var memoizedInvoiceStatsForClient = memo4((String clientId, - BuiltMap invoiceMap, - String activeLabel, - String archivedLabel) => - invoiceStatsForClient(clientId, invoiceMap, activeLabel, archivedLabel)); +var memoizedInvoiceStatsForClient = memo2((String clientId, + BuiltMap invoiceMap) => + invoiceStatsForClient(clientId, invoiceMap)); -String invoiceStatsForClient( +EntityStats invoiceStatsForClient( String clientId, - BuiltMap invoiceMap, - String activeLabel, - String archivedLabel) { + BuiltMap invoiceMap) { int countActive = 0; int countArchived = 0; invoiceMap.forEach((invoiceId, invoice) { @@ -129,31 +125,16 @@ String invoiceStatsForClient( } }); - String str = ''; - if (countActive > 0) { - str = '$countActive $activeLabel'; - if (countArchived > 0) { - str += ' • '; - } - } - if (countArchived > 0) { - str += '$countArchived $archivedLabel'; - } - - return str; + return EntityStats(countActive: countActive, countArchived: countArchived); } -var memoizedInvoiceStatsForUser = memo4((String userId, - BuiltMap invoiceMap, - String activeLabel, - String archivedLabel) => - invoiceStatsForUser(userId, invoiceMap, activeLabel, archivedLabel)); +var memoizedInvoiceStatsForUser = memo2((String userId, + BuiltMap invoiceMap) => + invoiceStatsForUser(userId, invoiceMap)); -String invoiceStatsForUser( +EntityStats invoiceStatsForUser( String userId, - BuiltMap invoiceMap, - String activeLabel, - String archivedLabel) { + BuiltMap invoiceMap) { int countActive = 0; int countArchived = 0; invoiceMap.forEach((invoiceId, invoice) { @@ -166,18 +147,7 @@ String invoiceStatsForUser( } }); - String str = ''; - if (countActive > 0) { - str = '$countActive $activeLabel'; - if (countArchived > 0) { - str += ' • '; - } - } - if (countArchived > 0) { - str += '$countArchived $archivedLabel'; - } - - return str; + return EntityStats(countActive: countActive, countArchived: countArchived); } bool hasInvoiceChanges( diff --git a/lib/redux/payment/payment_selectors.dart b/lib/redux/payment/payment_selectors.dart index 5a2ffe6bd..3b3728fca 100644 --- a/lib/redux/payment/payment_selectors.dart +++ b/lib/redux/payment/payment_selectors.dart @@ -100,20 +100,16 @@ List filteredPaymentsSelector( return list; } -var memoizedPaymentStatsForClient = memo5((String clientId, +var memoizedPaymentStatsForClient = memo3((String clientId, BuiltMap paymentMap, - BuiltMap invoiceMap, - String activeLabel, - String archivedLabel) => + BuiltMap invoiceMap) => paymentStatsForClient( - clientId, paymentMap, invoiceMap, activeLabel, archivedLabel)); + clientId, paymentMap, invoiceMap)); -String paymentStatsForClient( +EntityStats paymentStatsForClient( String clientId, BuiltMap paymentMap, - BuiltMap invoiceMap, - String activeLabel, - String archivedLabel) { + BuiltMap invoiceMap) { int countActive = 0; int countArchived = 0; paymentMap.forEach((paymentId, payment) { @@ -127,34 +123,19 @@ String paymentStatsForClient( } }); - String str = ''; - if (countActive > 0) { - str = '$countActive $activeLabel'; - if (countArchived > 0) { - str += ' • '; - } - } - if (countArchived > 0) { - str += '$countArchived $archivedLabel'; - } - - return str; + return EntityStats(countActive: countActive, countArchived: countArchived); } -var memoizedPaymentStatsForUser = memo5((String userId, +var memoizedPaymentStatsForUser = memo3((String userId, BuiltMap paymentMap, - BuiltMap invoiceMap, - String activeLabel, - String archivedLabel) => + BuiltMap invoiceMap) => paymentStatsForClient( - userId, paymentMap, invoiceMap, activeLabel, archivedLabel)); + userId, paymentMap, invoiceMap)); -String paymentStatsForUser( +EntityStats paymentStatsForUser( String userId, BuiltMap paymentMap, - BuiltMap invoiceMap, - String activeLabel, - String archivedLabel) { + BuiltMap invoiceMap) { int countActive = 0; int countArchived = 0; paymentMap.forEach((paymentId, payment) { @@ -167,18 +148,7 @@ String paymentStatsForUser( } }); - String str = ''; - if (countActive > 0) { - str = '$countActive $activeLabel'; - if (countArchived > 0) { - str += ' • '; - } - } - if (countArchived > 0) { - str += '$countArchived $archivedLabel'; - } - - return str; + return EntityStats(countActive: countActive, countArchived: countArchived); } bool hasPaymentChanges( diff --git a/lib/redux/project/project_selectors.dart b/lib/redux/project/project_selectors.dart index e66690251..e9027d762 100644 --- a/lib/redux/project/project_selectors.dart +++ b/lib/redux/project/project_selectors.dart @@ -131,17 +131,13 @@ Duration taskDurationForProject( return Duration(seconds: total); } -var memoizedProjectStatsForClient = memo4((String clientId, - BuiltMap projectMap, - String activeLabel, - String archivedLabel) => - projectStatsForClient(clientId, projectMap, activeLabel, archivedLabel)); +var memoizedProjectStatsForClient = memo2((String clientId, + BuiltMap projectMap) => + projectStatsForClient(clientId, projectMap)); -String projectStatsForClient( +EntityStats projectStatsForClient( String clientId, - BuiltMap projectMap, - String activeLabel, - String archivedLabel) { + BuiltMap projectMap) { int countActive = 0; int countArchived = 0; projectMap.forEach((projectId, project) { @@ -154,18 +150,7 @@ String projectStatsForClient( } }); - String str = ''; - if (countActive > 0) { - str = '$countActive $activeLabel'; - if (countArchived > 0) { - str += ' • '; - } - } - if (countArchived > 0) { - str += '$countArchived $archivedLabel'; - } - - return str; + return EntityStats(countActive: countActive, countArchived: countArchived); } bool hasProjectChanges( diff --git a/lib/redux/quote/quote_selectors.dart b/lib/redux/quote/quote_selectors.dart index 168e5baf0..226de4eeb 100644 --- a/lib/redux/quote/quote_selectors.dart +++ b/lib/redux/quote/quote_selectors.dart @@ -61,17 +61,13 @@ List filteredQuotesSelector( return list; } -var memoizedQuoteStatsForClient = memo4((String clientId, - BuiltMap quoteMap, - String activeLabel, - String archivedLabel) => - quoteStatsForClient(clientId, quoteMap, activeLabel, archivedLabel)); +var memoizedQuoteStatsForClient = memo2((String clientId, + BuiltMap quoteMap) => + quoteStatsForClient(clientId, quoteMap)); -String quoteStatsForClient( +EntityStats quoteStatsForClient( String clientId, - BuiltMap quoteMap, - String activeLabel, - String archivedLabel) { + BuiltMap quoteMap) { int countActive = 0; int countArchived = 0; quoteMap.forEach((quoteId, quote) { @@ -84,18 +80,7 @@ String quoteStatsForClient( } }); - String str = ''; - if (countActive > 0) { - str = '$countActive $activeLabel'; - if (countArchived > 0) { - str += ' • '; - } - } - if (countArchived > 0) { - str += '$countArchived $archivedLabel'; - } - - return str; + return EntityStats(countActive: countActive, countArchived: countArchived); } var memoizedQuoteStatsForUser = memo2((String userId, diff --git a/lib/redux/task/task_selectors.dart b/lib/redux/task/task_selectors.dart index 104b5f5a8..1eb832fbf 100644 --- a/lib/redux/task/task_selectors.dart +++ b/lib/redux/task/task_selectors.dart @@ -155,11 +155,12 @@ double taskRateSelector( return 0; } -var memoizedTaskStatsForClient = memo2((String clientId, - BuiltMap taskMap) => - taskStatsForClient(clientId, taskMap)); +var memoizedTaskStatsForClient = memo2( + (String clientId, BuiltMap taskMap) => + taskStatsForClient(clientId, taskMap)); -EntityStats taskStatsForClient(String clientId, BuiltMap taskMap) { +EntityStats taskStatsForClient( + String clientId, BuiltMap taskMap) { int countActive = 0; int countArchived = 0; taskMap.forEach((taskId, task) { @@ -175,17 +176,14 @@ EntityStats taskStatsForClient(String clientId, BuiltMap tas return EntityStats(countActive: countActive, countArchived: countArchived); } -var memoizedTaskStatsForProject = memo4((String projectId, - BuiltMap taskMap, - String activeLabel, - String archivedLabel) => - taskStatsForProject(projectId, taskMap, activeLabel, archivedLabel)); +var memoizedTaskStatsForProject = memo2(( + String projectId, + BuiltMap taskMap, +) => + taskStatsForProject(projectId, taskMap)); -String taskStatsForProject( - String projectId, - BuiltMap taskMap, - String activeLabel, - String archivedLabel) { +EntityStats taskStatsForProject( + String projectId, BuiltMap taskMap) { int countActive = 0; int countArchived = 0; taskMap.forEach((taskId, task) { @@ -198,18 +196,7 @@ String taskStatsForProject( } }); - String str = ''; - if (countActive > 0) { - str = '$countActive $activeLabel'; - if (countArchived > 0) { - str += ' • '; - } - } - if (countArchived > 0) { - str += '$countArchived $archivedLabel'; - } - - return str; + return EntityStats(countActive: countActive, countArchived: countArchived); } bool hasTaskChanges(TaskEntity task, BuiltMap taskMap) => diff --git a/lib/ui/client/view/client_view_overview.dart b/lib/ui/client/view/client_view_overview.dart index 2b909c3c4..d0233947a 100644 --- a/lib/ui/client/view/client_view_overview.dart +++ b/lib/ui/client/view/client_view_overview.dart @@ -78,11 +78,9 @@ class ClientOverview extends StatelessWidget { onTap: () => viewModel.onEntityPressed(context, EntityType.invoice), onLongPress: () => viewModel.onEntityPressed(context, EntityType.invoice, true), - subtitle: memoizedInvoiceStatsForClient( - client.id, - state.invoiceState.map, - localization.active, - localization.archived), + subtitle: + memoizedInvoiceStatsForClient(client.id, state.invoiceState.map) + .present(localization.active, localization.archived), ), EntityListTile( bottomPadding: 1, @@ -92,11 +90,8 @@ class ClientOverview extends StatelessWidget { onLongPress: () => viewModel.onEntityPressed(context, EntityType.payment, true), subtitle: memoizedPaymentStatsForClient( - client.id, - state.paymentState.map, - state.invoiceState.map, - localization.active, - localization.archived), + client.id, state.paymentState.map, state.invoiceState.map) + .present(localization.active, localization.archived), ), company.isModuleEnabled(EntityType.quote) ? EntityListTile( @@ -107,11 +102,9 @@ class ClientOverview extends StatelessWidget { viewModel.onEntityPressed(context, EntityType.quote), onLongPress: () => viewModel.onEntityPressed(context, EntityType.quote, true), - subtitle: memoizedQuoteStatsForClient( - client.id, - state.quoteState.map, - localization.active, - localization.archived), + subtitle: + memoizedQuoteStatsForClient(client.id, state.quoteState.map) + .present(localization.active, localization.archived), ) : Container(), company.isModuleEnabled(EntityType.project) @@ -125,9 +118,7 @@ class ClientOverview extends StatelessWidget { context, EntityType.project, true), subtitle: memoizedProjectStatsForClient( client.id, - state.projectState.map, - localization.active, - localization.archived), + state.projectState.map).present(localization.active, localization.archived), ) : Container(), company.isModuleEnabled(EntityType.task) @@ -154,10 +145,8 @@ class ClientOverview extends StatelessWidget { onLongPress: () => viewModel.onEntityPressed( context, EntityType.expense, true), subtitle: memoizedExpenseStatsForClient( - client.id, - state.expenseState.map, - localization.active, - localization.archived), + client.id, state.expenseState.map) + .present(localization.active, localization.archived), ) : Container(), ], diff --git a/lib/ui/group/view/group_view.dart b/lib/ui/group/view/group_view.dart index 7c8ddc59e..26ed5ce78 100644 --- a/lib/ui/group/view/group_view.dart +++ b/lib/ui/group/view/group_view.dart @@ -76,8 +76,9 @@ class _GroupViewState extends State { title: localization.clients, onTap: () => viewModel.onClientsPressed(context), onLongPress: () => viewModel.onClientsPressed(context, true), - subtitle: memoizedClientStatsForGroup(state.clientState.map, - group.id, localization.active, localization.archived), + subtitle: + memoizedClientStatsForGroup(state.clientState.map, group.id) + .present(localization.active, localization.archived), ), Container( color: Theme.of(context).backgroundColor, diff --git a/lib/ui/project/view/project_view.dart b/lib/ui/project/view/project_view.dart index 0ebd527ca..ab6c82d80 100644 --- a/lib/ui/project/view/project_view.dart +++ b/lib/ui/project/view/project_view.dart @@ -115,10 +115,8 @@ class _ProjectViewState extends State { onLongPress: () => viewModel.onTasksPressed(context, longPress: true), subtitle: memoizedTaskStatsForProject( - project.id, - viewModel.state.taskState.map, - localization.active, - localization.archived), + project.id, viewModel.state.taskState.map) + .present(localization.active, localization.archived), ), Container( color: Theme.of(context).backgroundColor, diff --git a/lib/ui/user/view/user_view.dart b/lib/ui/user/view/user_view.dart index a93cebb9b..fab4ac655 100644 --- a/lib/ui/user/view/user_view.dart +++ b/lib/ui/user/view/user_view.dart @@ -97,11 +97,9 @@ class UserView extends StatelessWidget { onTap: () => viewModel.onEntityPressed(context, EntityType.invoice), onLongPress: () => viewModel.onEntityPressed(context, EntityType.invoice, true), - subtitle: memoizedInvoiceStatsForUser( - user.id, - state.invoiceState.map, - localization.active, - localization.archived), + subtitle: + memoizedInvoiceStatsForUser(user.id, state.invoiceState.map) + .present(localization.active, localization.archived), ), EntityListTile( bottomPadding: 1, @@ -111,11 +109,8 @@ class UserView extends StatelessWidget { onLongPress: () => viewModel.onEntityPressed(context, EntityType.payment, true), subtitle: memoizedPaymentStatsForUser( - user.id, - state.paymentState.map, - state.invoiceState.map, - localization.active, - localization.archived), + user.id, state.paymentState.map, state.invoiceState.map) + .present(localization.active, localization.archived), ), company.isModuleEnabled(EntityType.quote) ? EntityListTile( diff --git a/lib/ui/vendor/view/vendor_view_overview.dart b/lib/ui/vendor/view/vendor_view_overview.dart index ca09e346d..f6ef17031 100644 --- a/lib/ui/vendor/view/vendor_view_overview.dart +++ b/lib/ui/vendor/view/vendor_view_overview.dart @@ -69,11 +69,9 @@ class VendorOverview extends StatelessWidget { onTap: () => viewModel.onEntityPressed(context, EntityType.expense), onLongPress: () => viewModel.onEntityPressed(context, EntityType.expense, true), - subtitle: memoizedExpenseStatsForVendor( - vendor.id, - state.expenseState.map, - localization.active, - localization.archived), + subtitle: + memoizedExpenseStatsForVendor(vendor.id, state.expenseState.map) + .present(localization.active, localization.archived), ), ], );