Only set loaded if initial load has data

This commit is contained in:
Hillel Coren 2020-06-23 14:44:06 +03:00
parent 1e6024b642
commit c358ffec16
14 changed files with 73 additions and 29 deletions

View File

@ -268,6 +268,8 @@ abstract class CompanyEntity extends Object
bool get enableThirdItemTaxRate => (numberOfItemTaxRates ?? 0) >= 3; bool get enableThirdItemTaxRate => (numberOfItemTaxRates ?? 0) >= 3;
bool get hasData => clients.isNotEmpty || products.isNotEmpty || tasks.isNotEmpty;
bool get hasCustomSurcharge => bool get hasCustomSurcharge =>
hasCustomField(CustomFieldType.surcharge1) || hasCustomField(CustomFieldType.surcharge1) ||
hasCustomField(CustomFieldType.surcharge2) || hasCustomField(CustomFieldType.surcharge2) ||

View File

@ -400,10 +400,6 @@ Middleware<AppState> _createAccountLoaded() {
store.dispatch(SelectCompany(i)); store.dispatch(SelectCompany(i));
store.dispatch(LoadCompanySuccess(userCompany)); store.dispatch(LoadCompanySuccess(userCompany));
/*
stub
*/
} }
store.dispatch(SelectCompany(selectedCompanyIndex)); store.dispatch(SelectCompany(selectedCompanyIndex));

View File

@ -363,5 +363,9 @@ ClientState _setLoadedClients(
clientState.loadClients(action.clients); clientState.loadClients(action.clients);
ClientState _setLoadedCompany( ClientState _setLoadedCompany(
ClientState clientState, LoadCompanySuccess action) => ClientState clientState, LoadCompanySuccess action) {
clientState.loadClients(action.userCompany.company.clients); final company = action.userCompany.company;
return company.hasData
? clientState.loadClients(company.clients)
: clientState;
}

View File

@ -400,5 +400,9 @@ CreditState _setLoadedCredits(
creditState.loadCredits(action.credits); creditState.loadCredits(action.credits);
CreditState _setLoadedCompany( CreditState _setLoadedCompany(
CreditState creditState, LoadCompanySuccess action) => CreditState creditState, LoadCompanySuccess action) {
creditState.loadCredits(action.userCompany.company.credits); final company = action.userCompany.company;
return company.hasData
? creditState.loadCredits(company.credits)
: creditState;
}

View File

@ -279,5 +279,9 @@ DesignState _setLoadedDesigns(
designState.loadDesigns(action.designs); designState.loadDesigns(action.designs);
DesignState _setLoadedCompany( DesignState _setLoadedCompany(
DesignState designState, LoadCompanySuccess action) => DesignState designState, LoadCompanySuccess action) {
designState.loadDesigns(action.userCompany.company.designs); final company = action.userCompany.company;
return company.hasData
? designState.loadDesigns(company.designs)
: designState;
}

View File

@ -316,5 +316,9 @@ ExpenseState _setLoadedExpenses(
expenseState.loadExpenses(action.expenses); expenseState.loadExpenses(action.expenses);
ExpenseState _setLoadedCompany( ExpenseState _setLoadedCompany(
ExpenseState expenseState, LoadCompanySuccess action) => ExpenseState expenseState, LoadCompanySuccess action) {
expenseState.loadExpenses(action.userCompany.company.expenses); final company = action.userCompany.company;
return company.hasData
? expenseState.loadExpenses(company.expenses)
: expenseState;
}

View File

@ -451,5 +451,9 @@ InvoiceState _setLoadedInvoices(
invoiceState.loadInvoices(action.invoices); invoiceState.loadInvoices(action.invoices);
InvoiceState _setLoadedCompany( InvoiceState _setLoadedCompany(
InvoiceState invoiceState, LoadCompanySuccess action) => InvoiceState invoiceState, LoadCompanySuccess action) {
invoiceState.loadInvoices(action.userCompany.company.invoices); final company = action.userCompany.company;
return company.hasData
? invoiceState.loadInvoices(company.invoices)
: invoiceState;
}

View File

@ -317,5 +317,9 @@ PaymentState _setLoadedPayments(
paymentState.loadPayments(action.payments); paymentState.loadPayments(action.payments);
PaymentState _setLoadedCompany( PaymentState _setLoadedCompany(
PaymentState paymentState, LoadCompanySuccess action) => PaymentState paymentState, LoadCompanySuccess action) {
paymentState.loadPayments(action.userCompany.company.payments); final company = action.userCompany.company;
return company.hasData
? paymentState.loadPayments(company.payments)
: paymentState;
}

View File

@ -295,5 +295,9 @@ ProductState _setLoadedProducts(
productState.loadProducts(action.products); productState.loadProducts(action.products);
ProductState _setLoadedCompany( ProductState _setLoadedCompany(
ProductState productState, LoadCompanySuccess action) => ProductState productState, LoadCompanySuccess action) {
productState.loadProducts(action.userCompany.company.products); final company = action.userCompany.company;
return company.hasData
? productState.loadProducts(company.products)
: productState;
}

View File

@ -321,5 +321,9 @@ ProjectState _setLoadedProjects(
projectState.loadProjects(action.projects); projectState.loadProjects(action.projects);
ProjectState _setLoadedCompany( ProjectState _setLoadedCompany(
ProjectState projectState, LoadCompanySuccess action) => ProjectState projectState, LoadCompanySuccess action) {
projectState.loadProjects(action.userCompany.company.projects); final company = action.userCompany.company;
return company.hasData
? projectState.loadProjects(company.projects)
: projectState;
}

View File

@ -408,6 +408,7 @@ QuoteState _updateQuote(QuoteState quoteState, dynamic action) {
QuoteState _setLoadedQuotes(QuoteState quoteState, LoadQuotesSuccess action) => QuoteState _setLoadedQuotes(QuoteState quoteState, LoadQuotesSuccess action) =>
quoteState.loadQuotes(action.quotes); quoteState.loadQuotes(action.quotes);
QuoteState _setLoadedCompany( QuoteState _setLoadedCompany(QuoteState quoteState, LoadCompanySuccess action) {
QuoteState quoteState, LoadCompanySuccess action) => final company = action.userCompany.company;
quoteState.loadQuotes(action.userCompany.company.quotes); return company.hasData ? quoteState.loadQuotes(company.quotes) : quoteState;
}

View File

@ -297,5 +297,10 @@ TaskState _setLoadedTask(TaskState taskState, LoadTaskSuccess action) {
TaskState _setLoadedTasks(TaskState taskState, LoadTasksSuccess action) => TaskState _setLoadedTasks(TaskState taskState, LoadTasksSuccess action) =>
taskState.loadTasks(action.tasks); taskState.loadTasks(action.tasks);
TaskState _setLoadedCompany(TaskState taskState, LoadCompanySuccess action) => TaskState _setLoadedCompany(TaskState taskState, LoadCompanySuccess action) {
taskState.loadTasks(action.userCompany.company.tasks); final company = action.userCompany.company;
return company.hasData
? taskState.loadTasks(company.tasks)
: taskState;
}

View File

@ -344,5 +344,9 @@ VendorState _setLoadedVendors(
vendorState.loadVendors(action.vendors); vendorState.loadVendors(action.vendors);
VendorState _setLoadedCompany( VendorState _setLoadedCompany(
VendorState vendorState, LoadCompanySuccess action) => VendorState vendorState, LoadCompanySuccess action) {
vendorState.loadVendors(action.userCompany.company.vendors); final company = action.userCompany.company;
return company.hasData
? vendorState.loadVendors(company.vendors)
: vendorState;
}

View File

@ -285,5 +285,9 @@ StubState _setLoadedStubs(
stubState.loadStubs(action.stubs); stubState.loadStubs(action.stubs);
StubState _setLoadedCompany( StubState _setLoadedCompany(
StubState stubState, LoadCompanySuccess action) => StubState stubState, LoadCompanySuccess action) {
stubState.loadStubs(action.userCompany.company.stubs); final company = action.userCompany.company;
return company.hasData
? stubState.loadStubs(company.stubs)
: stubState;
}