Scan ean code on iOS app
This commit is contained in:
@@ -36,13 +36,26 @@
|
||||
</MudItem>
|
||||
|
||||
<MudItem xs="12" sm="6" md="4">
|
||||
<MudTextField @bind-Value="filterRequest.Ean"
|
||||
Label="EAN"
|
||||
Immediate="true"
|
||||
DebounceInterval="500"
|
||||
OnDebounceIntervalElapsed="SearchProducts"
|
||||
Clearable="true">
|
||||
</MudTextField>
|
||||
<div style="display: flex; gap: 8px; align-items: flex-end;">
|
||||
<div style="flex: 1;">
|
||||
<MudTextField @bind-Value="filterRequest.Ean"
|
||||
Label="EAN"
|
||||
Immediate="true"
|
||||
DebounceInterval="500"
|
||||
OnDebounceIntervalElapsed="SearchProducts"
|
||||
Clearable="true"/>
|
||||
</div>
|
||||
@if (ScannerService.IsAvailable)
|
||||
{
|
||||
<MudIconButton Icon="@Icons.Material.Filled.CameraAlt"
|
||||
Color="Color.Primary"
|
||||
OnClick="OnScannerClick"
|
||||
Variant="Variant.Filled"
|
||||
Size="Size.Medium"
|
||||
Title="Skanuj kod EAN"/>
|
||||
}
|
||||
</div>
|
||||
|
||||
</MudItem>
|
||||
|
||||
<MudItem xs="12" sm="6" md="4">
|
||||
|
||||
@@ -1,16 +1,19 @@
|
||||
using Bimix.Application.DTOModels;
|
||||
using Bimix.Application.DTOModels.Common;
|
||||
using Bimix.Domain.Entities;
|
||||
using Bimix.UI.Shared.Interfaces;
|
||||
using Bimix.UI.Shared.Services;
|
||||
using Microsoft.AspNetCore.Components;
|
||||
using Microsoft.AspNetCore.Components.Web;
|
||||
using Microsoft.JSInterop;
|
||||
using MudBlazor;
|
||||
|
||||
|
||||
namespace Bimix.UI.Shared.Components;
|
||||
|
||||
public partial class ProductListComponent : ComponentBase
|
||||
{
|
||||
[Inject] private ProductService ProductService { get; set; } = default!;
|
||||
[Inject] private IScannerService ScannerService { get; set; } = default!;
|
||||
[Inject] private ISnackbar Snackbar { get; set; } = default!;
|
||||
|
||||
|
||||
private PagedResult<ProductDto> products = new();
|
||||
private ProductFilterRequest filterRequest = new();
|
||||
@@ -20,11 +23,6 @@ public partial class ProductListComponent : ComponentBase
|
||||
{
|
||||
await LoadProducts();
|
||||
}
|
||||
|
||||
private async Task StartBarcodeScanner()
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
private async Task LoadProducts()
|
||||
{
|
||||
@@ -74,4 +72,34 @@ public partial class ProductListComponent : ComponentBase
|
||||
Console.WriteLine($"Usuń produkt: {productId}");
|
||||
}
|
||||
|
||||
private string GetScannerIcon()
|
||||
{
|
||||
return ScannerService.IsAvailable ? Icons.Material.Filled.CameraAlt : "";
|
||||
}
|
||||
|
||||
private async Task OnScannerClick()
|
||||
{
|
||||
if (!ScannerService.IsAvailable)
|
||||
{
|
||||
Snackbar.Add("Skaner nie jest dostępny na tej platformie", Severity.Warning);
|
||||
return;
|
||||
}
|
||||
|
||||
try
|
||||
{
|
||||
var scannedCode = await ScannerService.ScanBarcodeAsync();
|
||||
if (!string.IsNullOrEmpty(scannedCode))
|
||||
{
|
||||
filterRequest.Ean = scannedCode;
|
||||
await SearchProducts();
|
||||
Snackbar.Add($"Zeskanowano kod: {scannedCode}", Severity.Success);
|
||||
}
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
System.Diagnostics.Debug.WriteLine($"Scanner error: {ex.Message}");
|
||||
Snackbar.Add("Błąd podczas skanowania", Severity.Error);
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
Reference in New Issue
Block a user