Show company logo in companies list.

This commit is contained in:
2025-11-15 18:42:11 +00:00
parent fe2c3a082d
commit 0368e12974
3 changed files with 60 additions and 16 deletions

View File

@@ -3,13 +3,16 @@
using System; using System;
using System.Collections.Generic; using System.Collections.Generic;
using System.Collections.ObjectModel; using System.Collections.ObjectModel;
using System.IO;
using System.Linq; using System.Linq;
using System.Threading.Tasks; using System.Threading.Tasks;
using System.Windows.Input; using System.Windows.Input;
using Marechai.App.Helpers; using Marechai.App.Helpers;
using Marechai.App.Presentation.Models; using Marechai.App.Presentation.Models;
using Marechai.App.Services; using Marechai.App.Services;
using Marechai.App.Services.Caching;
using Uno.Extensions.Navigation; using Uno.Extensions.Navigation;
using Microsoft.UI.Xaml.Media.Imaging;
namespace Marechai.App.Presentation.ViewModels; namespace Marechai.App.Presentation.ViewModels;
@@ -17,6 +20,7 @@ public partial class CompaniesViewModel : ObservableObject
{ {
private readonly List<CompanyListItem> _allCompanies = []; private readonly List<CompanyListItem> _allCompanies = [];
private readonly CompaniesService _companiesService; private readonly CompaniesService _companiesService;
private readonly CompanyLogoCache _logoCache;
private readonly IStringLocalizer _localizer; private readonly IStringLocalizer _localizer;
private readonly ILogger<CompaniesViewModel> _logger; private readonly ILogger<CompaniesViewModel> _logger;
private readonly INavigator _navigator; private readonly INavigator _navigator;
@@ -45,10 +49,12 @@ public partial class CompaniesViewModel : ObservableObject
[ObservableProperty] [ObservableProperty]
private string _searchQuery = string.Empty; private string _searchQuery = string.Empty;
public CompaniesViewModel(CompaniesService companiesService, IStringLocalizer localizer, public CompaniesViewModel(CompaniesService companiesService, CompanyLogoCache logoCache,
ILogger<CompaniesViewModel> logger, INavigator navigator) IStringLocalizer localizer, ILogger<CompaniesViewModel> logger,
INavigator navigator)
{ {
_companiesService = companiesService; _companiesService = companiesService;
_logoCache = logoCache;
_localizer = localizer; _localizer = localizer;
_logger = logger; _logger = logger;
_navigator = navigator; _navigator = navigator;
@@ -98,11 +104,29 @@ public partial class CompaniesViewModel : ObservableObject
// Convert DateTimeOffset? to DateTime? // Convert DateTimeOffset? to DateTime?
DateTime? foundedDate = company.Founded?.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);
logoSource = new SvgImageSource();
await logoSource.SetSourceAsync(logoStream.AsRandomAccessStream());
}
catch(Exception ex)
{
_logger.LogWarning("Failed to load logo for company {CompanyId}: {Exception}",
companyId, ex.Message);
}
}
_allCompanies.Add(new CompanyListItem _allCompanies.Add(new CompanyListItem
{ {
Id = companyId, Id = companyId,
Name = company.Name ?? string.Empty, Name = company.Name ?? string.Empty,
FoundationDate = foundedDate FoundationDate = foundedDate,
LogoImageSource = logoSource
}); });
} }
@@ -189,6 +213,7 @@ public class CompanyListItem
public int Id { get; set; } public int Id { get; set; }
public string Name { get; set; } = string.Empty; public string Name { get; set; } = string.Empty;
public DateTime? FoundationDate { get; set; } public DateTime? FoundationDate { get; set; }
public SvgImageSource? LogoImageSource { get; set; }
public string FoundationDateDisplay => public string FoundationDateDisplay =>
FoundationDate.HasValue ? FoundationDate.Value.ToString("MMMM d, yyyy") : string.Empty; FoundationDate.HasValue ? FoundationDate.Value.ToString("MMMM d, yyyy") : string.Empty;

View File

@@ -138,7 +138,7 @@ public partial class CompanyDetailViewModel : ObservableObject
OnPropertyChanged(nameof(HasLogoContent)); OnPropertyChanged(nameof(HasLogoContent));
} }
partial void OnCompanyLogosChanged(ObservableCollection<CompanyLogoItem> oldValue, partial void OnCompanyLogosChanged(ObservableCollection<CompanyLogoItem>? oldValue,
ObservableCollection<CompanyLogoItem> newValue) ObservableCollection<CompanyLogoItem> newValue)
{ {
// Notify that HasMultipleLogos has changed // Notify that HasMultipleLogos has changed

View File

@@ -97,8 +97,26 @@
<Button HorizontalAlignment="Stretch" <Button HorizontalAlignment="Stretch"
Command="{Binding DataContext.NavigateToCompanyCommand, ElementName=PageRoot}" Command="{Binding DataContext.NavigateToCompanyCommand, ElementName=PageRoot}"
CommandParameter="{Binding}"> CommandParameter="{Binding}">
<StackPanel Spacing="4" <Grid ColumnSpacing="12">
Padding="8"> <Grid.ColumnDefinitions>
<ColumnDefinition Width="Auto" />
<ColumnDefinition Width="*" />
</Grid.ColumnDefinitions>
<!-- Company Logo -->
<Image Grid.Column="0"
Width="48"
Height="48"
Stretch="Uniform"
VerticalAlignment="Center"
HorizontalAlignment="Left"
Source="{Binding LogoImageSource}"
Visibility="{Binding LogoImageSource, Converter={StaticResource ObjectToVisibilityConverter}}" />
<!-- Company Details -->
<StackPanel Grid.Column="1"
Spacing="4"
VerticalAlignment="Center">
<TextBlock Text="{Binding Name}" <TextBlock Text="{Binding Name}"
FontSize="16" FontSize="16"
FontWeight="SemiBold" /> FontWeight="SemiBold" />
@@ -106,6 +124,7 @@
FontSize="12" FontSize="12"
Opacity="0.6" /> Opacity="0.6" />
</StackPanel> </StackPanel>
</Grid>
</Button> </Button>
</DataTemplate> </DataTemplate>
</ItemsRepeater.ItemTemplate> </ItemsRepeater.ItemTemplate>