Skip to content

Commit

Permalink
feat: use list filters endpoint to get list of marketplace filters
Browse files Browse the repository at this point in the history
  • Loading branch information
nattb8 committed Oct 28, 2024
1 parent 3d92d09 commit 76740e2
Show file tree
Hide file tree
Showing 4 changed files with 30 additions and 17 deletions.
39 changes: 26 additions & 13 deletions Assets/Shared/Scripts/UI/Marketplace/MarketplaceScreen.cs
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
using System;
using System.Collections.Generic;
using System.Linq;
using Cysharp.Threading.Tasks;
using HyperCasual.Core;
using Immutable.Passport;
Expand All @@ -17,12 +18,6 @@ namespace HyperCasual.Runner
/// </summary>
public class MarketplaceScreen : View
{
// Lists of available colours and speeds for filtering
private static readonly List<string> s_Colours = new()
{ "All", "Tropical Indigo", "Cyclamen", "Robin Egg Blue", "Mint", "Mindaro", "Amaranth Pink" };

private static readonly List<string> s_Speeds = new() { "All", "Slow", "Medium", "Fast" };

[SerializeField] private HyperCasualButton m_BackButton;
[SerializeField] private AbstractGameEvent m_BackEvent;
[SerializeField] private HyperCasualButton m_AddButton;
Expand All @@ -36,6 +31,8 @@ public class MarketplaceScreen : View

private StacksApi m_StacksApi = new(new Configuration { BasePath = Config.BASE_URL });
private readonly List<StackBundle> m_Stacks = new();
private List<string> m_Colours = new();
private List<string> m_Speeds = new();
private bool m_IsLoadingMore;
private Page m_Page;

Expand Down Expand Up @@ -80,21 +77,37 @@ private async void OnEnable()
/// <summary>
/// Configures the dropdown filters for colours and speeds.
/// </summary>
private void ConfigureFilters()
private async void ConfigureFilters()
{
var filtersResponse = await m_StacksApi.ListFiltersAsync(
chainName: Config.CHAIN_NAME,
contractAddress: Contract.SKIN);
var filters = filtersResponse.Result.Filters;

// Configure Colours Dropdown
m_ColoursDropdown.ClearOptions();
m_ColoursDropdown.AddOptions(s_Colours);
m_Colours = new List<string> { "All" };
var colourValues = filters.First(f => f.Name == "Colour")
.Values.Select(v => v.Value).ToList();
m_Colours.AddRange(colourValues);
m_ColoursDropdown.AddOptions(m_Colours);
m_ColoursDropdown.value = 0; // Default to "All"
m_ColoursDropdown.onValueChanged.AddListener(delegate
m_ColoursDropdown.onValueChanged.AddListener(_ =>
{
Reset();
LoadStacks();
});

// Configure Speeds Dropdown
m_SpeedDropdown.ClearOptions();
m_SpeedDropdown.AddOptions(s_Speeds);
m_Speeds = new List<string> { "All" };
var speedValues = filters.First(f => f.Name == "Speed")
.Values.Select(v => v.Value).ToList();
speedValues.Sort(); // Sort speed values alphabetically
m_Speeds.AddRange(speedValues);
m_SpeedDropdown.AddOptions(m_Speeds);
m_SpeedDropdown.value = 0; // Default to "All"
m_SpeedDropdown.onValueChanged.AddListener(delegate
m_SpeedDropdown.onValueChanged.AddListener(_ =>
{
Reset();
LoadStacks();
Expand Down Expand Up @@ -172,13 +185,13 @@ private async UniTask<List<StackBundle>> GetStacks()
if (m_ColoursDropdown.value != 0)
filters["Colour"] = new
{
values = new List<string> { s_Colours[m_ColoursDropdown.value] },
values = new List<string> { m_Colours[m_ColoursDropdown.value] },
condition = "eq"
};
if (m_SpeedDropdown.value != 0)
filters["Speed"] = new
{
values = new List<string> { s_Speeds[m_SpeedDropdown.value] },
values = new List<string> { m_Speeds[m_SpeedDropdown.value] },
condition = "eq"
};

Expand Down
2 changes: 1 addition & 1 deletion Assets/Shared/Scripts/UI/UnlockedSkinScreen.cs
Original file line number Diff line number Diff line change
Expand Up @@ -114,7 +114,7 @@ public async void OnEnable()
private async void Craft()
{
CraftState = CraftSkinState.Crafting;

try
{
// Burn tokens and mint a new skin i.e. crafting a skin
Expand Down
4 changes: 2 additions & 2 deletions Packages/packages-lock.json
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@
"dependencies": {
"com.unity.nuget.newtonsoft-json": "3.0.2"
},
"hash": "8d2c06f296ebc97d8dfbf7acb2a81c0fddb16f33"
"hash": "e939167c61926c9302602e70e3bf6551dc2ddcde"
},
"com.immutable.marketplace": {
"version": "https://github.com/immutable/unity-immutable-sdk.git?path=/src/Packages/Marketplace",
Expand Down Expand Up @@ -42,7 +42,7 @@
"com.unity.nuget.newtonsoft-json": "3.2.0",
"com.cysharp.unitask": "2.3.3"
},
"hash": "e8d89db9019ae3d0e2fc6596dbd42c5b04276e00"
"hash": "b136ff40a2b0486fa9057b49b022d4d51581b82c"
},
"com.nobi.roundedcorners": {
"version": "https://github.com/kirevdokimov/Unity-UI-Rounded-Corners.git",
Expand Down
2 changes: 1 addition & 1 deletion ProjectSettings/PackageManagerSettings.asset
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ MonoBehaviour:
m_IsDefault: 0
m_Capabilities: 0
m_ConfigSource: 4
m_UserSelectedRegistryName: npmjs
m_UserSelectedRegistryName: package.openupm.com
m_UserAddingNewScopedRegistry: 0
m_RegistryInfoDraft:
m_Modified: 0
Expand Down

0 comments on commit 76740e2

Please sign in to comment.