Skip to content

Commit

Permalink
feat: add list of providers in settings
Browse files Browse the repository at this point in the history
  • Loading branch information
manuel-rw committed Jan 26, 2024
1 parent 5263639 commit 3a9c1c6
Show file tree
Hide file tree
Showing 5 changed files with 36 additions and 3 deletions.
4 changes: 4 additions & 0 deletions GrocyScanner.Core/Providers/IProductProvider.cs
Original file line number Diff line number Diff line change
Expand Up @@ -5,4 +5,8 @@ namespace GrocyScanner.Core.Providers;
public interface IProductProvider
{
public Task<Product?> GetProductByGtin(string gtin);

public string Name { get; }

public string IconUri { get; }
}
12 changes: 12 additions & 0 deletions GrocyScanner.Core/Providers/OpenFoodFactsProductProvider.cs
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
using Microsoft.Extensions.Logging;
using OpenFoodFacts4Net.ApiClient;
using OpenFoodFacts4Net.Json.Data;
using Product = GrocyScanner.Core.Models.Product;
Expand All @@ -6,6 +7,13 @@ namespace GrocyScanner.Core.Providers;

public class OpenFoodFactsProductProvider : IProductProvider
{
private readonly ILogger<OpenFoodFactsProductProvider> _logger;

public OpenFoodFactsProductProvider(ILogger<OpenFoodFactsProductProvider> logger)
{
_logger = logger;
}

public async Task<Product?> GetProductByGtin(string gtin)
{
Client client = new();
Expand All @@ -28,7 +36,11 @@ public class OpenFoodFactsProductProvider : IProductProvider
}
catch (HttpRequestException httpRequestException)
{
_logger.LogError(httpRequestException, "Unable to request {Gtin}", gtin);
return null;
}
}

public string Name => "Open Food Facts";
public string IconUri => "/open-food-facts-logo.png";
}
2 changes: 1 addition & 1 deletion GrocyScanner.Service/Pages/Index.razor
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,6 @@

<PageTitle>Home • Grocy Scanner</PageTitle>

<h3>Welcome back</h3>
<h3 class="fw-bolder">Welcome back</h3>
<p>Using this application, you can scan unknown Products and they'll be automatically added to Grocy.</p>

21 changes: 19 additions & 2 deletions GrocyScanner.Service/Pages/Settings.razor
Original file line number Diff line number Diff line change
@@ -1,5 +1,22 @@
@page "/Settings"
@using GrocyScanner.Core.Providers

<h3>Settings</h3>
@inject IEnumerable<IProductProvider> ProductProviders

<p class="fw-bold text-danger">Settings are currently unavailable in this version.</p>
<PageTitle>Settings • Grocy Scanner</PageTitle>

<h3 class="fw-bolder mb-3">Settings</h3>

<h4>Active Indexers</h4>

<MudList>
@foreach (IProductProvider provider in ProductProviders)
{
<MudListItem Avatar="<image href='https://ch.openfoodfacts.org/images/favicon/apple-touch-icon.png' width='100%' height='100%' />">
<div class="d-flex align-items-center gap-3">
<MudText>@provider.Name</MudText>
<MudChip Variant="Variant.Text" Color="Color.Success">Enabled</MudChip>
</div>
</MudListItem>
}
</MudList>
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.

0 comments on commit 3a9c1c6

Please sign in to comment.