Skip to content

Commit 378649b

Browse files
committed
Fix stash tabs being appended to the list instead of replacing the list
1 parent 08f89c1 commit 378649b

File tree

2 files changed

+30
-35
lines changed

2 files changed

+30
-35
lines changed

EnhancePoE/Model/ApiAdapter.cs

Lines changed: 9 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -19,9 +19,7 @@ public static class ApiAdapter
1919
public static bool FetchError { get; set; }
2020
public static bool FetchingDone { get; set; }
2121

22-
public static List<StashTab> StashTabList { get; private set; }
23-
24-
public static async Task<bool> GenerateUri()
22+
public static async Task<List<StashTab>> FetchStashTabs()
2523
{
2624
FetchError = false;
2725
FetchingDone = false;
@@ -34,30 +32,21 @@ public static async Task<bool> GenerateUri()
3432

3533
if ( await GetProps( accName, league ) && !FetchError )
3634
{
37-
StashTabList = PropsList.tabs.ConvertAll( x => new StashTab( x.n, x.i ) );
38-
GenerateStashtabUris( accName, league );
39-
return true;
35+
var stashTabs = PropsList.tabs.ConvertAll( x => new StashTab( x.n, x.i ) );
36+
for ( int i = 0; i < stashTabs.Count; i++ )
37+
{
38+
stashTabs[i].StashTabUri = new Uri( $"https://www.pathofexile.com/character-window/get-stash-items?accountName={accName}&tabIndex={i}&league={league}" );
39+
}
40+
41+
return stashTabs;
4042
}
4143
}
4244
else
4345
{
4446
_ = MessageBox.Show( "Missing Settings!" + Environment.NewLine + "Please set Accountname, Stash Tab and League." );
4547
}
4648
IsFetching = false;
47-
return false;
48-
}
49-
50-
private static void GenerateStashtabUris( string accName, string league )
51-
{
52-
if ( StashTabList is null )
53-
{
54-
return;
55-
}
56-
57-
for ( int i = 0; i < StashTabList.Count; i++ )
58-
{
59-
StashTabList[i].StashTabUri = new Uri( $"https://www.pathofexile.com/character-window/get-stash-items?accountName={accName}&tabIndex={i}&league={league}" );
60-
}
49+
return null;
6150
}
6251

6352
private static async Task<bool> GetProps( string accName, string league )

EnhancePoE/View/MainWindow.xaml.cs

Lines changed: 21 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -305,31 +305,37 @@ private async Task LoadStashTabsAsync()
305305
StashTabComboBox.IsEnabled = false;
306306

307307
SelectedStashTab = null;
308-
if ( await ApiAdapter.GenerateUri() )
308+
var stashTabs = await ApiAdapter.FetchStashTabs();
309+
if ( stashTabs is not null )
309310
{
310-
foreach ( var stashTab in ApiAdapter.StashTabList )
311+
StashTabList.Clear();
312+
foreach ( var tab in stashTabs )
311313
{
312-
StashTabList.Add( stashTab );
314+
StashTabList.Add( tab );
313315
}
314-
}
315316

316-
if ( StashTabList.Count > 0 )
317-
{
318-
var selectedStashTabName = Properties.Settings.Default.SelectedStashTabName;
319-
if ( !string.IsNullOrEmpty( selectedStashTabName ) )
317+
if ( stashTabs.Count > 0 )
320318
{
321-
var previouslySelectedStashTab = StashTabList.FirstOrDefault( x => x.TabName == selectedStashTabName );
322-
if ( previouslySelectedStashTab is not null )
319+
var selectedStashTabName = Properties.Settings.Default.SelectedStashTabName;
320+
if ( !string.IsNullOrEmpty( selectedStashTabName ) )
323321
{
324-
SelectedStashTab = previouslySelectedStashTab;
322+
var previouslySelectedStashTab = StashTabList.FirstOrDefault( x => x.TabName == selectedStashTabName );
323+
if ( previouslySelectedStashTab is not null )
324+
{
325+
SelectedStashTab = previouslySelectedStashTab;
326+
}
325327
}
326-
}
327328

328-
if ( SelectedStashTab is null )
329-
{
330-
SelectedStashTab = StashTabList[0];
329+
if ( SelectedStashTab is null )
330+
{
331+
SelectedStashTab = StashTabList[0];
332+
}
331333
}
332334
}
335+
else
336+
{
337+
_ = MessageBox.Show( "Failed to fetch stash tabs", "Request Failed", MessageBoxButton.OK, MessageBoxImage.Error );
338+
}
333339

334340
FetchStashTabsButton.IsEnabled = true;
335341
StashTabComboBox.IsEnabled = true;

0 commit comments

Comments
 (0)