44<MainNavButtons />
55
66<form @onsubmit =" @ExecuteSearch" >
7- <input @bind =" searchTerm" placeholder =" Search for mods" >
8- <button type =" submit" disabled =@isLoading >Search</button >
7+ <input @bind =" searchTerm" placeholder =" Search for mods" >
8+ <button type =" submit" disabled =@isLoading >Search</button >
99</form >
1010
11- @if (isLoading )
11+ @if (errorMessage is not null )
1212{
13- <LoadingSpinner />
13+ <p class =" accent-orange" >There was an error searching for mods.</p>
14+ <p class="accent-orange">For help, visit the Discord above, and provide all of the information below.</p>
15+ <SupportInformation />
16+ <p>@errorMessage</p>
1417}
15- else
18+ else if ( mods . Count == 0 )
1619{
17- if (errorMessage is not null )
18- {
19- < p class = " accent-orange" > There was an error searching for mods .< / p >
20- < p class = " accent-orange" > For help , visit the Discord above , and provide all of the information below .< / p >
21- < SupportInformation / >
22- < p > @errorMessage < / p >
20+ <p >No mods were found . Try using different search terms .</p >
2321}
24- else if (mods .Count == 0 )
25- {
26- <p >No mods were found . Try using different search terms .</p >
27- }
28- else
29- {
30- <p >Showing @mods .Count mods </p >
31- @foreach (var mod in mods )
32- {
33- <ModListingComponent Mod = "@mod " />
22+ else
23+ {
24+ <p >Showing @mods .Count mods </p >
25+ @foreach (var mod in mods )
26+ {
27+ <ModListingComponent Mod = "@mod " />
28+ }
3429}
35- }
30+ @if (isLoading )
31+ {
32+ <LoadingSpinner />
3633}
3734
3835@code {
39- private bool isLoading = true ;
36+ private bool isLoading = true ;
37+
38+ private string ? errorMessage ;
4039
41- private string ? errorMessage ;
40+ private GithubModSearchEngine github = new ( " Spore-Community/ModBrowser " ) ;
4241
43- private GithubModSearchEngine github = new ( " Spore-Community/ModBrowser " ) ;
42+ private string searchTerm = " " ;
4443
45- private string searchTerm = " " ;
44+ private List < ModListing > mods = new () ;
4645
47- private List <ModListing > mods = new ();
46+ protected override async Task OnInitializedAsync ()
47+ {
48+ await ExecuteSearch ();
49+ }
4850
49- protected override async Task OnInitializedAsync ()
50- {
51- await ExecuteSearch ();
52- }
51+ private async Task ExecuteSearch ()
52+ {
53+ isLoading = true ;
54+ mods .Clear ();
55+ try
56+ {
57+ await foreach (var mod in github .SearchModsAsync (searchTerm ))
58+ {
59+ mods .Add (mod );
5360
54- private async Task ExecuteSearch ()
55- {
56- isLoading = true ;
57- try
58- {
59- mods = await github .SearchModsAsync (searchTerm );
61+ // When listing all mods, sort by download count
62+ if (searchTerm .Length == 0 )
63+ {
64+ mods = mods .OrderByDescending (mod => mod .DownloadCount ).ToList ();
65+ }
6066
61- // When listing all mods, sort by download count
62- if (searchTerm .Length == 0 )
63- {
64- mods = mods .OrderByDescending (mod => mod .DownloadCount ).ToList ();
65- }
66- }
67- catch (Exception e )
68- {
69- errorMessage = e .Message ;
70- Console .WriteLine (" Spore Mod Browser encountered an error searching for mods. If requested, please provide the information below." );
71- Console .WriteLine (e .ToString ());
72- }
73- isLoading = false ;
74- }
67+ // Refresh UI
68+ StateHasChanged ();
69+ }
70+ }
71+ catch (Exception e )
72+ {
73+ errorMessage = e .Message ;
74+ Console .WriteLine (" Spore Mod Browser encountered an error searching for mods. If requested, please provide the information below." );
75+ Console .WriteLine (e .ToString ());
76+ }
77+ isLoading = false ;
78+ }
7579}
0 commit comments