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;
}
String expenseStatsForVendor(
var memoizedExpenseStatsForVendor = memo2((String vendorId,
BuiltMap<String, ExpenseEntity> expenseMap) =>
expenseStatsForVendor(vendorId, expenseMap));
EntityStats expenseStatsForVendor(
String vendorId,
BuiltMap<String, ExpenseEntity> expenseMap,
String activeLabel,
String archivedLabel) {
BuiltMap<String, ExpenseEntity> 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<String, ExpenseEntity> expenseMap,
String activeLabel,
String archivedLabel) =>
expenseStatsForClient(clientId, expenseMap, activeLabel, archivedLabel));
var memoizedExpenseStatsForClient = memo2((String clientId,
BuiltMap<String, ExpenseEntity> expenseMap) =>
expenseStatsForClient(clientId, expenseMap));
String expenseStatsForClient(
EntityStats expenseStatsForClient(
String clientId,
BuiltMap<String, ExpenseEntity> expenseMap,
String activeLabel,
String archivedLabel) {
BuiltMap<String, ExpenseEntity> 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<String, ExpenseEntity> expenseMap,
String activeLabel,
String archivedLabel) =>
expenseStatsForVendor(vendorId, expenseMap, activeLabel, archivedLabel));
var memoizedClientExpenseList = memo2(
(BuiltMap<String, ExpenseEntity> expenseMap, String 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/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<String> filteredGroupsSelector(BuiltMap<String, GroupEntity> groupMap,
return list;
}
var memoizedClientStatsForGroup = memo4(
(BuiltMap<String, ClientEntity> clientMap, String groupId,
String activeLabel, String archivedLabel) =>
clientStatsForGroup(clientMap, groupId, activeLabel, archivedLabel));
var memoizedClientStatsForGroup = memo2(
(BuiltMap<String, ClientEntity> clientMap, String groupId) =>
clientStatsForGroup(clientMap, groupId));
String clientStatsForGroup(BuiltMap<String, ClientEntity> clientMap,
String groupId, String activeLabel, String archivedLabel) {
EntityStats clientStatsForGroup(BuiltMap<String, ClientEntity> clientMap,
String groupId) {
int countActive = 0;
int countArchived = 0;
clientMap.forEach((clientId, client) {
@ -81,18 +81,7 @@ String clientStatsForGroup(BuiltMap<String, ClientEntity> 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(

View File

@ -106,17 +106,13 @@ List<String> filteredInvoicesSelector(
return list;
}
var memoizedInvoiceStatsForClient = memo4((String clientId,
BuiltMap<String, InvoiceEntity> invoiceMap,
String activeLabel,
String archivedLabel) =>
invoiceStatsForClient(clientId, invoiceMap, activeLabel, archivedLabel));
var memoizedInvoiceStatsForClient = memo2((String clientId,
BuiltMap<String, InvoiceEntity> invoiceMap) =>
invoiceStatsForClient(clientId, invoiceMap));
String invoiceStatsForClient(
EntityStats invoiceStatsForClient(
String clientId,
BuiltMap<String, InvoiceEntity> invoiceMap,
String activeLabel,
String archivedLabel) {
BuiltMap<String, InvoiceEntity> 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<String, InvoiceEntity> invoiceMap,
String activeLabel,
String archivedLabel) =>
invoiceStatsForUser(userId, invoiceMap, activeLabel, archivedLabel));
var memoizedInvoiceStatsForUser = memo2((String userId,
BuiltMap<String, InvoiceEntity> invoiceMap) =>
invoiceStatsForUser(userId, invoiceMap));
String invoiceStatsForUser(
EntityStats invoiceStatsForUser(
String userId,
BuiltMap<String, InvoiceEntity> invoiceMap,
String activeLabel,
String archivedLabel) {
BuiltMap<String, InvoiceEntity> 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(

View File

@ -100,20 +100,16 @@ List<String> filteredPaymentsSelector(
return list;
}
var memoizedPaymentStatsForClient = memo5((String clientId,
var memoizedPaymentStatsForClient = memo3((String clientId,
BuiltMap<String, PaymentEntity> paymentMap,
BuiltMap<String, InvoiceEntity> invoiceMap,
String activeLabel,
String archivedLabel) =>
BuiltMap<String, InvoiceEntity> invoiceMap) =>
paymentStatsForClient(
clientId, paymentMap, invoiceMap, activeLabel, archivedLabel));
clientId, paymentMap, invoiceMap));
String paymentStatsForClient(
EntityStats paymentStatsForClient(
String clientId,
BuiltMap<String, PaymentEntity> paymentMap,
BuiltMap<String, InvoiceEntity> invoiceMap,
String activeLabel,
String archivedLabel) {
BuiltMap<String, InvoiceEntity> 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<String, PaymentEntity> paymentMap,
BuiltMap<String, InvoiceEntity> invoiceMap,
String activeLabel,
String archivedLabel) =>
BuiltMap<String, InvoiceEntity> invoiceMap) =>
paymentStatsForClient(
userId, paymentMap, invoiceMap, activeLabel, archivedLabel));
userId, paymentMap, invoiceMap));
String paymentStatsForUser(
EntityStats paymentStatsForUser(
String userId,
BuiltMap<String, PaymentEntity> paymentMap,
BuiltMap<String, InvoiceEntity> invoiceMap,
String activeLabel,
String archivedLabel) {
BuiltMap<String, InvoiceEntity> 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(

View File

@ -131,17 +131,13 @@ Duration taskDurationForProject(
return Duration(seconds: total);
}
var memoizedProjectStatsForClient = memo4((String clientId,
BuiltMap<String, ProjectEntity> projectMap,
String activeLabel,
String archivedLabel) =>
projectStatsForClient(clientId, projectMap, activeLabel, archivedLabel));
var memoizedProjectStatsForClient = memo2((String clientId,
BuiltMap<String, ProjectEntity> projectMap) =>
projectStatsForClient(clientId, projectMap));
String projectStatsForClient(
EntityStats projectStatsForClient(
String clientId,
BuiltMap<String, ProjectEntity> projectMap,
String activeLabel,
String archivedLabel) {
BuiltMap<String, ProjectEntity> 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(

View File

@ -61,17 +61,13 @@ List<String> filteredQuotesSelector(
return list;
}
var memoizedQuoteStatsForClient = memo4((String clientId,
BuiltMap<String, InvoiceEntity> quoteMap,
String activeLabel,
String archivedLabel) =>
quoteStatsForClient(clientId, quoteMap, activeLabel, archivedLabel));
var memoizedQuoteStatsForClient = memo2((String clientId,
BuiltMap<String, InvoiceEntity> quoteMap) =>
quoteStatsForClient(clientId, quoteMap));
String quoteStatsForClient(
EntityStats quoteStatsForClient(
String clientId,
BuiltMap<String, InvoiceEntity> quoteMap,
String activeLabel,
String archivedLabel) {
BuiltMap<String, InvoiceEntity> 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,

View File

@ -155,11 +155,12 @@ double taskRateSelector(
return 0;
}
var memoizedTaskStatsForClient = memo2((String clientId,
BuiltMap<String, TaskEntity> taskMap) =>
taskStatsForClient(clientId, taskMap));
var memoizedTaskStatsForClient = memo2(
(String clientId, BuiltMap<String, TaskEntity> taskMap) =>
taskStatsForClient(clientId, taskMap));
EntityStats taskStatsForClient(String clientId, BuiltMap<String, TaskEntity> taskMap) {
EntityStats taskStatsForClient(
String clientId, BuiltMap<String, TaskEntity> taskMap) {
int countActive = 0;
int countArchived = 0;
taskMap.forEach((taskId, task) {
@ -175,17 +176,14 @@ EntityStats taskStatsForClient(String clientId, BuiltMap<String, TaskEntity> tas
return EntityStats(countActive: countActive, countArchived: countArchived);
}
var memoizedTaskStatsForProject = memo4((String projectId,
BuiltMap<String, TaskEntity> taskMap,
String activeLabel,
String archivedLabel) =>
taskStatsForProject(projectId, taskMap, activeLabel, archivedLabel));
var memoizedTaskStatsForProject = memo2((
String projectId,
BuiltMap<String, TaskEntity> taskMap,
) =>
taskStatsForProject(projectId, taskMap));
String taskStatsForProject(
String projectId,
BuiltMap<String, TaskEntity> taskMap,
String activeLabel,
String archivedLabel) {
EntityStats taskStatsForProject(
String projectId, BuiltMap<String, TaskEntity> 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<String, TaskEntity> taskMap) =>

View File

@ -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(),
],

View File

@ -76,8 +76,9 @@ class _GroupViewState extends State<GroupView> {
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,

View File

@ -115,10 +115,8 @@ class _ProjectViewState extends State<ProjectView> {
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,

View File

@ -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(

View File

@ -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),
),
],
);