Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Added tooltips over currencies #497

Merged
merged 2 commits into from
Jan 27, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 5 additions & 4 deletions src/Sidekick.Apis.Poe/Bulk/BulkTradeService.cs
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
using Sidekick.Apis.Poe.Bulk.Results;
using Sidekick.Apis.Poe.Clients;
using Sidekick.Apis.Poe.Filters;
using Sidekick.Apis.Poe.Static;
using Sidekick.Apis.Poe.Trade.Requests;
using Sidekick.Common.Exceptions;
using Sidekick.Common.Extensions;
Expand All @@ -27,7 +28,7 @@ public class BulkTradeService(

public bool SupportsBulkTrade(Item? item)
{
return item?.Header.Rarity == Rarity.Currency && itemStaticDataProvider.GetId(item.Header) != null;
return item?.Header.Rarity == Rarity.Currency && itemStaticDataProvider.Get(item.Header) != null;
}

public async Task<BulkResponseModel> SearchBulk(Item item)
Expand All @@ -37,8 +38,8 @@ public async Task<BulkResponseModel> SearchBulk(Item item)
var leagueId = await settingsService.GetString(SettingKeys.LeagueId);
var uri = $"{await GetBaseApiUrl(item.Header.Game)}exchange/{leagueId.GetUrlSlugForLeague()}";

var itemId = itemStaticDataProvider.GetId(item.Header);
if (itemId == null)
var staticItem = itemStaticDataProvider.Get(item.Header);
if (staticItem == null)
{
throw new ApiErrorException { AdditionalInformation = ["Sidekick could not find a valid item."], };
}
Expand All @@ -48,7 +49,7 @@ public async Task<BulkResponseModel> SearchBulk(Item item)
var minStock = await settingsService.GetInt(SettingKeys.PriceCheckBulkMinimumStock);

var model = new BulkQueryRequest();
model.Query.Want.Add(itemId);
model.Query.Want.Add(staticItem.Id);
model.Query.Minimum = minStock;

if (currency == null || currency == "chaos_divine")
Expand Down
Original file line number Diff line number Diff line change
@@ -1,12 +1,15 @@
using Sidekick.Apis.Poe.Static.Models;
using Sidekick.Common.Game.Items;
using Sidekick.Common.Initialization;

namespace Sidekick.Apis.Poe
namespace Sidekick.Apis.Poe.Static
{
public interface IItemStaticDataProvider : IInitializableService
{
string? GetImage(string id);

string? GetId(ItemHeader itemHeader);
StaticItem? Get(string id);

StaticItem? Get(ItemHeader itemHeader);
}
}
41 changes: 19 additions & 22 deletions src/Sidekick.Apis.Poe/Static/ItemStaticDataProvider.cs
Original file line number Diff line number Diff line change
Expand Up @@ -17,9 +17,9 @@ public class ItemStaticDataProvider
ISettingsService settingsService
) : IItemStaticDataProvider
{
private Dictionary<string, string> ImageUrls { get; set; } = new();
private Dictionary<string, StaticItem> ByIds { get; } = new();

private Dictionary<string, string> Ids { get; set; } = new();
private Dictionary<string, StaticItem> ByTexts { get; } = new();

/// <inheritdoc/>
public int Priority => 100;
Expand All @@ -32,51 +32,48 @@ public async Task Initialize()
var cacheKey = $"{game.GetValueAttribute()}_StaticData";
var result = await cacheProvider.GetOrSet(cacheKey, () => poeTradeClient.Fetch<StaticItemCategory>(game, gameLanguageProvider.Language, "data/static"), (cache) => cache.Result.Any());

ImageUrls.Clear();
Ids.Clear();
ByTexts.Clear();
ByIds.Clear();
foreach (var category in result.Result)
{
foreach (var entry in category.Entries)
{
if (entry.Id == null || entry.Image == null || entry.Text == null)
if (entry.Id == null! || entry.Image == null || entry.Text == null)
{
continue;
}

ImageUrls.Add(entry.Id, entry.Image);
if (!Ids.ContainsKey(entry.Text))
{
Ids.Add(entry.Text, entry.Id);
}
ByIds.Add(entry.Id, entry);
ByTexts.TryAdd(entry.Text, entry);
}
}
}

public string? GetImage(string id)
{
var result = Get(id);
if (result?.Image == null) return null;

return $"{gameLanguageProvider.Language.PoeCdnBaseUrl}{result.Image.Trim('/')}";
}

public StaticItem? Get(string id)
{
id = id switch
{
"exalt" => "exalted",
_ => id
};

if (string.IsNullOrEmpty(id) || !ImageUrls.TryGetValue(id, out var result))
{
return null;
}

return $"{gameLanguageProvider.Language.PoeCdnBaseUrl}{result.Trim('/')}";
return ByIds.GetValueOrDefault(id);
}

public string? GetId(ItemHeader itemHeader)
public StaticItem? Get(ItemHeader itemHeader)
{
var text = itemHeader.Name ?? itemHeader.Type ?? itemHeader.ApiType;
if (text != null && Ids.TryGetValue(text, out var result))
{
return result;
}
if (text == null) return null;

return null;
return ByTexts.GetValueOrDefault(text);
}
}
}
2 changes: 1 addition & 1 deletion src/Sidekick.Apis.Poe/Static/Models/StaticItem.cs
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ namespace Sidekick.Apis.Poe.Static.Models
{
public class StaticItem
{
public string? Id { get; set; }
public required string Id { get; set; }
public string? Text { get; set; }
public string? Image { get; set; }
}
Expand Down
23 changes: 23 additions & 0 deletions src/Sidekick.Common.Ui/Tooltips/TooltipLeft.razor
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
@using MudBlazor

<MudTooltip Placement="Placement.Left">
<ChildContent>
@ChildContent
</ChildContent>
<TooltipContent>
<div class="-mx-2 -my-1 bg-black py-[2px] px-1 text-white max-w-[15rem] rounded-sm">
@TooltipContent
</div>
</TooltipContent>
</MudTooltip>


@code {

[Parameter]
public RenderFragment? ChildContent { get; set; }

[Parameter]
public RenderFragment? TooltipContent { get; set; }

}
18 changes: 16 additions & 2 deletions src/Sidekick.Modules.Trade/Components/Prices/PriceDisplay.razor
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
@using Sidekick.Apis.Poe.Static
@using Sidekick.Apis.Poe

@if (Small)
Expand All @@ -7,7 +8,12 @@
@if (ImageUrl != null)
{
<TextCaption Class="text-[#a38d6d]">&times;</TextCaption>
<img src="@ImageUrl" class="max-h-5" alt="@Currency" />
<TooltipLeft>
<ChildContent>
<img src="@ImageUrl" class="max-h-5" alt="@Currency"/>
</ChildContent>
<TooltipContent>@CurrencyText</TooltipContent>
</TooltipLeft>
}
</div>
}
Expand All @@ -18,7 +24,12 @@ else
@if (ImageUrl != null)
{
<TextBase Class="text-[#a38d6d]">&times;</TextBase>
<img src="@ImageUrl" class="max-h-10" alt="@Currency" />
<TooltipLeft>
<ChildContent>
<img src="@ImageUrl" class="max-h-10" alt="@Currency"/>
</ChildContent>
<TooltipContent>@CurrencyText</TooltipContent>
</TooltipLeft>
}
</div>
}
Expand All @@ -37,4 +48,7 @@ else
public bool Small { get; set; }

private string? ImageUrl => ItemStaticDataProvider.GetImage(Currency);

private string? CurrencyText => ItemStaticDataProvider.Get(Currency)?.Text;

}
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
@using Sidekick.Apis.Poe.Static
@using Sidekick.Apis.Poe

<div class="flex flex-nowrap gap-1 items-center">
Expand All @@ -8,7 +9,12 @@
@if (ImageUrl != null)
{
<TextBase Class="text-[#a38d6d]">&times;</TextBase>
<img src="@ImageUrl" class="max-h-10" alt="@Currency"/>
<TooltipLeft>
<ChildContent>
<img src="@ImageUrl" class="max-h-10" alt="@Currency"/>
</ChildContent>
<TooltipContent>@CurrencyText</TooltipContent>
</TooltipLeft>
}
</div>

Expand All @@ -27,4 +33,6 @@

private string? ImageUrl => ItemStaticDataProvider.GetImage(Currency);

private string? CurrencyText => ItemStaticDataProvider.Get(Currency)?.Text;

}
Loading