Skip to content

Commit

Permalink
fix music categories opening wrong ones
Browse files Browse the repository at this point in the history
  • Loading branch information
zznty committed Apr 2, 2024
1 parent 6a6375e commit edaa04b
Showing 1 changed file with 25 additions and 12 deletions.
37 changes: 25 additions & 12 deletions MusicX/Controls/Blocks/MusicCategoryBlockControl.xaml.cs
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,12 @@
using System.Windows.Controls;
using Microsoft.Extensions.DependencyInjection;
using System;
using System.Linq;
using System.Web;
using Microsoft.AppCenter.Crashes;
using Wpf.Ui;
using Wpf.Ui.Controls;
using Wpf.Ui.Extensions;

namespace MusicX.Controls.Blocks
{
Expand All @@ -32,10 +37,8 @@ public MusicCategoryBlockControl()

private async void CardAction_Click(object sender, RoutedEventArgs e)
{
var link = Links[0];

await OpenPage(link);

if (GetLinkBySection("recent") is { } link)
await OpenPage(link);
}

private async Task OpenPage(Link link)
Expand Down Expand Up @@ -63,23 +66,33 @@ private async Task OpenPage(Link link)

private async void CardAction_Click_1(object sender, RoutedEventArgs e)
{
var link = Links[1];

await OpenPage(link);
if (GetLinkBySection("my_playlists") is { } link)
await OpenPage(link);
}

private async void CardAction_Click_2(object sender, RoutedEventArgs e)
{
var link = Links[2];

await OpenPage(link);
if (GetLinkBySection("albums") is { } link)
await OpenPage(link);
}

private async void CardAction_Click_3(object sender, RoutedEventArgs e)
{
var link = Links[5];
if (GetLinkBySection("followings") is { } link)
await OpenPage(link);
}

await OpenPage(link);
private Link? GetLinkBySection(string section)
{
var link = Links.FirstOrDefault(b =>
HttpUtility.ParseQueryString(new Uri(b.Url).Query)["section"]
?.Equals(section, StringComparison.OrdinalIgnoreCase) is true);

if (link is null)
StaticService.Container.GetRequiredService<ISnackbarService>().Show("Ошибка",
$"Ссылка {section} не найдена", ControlAppearance.Danger);

return link;
}
}
}

0 comments on commit edaa04b

Please sign in to comment.