Skip to content

Commit

Permalink
fix: grocyproducts again (#16)
Browse files Browse the repository at this point in the history
Co-authored-by: GoodOldJack12 <[email protected]>
  • Loading branch information
GoodOldJack12 and GoodOldJack12 authored Sep 4, 2024
1 parent d8c0541 commit 1729abb
Showing 1 changed file with 6 additions and 9 deletions.
15 changes: 6 additions & 9 deletions GrocyScanner.Service/Shared/Components/AddProductDialog.razor
Original file line number Diff line number Diff line change
Expand Up @@ -82,7 +82,7 @@
OnClick="OnClickPurchase"
Variant="Variant.Filled"
Color="Color.Primary"
Disabled= "@( IsLoading || Product == null || string.IsNullOrWhiteSpace(FormProductName))">
Disabled= "@( IsLoading || Product == null || (Product.Name == UnknownFlag && string.IsNullOrWhiteSpace(FormProductName)))">
Purchase
</MudButton>
</DialogActions>
Expand Down Expand Up @@ -127,13 +127,9 @@
{
Product?[] products = await Task.WhenAll(ProductProviders.Select(async provider => await provider.GetProductByGtin(Barcode)));
Product = BestValueCalculator.GetProductWithMostValue(products.Where(product => product != null).Cast<Product>().ToList());
if (Product != null)
if (Product == null)
{
FormProductName = Product.Name;
}
else
{
Product = new Product {Name = UnknownFlag, Gtin = Barcode };
Product = new Product { Name = UnknownFlag, Gtin = Barcode };
}
}
else
Expand All @@ -147,11 +143,12 @@

private async Task OnClickPurchase()
{
if (Product == null || string.IsNullOrEmpty(FormProductName))
if (Product == null || (Product.Name == UnknownFlag && string.IsNullOrEmpty(FormProductName)))
{
return;
}
Product.Name = FormProductName;

if (FormProductName != null) Product.Name = FormProductName;
DateOnly? bestBeforeDate = FormBestBefore.HasValue ? DateOnly.FromDateTime(FormBestBefore.Value) : null;
await GrocyClient.UpsertProduct(Product, FormAmount, bestBeforeDate, FormPrice);
Snackbar.Add($"Added \"{Product.Name}\" to Grocy", Severity.Success);
Expand Down

0 comments on commit 1729abb

Please sign in to comment.