Skip to content

Commit

Permalink
Fixed link not working on the price view
Browse files Browse the repository at this point in the history
  • Loading branch information
leMicin committed Jan 2, 2021
1 parent 6c307d4 commit 2bbf65b
Show file tree
Hide file tree
Showing 6 changed files with 93 additions and 3 deletions.
45 changes: 45 additions & 0 deletions src/Sidekick.Application/Game/Trade/GetTradeUriHandler.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
using System;
using System.Threading;
using System.Threading.Tasks;
using MediatR;
using Sidekick.Domain.Game.Items.Metadatas;
using Sidekick.Domain.Game.Items.Models;
using Sidekick.Domain.Game.Languages;
using Sidekick.Domain.Game.Trade.Queries;
using Sidekick.Domain.Settings;

namespace Sidekick.Application.Game.Trade
{
public class GetTradeUriHandler : IQueryHandler<GetTradeUriQuery, Uri>
{
private readonly IGameLanguageProvider gameLanguageProvider;
private readonly IItemStaticDataProvider itemStaticDataProvider;
private readonly ISidekickSettings settings;

public GetTradeUriHandler(IGameLanguageProvider gameLanguageProvider,
IItemStaticDataProvider itemStaticDataProvider,
ISidekickSettings settings)
{
this.gameLanguageProvider = gameLanguageProvider;
this.itemStaticDataProvider = itemStaticDataProvider;
this.settings = settings;
}

public Task<Uri> Handle(GetTradeUriQuery request, CancellationToken cancellationToken)
{
Uri baseUri;

if (request.Item.Rarity == Rarity.Currency && itemStaticDataProvider.GetId(request.Item) != null)
{
baseUri = gameLanguageProvider.Language.PoeTradeExchangeBaseUrl;
}
else
{

baseUri = gameLanguageProvider.Language.PoeTradeSearchBaseUrl;
}

return Task.FromResult(new Uri(baseUri, $"{settings.LeagueId}/{request.QueryId}"));
}
}
}
33 changes: 33 additions & 0 deletions src/Sidekick.Domain/Game/Trade/Queries/GetTradeUriQuery.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
using System;
using MediatR;
using Sidekick.Domain.Game.Items.Models;

namespace Sidekick.Domain.Game.Trade.Queries
{
/// <summary>
/// Gets the Uri for the specified trade query id
/// </summary>
public class GetTradeUriQuery : IQuery<Uri>
{
/// <summary>
/// Gets the Uri for the specified trade query id
/// </summary>
/// <param name="item">The item for which the uri is for</param>
/// <param name="queryId">The trade query id</param>
public GetTradeUriQuery(Item item, string queryId)
{
Item = item;
QueryId = queryId;
}

/// <summary>
/// The item for which the uri is for
/// </summary>
public Item Item { get; }

/// <summary>
/// The trade query id
/// </summary>
public string QueryId { get; }
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ public static T GetChildOfType<T>(this DependencyObject depObj)
{
if (depObj == null) return null;

for (int i = 0; i < VisualTreeHelper.GetChildrenCount(depObj); i++)
for (var i = 0; i < VisualTreeHelper.GetChildrenCount(depObj); i++)
{
var child = VisualTreeHelper.GetChild(depObj, i);

Expand Down
3 changes: 2 additions & 1 deletion src/Sidekick.Presentation.Wpf/Views/Prices/PriceView.xaml
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@
<ResourceDictionary>
<BooleanToVisibilityConverter x:Key="BooleanToVisibility" />
<converters:StringToVisibilityConverter x:Key="StringToVisibility" />
<converters:NullableToVisibilityConverter x:Key="NullableToVisibilityConverter" />
<converters:ReverseStringToVisibilityConverter x:Key="ReverseStringToVisibility" />
<converters:ReverseBooleanToVisibilityConverter x:Key="ReverseBooleanToVisibility" />
</ResourceDictionary>
Expand Down Expand Up @@ -110,7 +111,7 @@
Visibility="{Binding IsFetching, Converter={StaticResource BooleanToVisibility}}" />

<StackPanel VerticalAlignment="Center" Visibility="{Binding IsFetching, Converter={StaticResource ReverseBooleanToVisibility}}">
<TextBlock>
<TextBlock Visibility="{Binding Uri, Converter={StaticResource NullableToVisibilityConverter}}">
<Hyperlink NavigateUri="{Binding Uri}" RequestNavigate="OpenLink">
<TextBlock Text="{Binding CountString}" />
</Hyperlink>
Expand Down
12 changes: 12 additions & 0 deletions src/Sidekick.Presentation.Wpf/Views/Prices/PriceViewModel.cs
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@
using Sidekick.Domain.Game.Modifiers.Models;
using Sidekick.Domain.Game.Trade;
using Sidekick.Domain.Game.Trade.Models;
using Sidekick.Domain.Game.Trade.Queries;
using Sidekick.Domain.Settings;
using Sidekick.Domain.Settings.Commands;
using Sidekick.Persistence.ItemCategories;
Expand Down Expand Up @@ -560,6 +561,8 @@ private void InitializePropertyFilter<T>(PriceFilterCategory category,
return null;
}

public Uri Uri { get; set; }

public int UpdateCountdown { get; private set; }

public void UpdateDebounce()
Expand Down Expand Up @@ -632,6 +635,15 @@ public async Task UpdateQuery()
await LoadMoreData();
}

if (!string.IsNullOrEmpty(QueryResult.Id))
{
Uri = await mediator.Send(new GetTradeUriQuery(Item, QueryResult.Id));
}
else
{
Uri = null;
}

UpdateCountString();
}

Expand Down
1 change: 0 additions & 1 deletion src/Sidekick.Presentation.Wpf/Views/Prices/Sockets.xaml.cs
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,5 @@ public static void OnPropertyChanged(

self.SocketGroups = sockets;
}

}
}

0 comments on commit 2bbf65b

Please sign in to comment.