Skip to content

Commit

Permalink
feat: go to dependency detail
Browse files Browse the repository at this point in the history
  • Loading branch information
AuroraZiling committed May 11, 2024
1 parent 4403133 commit 034310f
Show file tree
Hide file tree
Showing 6 changed files with 43 additions and 4 deletions.
9 changes: 9 additions & 0 deletions src/PipManager/Languages/Lang.Designer.cs

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

3 changes: 3 additions & 0 deletions src/PipManager/Languages/Lang.resx
Original file line number Diff line number Diff line change
Expand Up @@ -762,4 +762,7 @@
<data name="Settings_DetectNonReleaseVersion_Subtitle" xml:space="preserve">
<value>Packages that are in Alpha, Beta, etc. test versions will not be ignored</value>
</data>
<data name="LibraryDetail_Toast_PackageNotFound" xml:space="preserve">
<value>Dependency Not Found</value>
</data>
</root>
3 changes: 3 additions & 0 deletions src/PipManager/Languages/Lang.zh-cn.resx
Original file line number Diff line number Diff line change
Expand Up @@ -762,4 +762,7 @@
<data name="Settings_DetectNonReleaseVersion_Subtitle" xml:space="preserve">
<value>Alpha、Beta等测试版本的包将不会被忽略</value>
</data>
<data name="LibraryDetail_Toast_PackageNotFound" xml:space="preserve">
<value>未在库中找到该依赖</value>
</data>
</root>
28 changes: 25 additions & 3 deletions src/PipManager/ViewModels/Pages/Library/LibraryDetailViewModel.cs
Original file line number Diff line number Diff line change
Expand Up @@ -5,18 +5,24 @@
using System.Collections.ObjectModel;
using PipManager.Services.Environment;
using PipManager.Services.Environment.Response;
using PipManager.Services.Toast;
using PipManager.Views.Pages.Library;
using Wpf.Ui;
using Wpf.Ui.Controls;

namespace PipManager.ViewModels.Pages.Library;

public partial class LibraryDetailViewModel : ObservableObject, INavigationAware
{
private readonly IEnvironmentService _environmentService;
public record LibraryDetailMessage(PackageItem Package);
private readonly INavigationService _navigationService;
private readonly IToastService _toastService;
public record LibraryDetailMessage(PackageItem Package, List<PackageItem> Library);
private bool _isInitialized;

[ObservableProperty]
private PackageItem? _package;
[ObservableProperty] private List<PackageItem>? _library;

#region Contact

Expand All @@ -41,9 +47,11 @@ public record LibraryDetailMessage(PackageItem Package);

#endregion Classifier

public LibraryDetailViewModel(IEnvironmentService environmentService)
public LibraryDetailViewModel(IEnvironmentService environmentService, INavigationService navigationService, IToastService toastService)
{
_environmentService = environmentService;
_navigationService = navigationService;
_toastService = toastService;
WeakReferenceMessenger.Default.Register<LibraryDetailMessage>(this, Receive);
}

Expand All @@ -61,11 +69,25 @@ private void InitializeViewModel()
{
_isInitialized = true;
}

[RelayCommand]
private void NavigateToDependency(string name)
{
var targetPackage = Library!.FirstOrDefault(item => item!.Name == name, null);
if (targetPackage is null)
{
_toastService.Error(Lang.LibraryDetail_Toast_PackageNotFound);
return;
}
_navigationService.NavigateWithHierarchy(typeof(LibraryDetailPage));
WeakReferenceMessenger.Default.Send(new LibraryDetailMessage(targetPackage!, Library!));
}

private void Receive(object recipient, LibraryDetailMessage message)
{
Package = message.Package;

Library = message.Library;

#region Contact

Author = Package.Author!.Count == 0 ? Lang.LibraryDetail_Unknown : string.Join(", ", Package.Author!);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -162,7 +162,7 @@ private void ToDetailPage(object parameter)
if (_library is null) return;
_navigationService.NavigateWithHierarchy(typeof(LibraryDetailPage));
var current = _library.Where(libraryListItem => libraryListItem.Name == parameter as string).ToList()[0];
WeakReferenceMessenger.Default.Send(new LibraryDetailMessage(current));
WeakReferenceMessenger.Default.Send(new LibraryDetailMessage(current, _library));
Log.Information($"[Library] Turn to detail page: {current.Name}");
}

Expand Down
2 changes: 2 additions & 0 deletions src/PipManager/Views/Pages/Library/LibraryDetailPage.xaml
Original file line number Diff line number Diff line change
Expand Up @@ -105,6 +105,7 @@
<Grid.ColumnDefinitions>
<ColumnDefinition Width="300" />
<ColumnDefinition Width="*" />
<ColumnDefinition Width="Auto" />
</Grid.ColumnDefinitions>
<ui:TextBlock
FontTypography="Body"
Expand All @@ -116,6 +117,7 @@
Grid.Column="1"
Margin="3,5,0,5"
Text="{Binding Specifier}" />
<ui:HyperlinkButton Grid.Column="2" Icon="{ui:SymbolIcon Link24}" Content="{I18N {x:Static lang:LangKeys.Library_Operation_Details}}" Command="{Binding ElementName=LibraryDetail, Path=ViewModel.NavigateToDependencyCommand}" CommandParameter="{Binding Name}"></ui:HyperlinkButton>
</Grid>
</DataTemplate>
</ItemsControl.ItemTemplate>
Expand Down

0 comments on commit 034310f

Please sign in to comment.