mirror of
https://github.com/claunia/marechai.git
synced 2025-12-16 19:14:25 +00:00
No need to use untypenode extraction anymore.
This commit is contained in:
@@ -7,12 +7,11 @@ using System.IO;
|
||||
using System.Linq;
|
||||
using System.Threading.Tasks;
|
||||
using System.Windows.Input;
|
||||
using Marechai.App.Helpers;
|
||||
using Marechai.App.Presentation.Models;
|
||||
using Marechai.App.Services;
|
||||
using Marechai.App.Services.Caching;
|
||||
using Uno.Extensions.Navigation;
|
||||
using Microsoft.UI.Xaml.Media.Imaging;
|
||||
using Uno.Extensions.Navigation;
|
||||
|
||||
namespace Marechai.App.Presentation.ViewModels;
|
||||
|
||||
@@ -20,9 +19,9 @@ public partial class CompaniesViewModel : ObservableObject
|
||||
{
|
||||
private readonly List<CompanyListItem> _allCompanies = [];
|
||||
private readonly CompaniesService _companiesService;
|
||||
private readonly CompanyLogoCache _logoCache;
|
||||
private readonly IStringLocalizer _localizer;
|
||||
private readonly ILogger<CompaniesViewModel> _logger;
|
||||
private readonly CompanyLogoCache _logoCache;
|
||||
private readonly INavigator _navigator;
|
||||
|
||||
[ObservableProperty]
|
||||
@@ -49,9 +48,8 @@ public partial class CompaniesViewModel : ObservableObject
|
||||
[ObservableProperty]
|
||||
private string _searchQuery = string.Empty;
|
||||
|
||||
public CompaniesViewModel(CompaniesService companiesService, CompanyLogoCache logoCache,
|
||||
IStringLocalizer localizer, ILogger<CompaniesViewModel> logger,
|
||||
INavigator navigator)
|
||||
public CompaniesViewModel(CompaniesService companiesService, CompanyLogoCache logoCache, IStringLocalizer localizer,
|
||||
ILogger<CompaniesViewModel> logger, INavigator navigator)
|
||||
{
|
||||
_companiesService = companiesService;
|
||||
_logoCache = logoCache;
|
||||
@@ -98,34 +96,36 @@ public partial class CompaniesViewModel : ObservableObject
|
||||
// Build the full list in memory
|
||||
foreach(CompanyDto company in companies)
|
||||
{
|
||||
// Extract id from UntypedNode
|
||||
int companyId = UntypedNodeExtractor.ExtractInt(company.Id);
|
||||
// Extract id from company
|
||||
int companyId = company.Id ?? 0;
|
||||
|
||||
// Convert DateTimeOffset? to DateTime?
|
||||
DateTime? foundedDate = company.Founded?.DateTime;
|
||||
|
||||
// Load logo if available
|
||||
SvgImageSource? logoSource = null;
|
||||
|
||||
if(company.LastLogo.HasValue)
|
||||
{
|
||||
try
|
||||
{
|
||||
var logoStream = await _logoCache.GetLogoAsync(company.LastLogo.Value);
|
||||
Stream? logoStream = await _logoCache.GetLogoAsync(company.LastLogo.Value);
|
||||
logoSource = new SvgImageSource();
|
||||
await logoSource.SetSourceAsync(logoStream.AsRandomAccessStream());
|
||||
}
|
||||
catch(Exception ex)
|
||||
{
|
||||
_logger.LogWarning("Failed to load logo for company {CompanyId}: {Exception}",
|
||||
companyId, ex.Message);
|
||||
companyId,
|
||||
ex.Message);
|
||||
}
|
||||
}
|
||||
|
||||
_allCompanies.Add(new CompanyListItem
|
||||
{
|
||||
Id = companyId,
|
||||
Name = company.Name ?? string.Empty,
|
||||
FoundationDate = foundedDate,
|
||||
Id = companyId,
|
||||
Name = company.Name ?? string.Empty,
|
||||
FoundationDate = foundedDate,
|
||||
LogoImageSource = logoSource
|
||||
});
|
||||
}
|
||||
@@ -210,10 +210,10 @@ public partial class CompaniesViewModel : ObservableObject
|
||||
/// </summary>
|
||||
public class CompanyListItem
|
||||
{
|
||||
public int Id { get; set; }
|
||||
public string Name { get; set; } = string.Empty;
|
||||
public DateTime? FoundationDate { get; set; }
|
||||
public SvgImageSource? LogoImageSource { get; set; }
|
||||
public int Id { get; set; }
|
||||
public string Name { get; set; } = string.Empty;
|
||||
public DateTime? FoundationDate { get; set; }
|
||||
public SvgImageSource? LogoImageSource { get; set; }
|
||||
|
||||
public string FoundationDateDisplay =>
|
||||
FoundationDate.HasValue ? FoundationDate.Value.ToString("MMMM d, yyyy") : string.Empty;
|
||||
|
||||
Reference in New Issue
Block a user