This commit is contained in:
Hillel Coren 2019-11-07 21:03:26 +02:00
parent 264551c7eb
commit a034aa644d
12 changed files with 93 additions and 256 deletions

View File

@ -111,11 +111,13 @@ List<String> filteredExpensesSelector(
return list; return list;
} }
String expenseStatsForVendor( var memoizedExpenseStatsForVendor = memo2((String vendorId,
BuiltMap<String, ExpenseEntity> expenseMap) =>
expenseStatsForVendor(vendorId, expenseMap));
EntityStats expenseStatsForVendor(
String vendorId, String vendorId,
BuiltMap<String, ExpenseEntity> expenseMap, BuiltMap<String, ExpenseEntity> expenseMap) {
String activeLabel,
String archivedLabel) {
int countActive = 0; int countActive = 0;
int countArchived = 0; int countArchived = 0;
expenseMap.forEach((expenseId, expense) { expenseMap.forEach((expenseId, expense) {
@ -128,31 +130,16 @@ String expenseStatsForVendor(
} }
}); });
String str = ''; return EntityStats(countActive: countActive, countArchived: countArchived);
if (countActive > 0) {
str = '$countActive $activeLabel';
if (countArchived > 0) {
str += '';
}
}
if (countArchived > 0) {
str += '$countArchived $archivedLabel';
}
return str;
} }
var memoizedExpenseStatsForClient = memo4((String clientId, var memoizedExpenseStatsForClient = memo2((String clientId,
BuiltMap<String, ExpenseEntity> expenseMap, BuiltMap<String, ExpenseEntity> expenseMap) =>
String activeLabel, expenseStatsForClient(clientId, expenseMap));
String archivedLabel) =>
expenseStatsForClient(clientId, expenseMap, activeLabel, archivedLabel));
String expenseStatsForClient( EntityStats expenseStatsForClient(
String clientId, String clientId,
BuiltMap<String, ExpenseEntity> expenseMap, BuiltMap<String, ExpenseEntity> expenseMap) {
String activeLabel,
String archivedLabel) {
int countActive = 0; int countActive = 0;
int countArchived = 0; int countArchived = 0;
expenseMap.forEach((expenseId, expense) { expenseMap.forEach((expenseId, expense) {
@ -165,26 +152,9 @@ String expenseStatsForClient(
} }
}); });
String str = ''; return EntityStats(countActive: countActive, countArchived: countArchived);
if (countActive > 0) {
str = '$countActive $activeLabel';
if (countArchived > 0) {
str += '';
}
}
if (countArchived > 0) {
str += '$countArchived $archivedLabel';
}
return str;
} }
var memoizedExpenseStatsForVendor = memo4((String vendorId,
BuiltMap<String, ExpenseEntity> expenseMap,
String activeLabel,
String archivedLabel) =>
expenseStatsForVendor(vendorId, expenseMap, activeLabel, archivedLabel));
var memoizedClientExpenseList = memo2( var memoizedClientExpenseList = memo2(
(BuiltMap<String, ExpenseEntity> expenseMap, String clientId) => (BuiltMap<String, ExpenseEntity> expenseMap, String clientId) =>
clientExpenseList(expenseMap, clientId)); clientExpenseList(expenseMap, clientId));

View File

@ -1,4 +1,5 @@
import 'package:invoiceninja_flutter/data/models/client_model.dart'; 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:invoiceninja_flutter/data/models/group_model.dart';
import 'package:memoize/memoize.dart'; import 'package:memoize/memoize.dart';
import 'package:built_collection/built_collection.dart'; import 'package:built_collection/built_collection.dart';
@ -62,13 +63,12 @@ List<String> filteredGroupsSelector(BuiltMap<String, GroupEntity> groupMap,
return list; return list;
} }
var memoizedClientStatsForGroup = memo4( var memoizedClientStatsForGroup = memo2(
(BuiltMap<String, ClientEntity> clientMap, String groupId, (BuiltMap<String, ClientEntity> clientMap, String groupId) =>
String activeLabel, String archivedLabel) => clientStatsForGroup(clientMap, groupId));
clientStatsForGroup(clientMap, groupId, activeLabel, archivedLabel));
String clientStatsForGroup(BuiltMap<String, ClientEntity> clientMap, EntityStats clientStatsForGroup(BuiltMap<String, ClientEntity> clientMap,
String groupId, String activeLabel, String archivedLabel) { String groupId) {
int countActive = 0; int countActive = 0;
int countArchived = 0; int countArchived = 0;
clientMap.forEach((clientId, client) { clientMap.forEach((clientId, client) {
@ -81,18 +81,7 @@ String clientStatsForGroup(BuiltMap<String, ClientEntity> clientMap,
} }
}); });
String str = ''; return EntityStats(countActive: countActive, countArchived: countArchived);
if (countActive > 0) {
str = '$countActive $activeLabel';
if (countArchived > 0) {
str += '';
}
}
if (countArchived > 0) {
str += '$countArchived $archivedLabel';
}
return str;
} }
bool hasGroupChanges( bool hasGroupChanges(

View File

@ -106,17 +106,13 @@ List<String> filteredInvoicesSelector(
return list; return list;
} }
var memoizedInvoiceStatsForClient = memo4((String clientId, var memoizedInvoiceStatsForClient = memo2((String clientId,
BuiltMap<String, InvoiceEntity> invoiceMap, BuiltMap<String, InvoiceEntity> invoiceMap) =>
String activeLabel, invoiceStatsForClient(clientId, invoiceMap));
String archivedLabel) =>
invoiceStatsForClient(clientId, invoiceMap, activeLabel, archivedLabel));
String invoiceStatsForClient( EntityStats invoiceStatsForClient(
String clientId, String clientId,
BuiltMap<String, InvoiceEntity> invoiceMap, BuiltMap<String, InvoiceEntity> invoiceMap) {
String activeLabel,
String archivedLabel) {
int countActive = 0; int countActive = 0;
int countArchived = 0; int countArchived = 0;
invoiceMap.forEach((invoiceId, invoice) { invoiceMap.forEach((invoiceId, invoice) {
@ -129,31 +125,16 @@ String invoiceStatsForClient(
} }
}); });
String str = ''; return EntityStats(countActive: countActive, countArchived: countArchived);
if (countActive > 0) {
str = '$countActive $activeLabel';
if (countArchived > 0) {
str += '';
}
}
if (countArchived > 0) {
str += '$countArchived $archivedLabel';
}
return str;
} }
var memoizedInvoiceStatsForUser = memo4((String userId, var memoizedInvoiceStatsForUser = memo2((String userId,
BuiltMap<String, InvoiceEntity> invoiceMap, BuiltMap<String, InvoiceEntity> invoiceMap) =>
String activeLabel, invoiceStatsForUser(userId, invoiceMap));
String archivedLabel) =>
invoiceStatsForUser(userId, invoiceMap, activeLabel, archivedLabel));
String invoiceStatsForUser( EntityStats invoiceStatsForUser(
String userId, String userId,
BuiltMap<String, InvoiceEntity> invoiceMap, BuiltMap<String, InvoiceEntity> invoiceMap) {
String activeLabel,
String archivedLabel) {
int countActive = 0; int countActive = 0;
int countArchived = 0; int countArchived = 0;
invoiceMap.forEach((invoiceId, invoice) { invoiceMap.forEach((invoiceId, invoice) {
@ -166,18 +147,7 @@ String invoiceStatsForUser(
} }
}); });
String str = ''; return EntityStats(countActive: countActive, countArchived: countArchived);
if (countActive > 0) {
str = '$countActive $activeLabel';
if (countArchived > 0) {
str += '';
}
}
if (countArchived > 0) {
str += '$countArchived $archivedLabel';
}
return str;
} }
bool hasInvoiceChanges( bool hasInvoiceChanges(

View File

@ -100,20 +100,16 @@ List<String> filteredPaymentsSelector(
return list; return list;
} }
var memoizedPaymentStatsForClient = memo5((String clientId, var memoizedPaymentStatsForClient = memo3((String clientId,
BuiltMap<String, PaymentEntity> paymentMap, BuiltMap<String, PaymentEntity> paymentMap,
BuiltMap<String, InvoiceEntity> invoiceMap, BuiltMap<String, InvoiceEntity> invoiceMap) =>
String activeLabel,
String archivedLabel) =>
paymentStatsForClient( paymentStatsForClient(
clientId, paymentMap, invoiceMap, activeLabel, archivedLabel)); clientId, paymentMap, invoiceMap));
String paymentStatsForClient( EntityStats paymentStatsForClient(
String clientId, String clientId,
BuiltMap<String, PaymentEntity> paymentMap, BuiltMap<String, PaymentEntity> paymentMap,
BuiltMap<String, InvoiceEntity> invoiceMap, BuiltMap<String, InvoiceEntity> invoiceMap) {
String activeLabel,
String archivedLabel) {
int countActive = 0; int countActive = 0;
int countArchived = 0; int countArchived = 0;
paymentMap.forEach((paymentId, payment) { paymentMap.forEach((paymentId, payment) {
@ -127,34 +123,19 @@ String paymentStatsForClient(
} }
}); });
String str = ''; return EntityStats(countActive: countActive, countArchived: countArchived);
if (countActive > 0) {
str = '$countActive $activeLabel';
if (countArchived > 0) {
str += '';
}
}
if (countArchived > 0) {
str += '$countArchived $archivedLabel';
}
return str;
} }
var memoizedPaymentStatsForUser = memo5((String userId, var memoizedPaymentStatsForUser = memo3((String userId,
BuiltMap<String, PaymentEntity> paymentMap, BuiltMap<String, PaymentEntity> paymentMap,
BuiltMap<String, InvoiceEntity> invoiceMap, BuiltMap<String, InvoiceEntity> invoiceMap) =>
String activeLabel,
String archivedLabel) =>
paymentStatsForClient( paymentStatsForClient(
userId, paymentMap, invoiceMap, activeLabel, archivedLabel)); userId, paymentMap, invoiceMap));
String paymentStatsForUser( EntityStats paymentStatsForUser(
String userId, String userId,
BuiltMap<String, PaymentEntity> paymentMap, BuiltMap<String, PaymentEntity> paymentMap,
BuiltMap<String, InvoiceEntity> invoiceMap, BuiltMap<String, InvoiceEntity> invoiceMap) {
String activeLabel,
String archivedLabel) {
int countActive = 0; int countActive = 0;
int countArchived = 0; int countArchived = 0;
paymentMap.forEach((paymentId, payment) { paymentMap.forEach((paymentId, payment) {
@ -167,18 +148,7 @@ String paymentStatsForUser(
} }
}); });
String str = ''; return EntityStats(countActive: countActive, countArchived: countArchived);
if (countActive > 0) {
str = '$countActive $activeLabel';
if (countArchived > 0) {
str += '';
}
}
if (countArchived > 0) {
str += '$countArchived $archivedLabel';
}
return str;
} }
bool hasPaymentChanges( bool hasPaymentChanges(

View File

@ -131,17 +131,13 @@ Duration taskDurationForProject(
return Duration(seconds: total); return Duration(seconds: total);
} }
var memoizedProjectStatsForClient = memo4((String clientId, var memoizedProjectStatsForClient = memo2((String clientId,
BuiltMap<String, ProjectEntity> projectMap, BuiltMap<String, ProjectEntity> projectMap) =>
String activeLabel, projectStatsForClient(clientId, projectMap));
String archivedLabel) =>
projectStatsForClient(clientId, projectMap, activeLabel, archivedLabel));
String projectStatsForClient( EntityStats projectStatsForClient(
String clientId, String clientId,
BuiltMap<String, ProjectEntity> projectMap, BuiltMap<String, ProjectEntity> projectMap) {
String activeLabel,
String archivedLabel) {
int countActive = 0; int countActive = 0;
int countArchived = 0; int countArchived = 0;
projectMap.forEach((projectId, project) { projectMap.forEach((projectId, project) {
@ -154,18 +150,7 @@ String projectStatsForClient(
} }
}); });
String str = ''; return EntityStats(countActive: countActive, countArchived: countArchived);
if (countActive > 0) {
str = '$countActive $activeLabel';
if (countArchived > 0) {
str += '';
}
}
if (countArchived > 0) {
str += '$countArchived $archivedLabel';
}
return str;
} }
bool hasProjectChanges( bool hasProjectChanges(

View File

@ -61,17 +61,13 @@ List<String> filteredQuotesSelector(
return list; return list;
} }
var memoizedQuoteStatsForClient = memo4((String clientId, var memoizedQuoteStatsForClient = memo2((String clientId,
BuiltMap<String, InvoiceEntity> quoteMap, BuiltMap<String, InvoiceEntity> quoteMap) =>
String activeLabel, quoteStatsForClient(clientId, quoteMap));
String archivedLabel) =>
quoteStatsForClient(clientId, quoteMap, activeLabel, archivedLabel));
String quoteStatsForClient( EntityStats quoteStatsForClient(
String clientId, String clientId,
BuiltMap<String, InvoiceEntity> quoteMap, BuiltMap<String, InvoiceEntity> quoteMap) {
String activeLabel,
String archivedLabel) {
int countActive = 0; int countActive = 0;
int countArchived = 0; int countArchived = 0;
quoteMap.forEach((quoteId, quote) { quoteMap.forEach((quoteId, quote) {
@ -84,18 +80,7 @@ String quoteStatsForClient(
} }
}); });
String str = ''; return EntityStats(countActive: countActive, countArchived: countArchived);
if (countActive > 0) {
str = '$countActive $activeLabel';
if (countArchived > 0) {
str += '';
}
}
if (countArchived > 0) {
str += '$countArchived $archivedLabel';
}
return str;
} }
var memoizedQuoteStatsForUser = memo2((String userId, var memoizedQuoteStatsForUser = memo2((String userId,

View File

@ -155,11 +155,12 @@ double taskRateSelector(
return 0; return 0;
} }
var memoizedTaskStatsForClient = memo2((String clientId, var memoizedTaskStatsForClient = memo2(
BuiltMap<String, TaskEntity> taskMap) => (String clientId, BuiltMap<String, TaskEntity> taskMap) =>
taskStatsForClient(clientId, taskMap)); taskStatsForClient(clientId, taskMap));
EntityStats taskStatsForClient(String clientId, BuiltMap<String, TaskEntity> taskMap) { EntityStats taskStatsForClient(
String clientId, BuiltMap<String, TaskEntity> taskMap) {
int countActive = 0; int countActive = 0;
int countArchived = 0; int countArchived = 0;
taskMap.forEach((taskId, task) { taskMap.forEach((taskId, task) {
@ -175,17 +176,14 @@ EntityStats taskStatsForClient(String clientId, BuiltMap<String, TaskEntity> tas
return EntityStats(countActive: countActive, countArchived: countArchived); return EntityStats(countActive: countActive, countArchived: countArchived);
} }
var memoizedTaskStatsForProject = memo4((String projectId, var memoizedTaskStatsForProject = memo2((
BuiltMap<String, TaskEntity> taskMap,
String activeLabel,
String archivedLabel) =>
taskStatsForProject(projectId, taskMap, activeLabel, archivedLabel));
String taskStatsForProject(
String projectId, String projectId,
BuiltMap<String, TaskEntity> taskMap, BuiltMap<String, TaskEntity> taskMap,
String activeLabel, ) =>
String archivedLabel) { taskStatsForProject(projectId, taskMap));
EntityStats taskStatsForProject(
String projectId, BuiltMap<String, TaskEntity> taskMap) {
int countActive = 0; int countActive = 0;
int countArchived = 0; int countArchived = 0;
taskMap.forEach((taskId, task) { taskMap.forEach((taskId, task) {
@ -198,18 +196,7 @@ String taskStatsForProject(
} }
}); });
String str = ''; return EntityStats(countActive: countActive, countArchived: countArchived);
if (countActive > 0) {
str = '$countActive $activeLabel';
if (countArchived > 0) {
str += '';
}
}
if (countArchived > 0) {
str += '$countArchived $archivedLabel';
}
return str;
} }
bool hasTaskChanges(TaskEntity task, BuiltMap<String, TaskEntity> taskMap) => bool hasTaskChanges(TaskEntity task, BuiltMap<String, TaskEntity> taskMap) =>

View File

@ -78,11 +78,9 @@ class ClientOverview extends StatelessWidget {
onTap: () => viewModel.onEntityPressed(context, EntityType.invoice), onTap: () => viewModel.onEntityPressed(context, EntityType.invoice),
onLongPress: () => onLongPress: () =>
viewModel.onEntityPressed(context, EntityType.invoice, true), viewModel.onEntityPressed(context, EntityType.invoice, true),
subtitle: memoizedInvoiceStatsForClient( subtitle:
client.id, memoizedInvoiceStatsForClient(client.id, state.invoiceState.map)
state.invoiceState.map, .present(localization.active, localization.archived),
localization.active,
localization.archived),
), ),
EntityListTile( EntityListTile(
bottomPadding: 1, bottomPadding: 1,
@ -92,11 +90,8 @@ class ClientOverview extends StatelessWidget {
onLongPress: () => onLongPress: () =>
viewModel.onEntityPressed(context, EntityType.payment, true), viewModel.onEntityPressed(context, EntityType.payment, true),
subtitle: memoizedPaymentStatsForClient( subtitle: memoizedPaymentStatsForClient(
client.id, client.id, state.paymentState.map, state.invoiceState.map)
state.paymentState.map, .present(localization.active, localization.archived),
state.invoiceState.map,
localization.active,
localization.archived),
), ),
company.isModuleEnabled(EntityType.quote) company.isModuleEnabled(EntityType.quote)
? EntityListTile( ? EntityListTile(
@ -107,11 +102,9 @@ class ClientOverview extends StatelessWidget {
viewModel.onEntityPressed(context, EntityType.quote), viewModel.onEntityPressed(context, EntityType.quote),
onLongPress: () => onLongPress: () =>
viewModel.onEntityPressed(context, EntityType.quote, true), viewModel.onEntityPressed(context, EntityType.quote, true),
subtitle: memoizedQuoteStatsForClient( subtitle:
client.id, memoizedQuoteStatsForClient(client.id, state.quoteState.map)
state.quoteState.map, .present(localization.active, localization.archived),
localization.active,
localization.archived),
) )
: Container(), : Container(),
company.isModuleEnabled(EntityType.project) company.isModuleEnabled(EntityType.project)
@ -125,9 +118,7 @@ class ClientOverview extends StatelessWidget {
context, EntityType.project, true), context, EntityType.project, true),
subtitle: memoizedProjectStatsForClient( subtitle: memoizedProjectStatsForClient(
client.id, client.id,
state.projectState.map, state.projectState.map).present(localization.active, localization.archived),
localization.active,
localization.archived),
) )
: Container(), : Container(),
company.isModuleEnabled(EntityType.task) company.isModuleEnabled(EntityType.task)
@ -154,10 +145,8 @@ class ClientOverview extends StatelessWidget {
onLongPress: () => viewModel.onEntityPressed( onLongPress: () => viewModel.onEntityPressed(
context, EntityType.expense, true), context, EntityType.expense, true),
subtitle: memoizedExpenseStatsForClient( subtitle: memoizedExpenseStatsForClient(
client.id, client.id, state.expenseState.map)
state.expenseState.map, .present(localization.active, localization.archived),
localization.active,
localization.archived),
) )
: Container(), : Container(),
], ],

View File

@ -76,8 +76,9 @@ class _GroupViewState extends State<GroupView> {
title: localization.clients, title: localization.clients,
onTap: () => viewModel.onClientsPressed(context), onTap: () => viewModel.onClientsPressed(context),
onLongPress: () => viewModel.onClientsPressed(context, true), onLongPress: () => viewModel.onClientsPressed(context, true),
subtitle: memoizedClientStatsForGroup(state.clientState.map, subtitle:
group.id, localization.active, localization.archived), memoizedClientStatsForGroup(state.clientState.map, group.id)
.present(localization.active, localization.archived),
), ),
Container( Container(
color: Theme.of(context).backgroundColor, color: Theme.of(context).backgroundColor,

View File

@ -115,10 +115,8 @@ class _ProjectViewState extends State<ProjectView> {
onLongPress: () => onLongPress: () =>
viewModel.onTasksPressed(context, longPress: true), viewModel.onTasksPressed(context, longPress: true),
subtitle: memoizedTaskStatsForProject( subtitle: memoizedTaskStatsForProject(
project.id, project.id, viewModel.state.taskState.map)
viewModel.state.taskState.map, .present(localization.active, localization.archived),
localization.active,
localization.archived),
), ),
Container( Container(
color: Theme.of(context).backgroundColor, color: Theme.of(context).backgroundColor,

View File

@ -97,11 +97,9 @@ class UserView extends StatelessWidget {
onTap: () => viewModel.onEntityPressed(context, EntityType.invoice), onTap: () => viewModel.onEntityPressed(context, EntityType.invoice),
onLongPress: () => onLongPress: () =>
viewModel.onEntityPressed(context, EntityType.invoice, true), viewModel.onEntityPressed(context, EntityType.invoice, true),
subtitle: memoizedInvoiceStatsForUser( subtitle:
user.id, memoizedInvoiceStatsForUser(user.id, state.invoiceState.map)
state.invoiceState.map, .present(localization.active, localization.archived),
localization.active,
localization.archived),
), ),
EntityListTile( EntityListTile(
bottomPadding: 1, bottomPadding: 1,
@ -111,11 +109,8 @@ class UserView extends StatelessWidget {
onLongPress: () => onLongPress: () =>
viewModel.onEntityPressed(context, EntityType.payment, true), viewModel.onEntityPressed(context, EntityType.payment, true),
subtitle: memoizedPaymentStatsForUser( subtitle: memoizedPaymentStatsForUser(
user.id, user.id, state.paymentState.map, state.invoiceState.map)
state.paymentState.map, .present(localization.active, localization.archived),
state.invoiceState.map,
localization.active,
localization.archived),
), ),
company.isModuleEnabled(EntityType.quote) company.isModuleEnabled(EntityType.quote)
? EntityListTile( ? EntityListTile(

View File

@ -69,11 +69,9 @@ class VendorOverview extends StatelessWidget {
onTap: () => viewModel.onEntityPressed(context, EntityType.expense), onTap: () => viewModel.onEntityPressed(context, EntityType.expense),
onLongPress: () => onLongPress: () =>
viewModel.onEntityPressed(context, EntityType.expense, true), viewModel.onEntityPressed(context, EntityType.expense, true),
subtitle: memoizedExpenseStatsForVendor( subtitle:
vendor.id, memoizedExpenseStatsForVendor(vendor.id, state.expenseState.map)
state.expenseState.map, .present(localization.active, localization.archived),
localization.active,
localization.archived),
), ),
], ],
); );