mirror of
https://github.com/claunia/marechai.git
synced 2025-12-16 19:14:25 +00:00
Show company logo in companies list.
This commit is contained in:
@@ -3,13 +3,16 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Collections.ObjectModel;
|
||||
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;
|
||||
|
||||
namespace Marechai.App.Presentation.ViewModels;
|
||||
|
||||
@@ -17,6 +20,7 @@ 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 INavigator _navigator;
|
||||
@@ -45,10 +49,12 @@ public partial class CompaniesViewModel : ObservableObject
|
||||
[ObservableProperty]
|
||||
private string _searchQuery = string.Empty;
|
||||
|
||||
public CompaniesViewModel(CompaniesService companiesService, IStringLocalizer localizer,
|
||||
ILogger<CompaniesViewModel> logger, INavigator navigator)
|
||||
public CompaniesViewModel(CompaniesService companiesService, CompanyLogoCache logoCache,
|
||||
IStringLocalizer localizer, ILogger<CompaniesViewModel> logger,
|
||||
INavigator navigator)
|
||||
{
|
||||
_companiesService = companiesService;
|
||||
_logoCache = logoCache;
|
||||
_localizer = localizer;
|
||||
_logger = logger;
|
||||
_navigator = navigator;
|
||||
@@ -98,11 +104,29 @@ public partial class CompaniesViewModel : ObservableObject
|
||||
// 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);
|
||||
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
|
||||
{
|
||||
Id = companyId,
|
||||
Name = company.Name ?? string.Empty,
|
||||
FoundationDate = foundedDate
|
||||
FoundationDate = foundedDate,
|
||||
LogoImageSource = logoSource
|
||||
});
|
||||
}
|
||||
|
||||
@@ -189,6 +213,7 @@ 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 string FoundationDateDisplay =>
|
||||
FoundationDate.HasValue ? FoundationDate.Value.ToString("MMMM d, yyyy") : string.Empty;
|
||||
|
||||
@@ -138,7 +138,7 @@ public partial class CompanyDetailViewModel : ObservableObject
|
||||
OnPropertyChanged(nameof(HasLogoContent));
|
||||
}
|
||||
|
||||
partial void OnCompanyLogosChanged(ObservableCollection<CompanyLogoItem> oldValue,
|
||||
partial void OnCompanyLogosChanged(ObservableCollection<CompanyLogoItem>? oldValue,
|
||||
ObservableCollection<CompanyLogoItem> newValue)
|
||||
{
|
||||
// Notify that HasMultipleLogos has changed
|
||||
|
||||
@@ -97,8 +97,26 @@
|
||||
<Button HorizontalAlignment="Stretch"
|
||||
Command="{Binding DataContext.NavigateToCompanyCommand, ElementName=PageRoot}"
|
||||
CommandParameter="{Binding}">
|
||||
<StackPanel Spacing="4"
|
||||
Padding="8">
|
||||
<Grid ColumnSpacing="12">
|
||||
<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}"
|
||||
FontSize="16"
|
||||
FontWeight="SemiBold" />
|
||||
@@ -106,6 +124,7 @@
|
||||
FontSize="12"
|
||||
Opacity="0.6" />
|
||||
</StackPanel>
|
||||
</Grid>
|
||||
</Button>
|
||||
</DataTemplate>
|
||||
</ItemsRepeater.ItemTemplate>
|
||||
|
||||
Reference in New Issue
Block a user