diff --git a/Wonky.Client/Pages/AdvisorCustomerInvoiceListPage.razor b/Wonky.Client/Pages/AdvisorCustomerInvoiceListPage.razor index 0b574d42..879724c7 100644 --- a/Wonky.Client/Pages/AdvisorCustomerInvoiceListPage.razor +++ b/Wonky.Client/Pages/AdvisorCustomerInvoiceListPage.razor @@ -32,8 +32,8 @@ Besøg - - + + } @if (Working) diff --git a/Wonky.Client/Pages/AdvisorCustomerInvoiceListPage.razor.cs b/Wonky.Client/Pages/AdvisorCustomerInvoiceListPage.razor.cs index fe7da5ad..b7ade2a0 100644 --- a/Wonky.Client/Pages/AdvisorCustomerInvoiceListPage.razor.cs +++ b/Wonky.Client/Pages/AdvisorCustomerInvoiceListPage.razor.cs @@ -23,36 +23,41 @@ public partial class AdvisorCustomerInvoiceListPage : IDisposable [Inject] public ILogger Logger { get; set; } private InvoiceListView CompanyInvoices { get; set; } = new(); private CompanyDto Company { get; set; } = new(); - private bool Working { get; set; } = true; + private bool Working { get; set; } private InvoiceViewModal InvoiceView { get; set; } = new(); private string InvoiceId { get; set; } = ""; + private bool AllSet { get; set; } + private string _companyId = ""; + + protected override void OnInitialized() + { + _companyId = CompanyId; + Working = true; + } protected override async Task OnInitializedAsync() { Interceptor.RegisterEvent(); Interceptor.RegisterBeforeSendEvent(); - Company = await CompanyRepo.GetCompanyById(CompanyId); - while (string.IsNullOrWhiteSpace(Company.HistorySync)) - { - await Task.Delay(1000); - } + Company = await CompanyRepo.GetCompanyById(_companyId); - var iDate = await Storage.GetItemAsStringAsync($"{Company.CompanyId}-iDate"); + while (string.IsNullOrWhiteSpace(Company.HistorySync)) + await Task.Delay(500); + + var iDate = await Storage.GetItemAsStringAsync($"{_companyId}-iDate"); if (string.IsNullOrWhiteSpace(iDate) || (iDate == Company.HistorySync && iDate != $"{DateTime.Now:yyyy-MM-dd}")) { // send rpc to sync invoices from ERP to CRM - var ts = await HistoryRepo.ErpInvoiceToCrmRpc(CompanyId, Company.HistorySync); + var ts = await HistoryRepo.ErpInvoiceToCrmRpc(_companyId, Company.HistorySync); // wait until we have the result while (string.IsNullOrWhiteSpace(ts)) - { - await Task.Delay(1000); - } - await Storage.SetItemAsync($"{Company.CompanyId}-iDate", ts); + await Task.Delay(500); + + await Storage.SetItemAsync($"{_companyId}-iDate", ts); } - CompanyInvoices = await FetchCompanyInvoices(); - Working = false; + AllSet = true; } private void CallInvoiceModal(string invoiceId) @@ -63,20 +68,23 @@ public partial class AdvisorCustomerInvoiceListPage : IDisposable private async Task FetchCompanyInvoices() { - var storage = await Storage.GetItemAsStringAsync($"{Company.CompanyId}-invoices"); - var iDate = await Storage.GetItemAsStringAsync($"{Company.CompanyId}-iDate"); + // fetch from storage + var storage = await Storage.GetItemAsStringAsync($"{_companyId}-invoices"); + var iDate = await Storage.GetItemAsStringAsync($"{_companyId}-iDate"); + // if we have a list and iDate was today return the list - if (!string.IsNullOrWhiteSpace(storage) && DateTime.Parse(iDate.Replace("\"", "")) >= DateTime.Now) + if (!string.IsNullOrWhiteSpace(storage) && (!string.IsNullOrWhiteSpace(iDate) && DateTime.Parse(iDate.Replace("\"", "")) >= DateTime.Now)) { Logger.LogDebug("return invoices from storage"); return JsonSerializer.Deserialize(storage); } Logger.LogDebug("pulling invoices from backend"); // pull invoices - var invoices = await HistoryRepo.FetchInvoiceList(CompanyId); + var invoices = await HistoryRepo.FetchInvoiceList(_companyId); // send invoices to storage - await Storage.SetItemAsync($"{Company.CompanyId}-invoices", invoices); + await Storage.SetItemAsync($"{_companyId}-invoices", invoices); Logger.LogDebug("return invoices from backend"); + Working = false; return invoices; } diff --git a/Wonky.Client/wwwroot/appsettings.json b/Wonky.Client/wwwroot/appsettings.json index 0e7639c5..4a71c921 100644 --- a/Wonky.Client/wwwroot/appsettings.json +++ b/Wonky.Client/wwwroot/appsettings.json @@ -1,7 +1,7 @@ { "appInfo": { "name": "Wonky Client", - "version": "0.91.1", + "version": "0.92.1", "rc": true, "sandBox": false, "image": "grumpy-coder.png"