From a3aa2db9cf7fc7d068a6747afce383d560679834 Mon Sep 17 00:00:00 2001 From: Stefan Frijters Date: Sat, 28 Sep 2024 09:51:39 +0200 Subject: [PATCH] Prevent crash when a game does not have categories yet --- .../ViewModels/GameDetailViewModel.cs | 28 ++++++++++++------- 1 file changed, 18 insertions(+), 10 deletions(-) diff --git a/SpeedrunTracker/ViewModels/GameDetailViewModel.cs b/SpeedrunTracker/ViewModels/GameDetailViewModel.cs index d15baca..916675f 100644 --- a/SpeedrunTracker/ViewModels/GameDetailViewModel.cs +++ b/SpeedrunTracker/ViewModels/GameDetailViewModel.cs @@ -214,19 +214,27 @@ public async Task LoadLeaderboardAsync() LeaderboardEntries.Clear(); List variableValues = new(); - foreach (VariableViewModel vm in Variables) - variableValues.Add($"var-{vm.VariableId}={vm.SelectedValue.Id}"); - string variables = string.Join('&', variableValues); + string variables = string.Empty; - if (!string.IsNullOrEmpty(variables)) - variables = $"&{variables}"; + if (Variables != null) + { + foreach (VariableViewModel vm in Variables) + variableValues.Add($"var-{vm.VariableId}={vm.SelectedValue.Id}"); + variables = string.Join('&', variableValues); + } - _leaderboard = string.IsNullOrEmpty(SelectedLevel.Id) ? - await ExecuteNetworkTask(_leaderboardService.GetFullGameLeaderboardAsync(Game.Id, SelectedCategory.Id, variables, _settingsService.UserSettings.MaxLeaderboardResults)) : - await ExecuteNetworkTask(_leaderboardService.GetLevelLeaderboardAsync(Game.Id, SelectedLevel.Id, SelectedCategory.Id, variables, _settingsService.UserSettings.MaxLeaderboardResults)); + if (SelectedCategory != null) + { + if (!string.IsNullOrEmpty(variables)) + variables = $"&{variables}"; - if (_leaderboard != null) - DisplayLeaderboardEntries(); + _leaderboard = string.IsNullOrEmpty(SelectedLevel.Id) ? + await ExecuteNetworkTask(_leaderboardService.GetFullGameLeaderboardAsync(Game.Id, SelectedCategory.Id, variables, _settingsService.UserSettings.MaxLeaderboardResults)) : + await ExecuteNetworkTask(_leaderboardService.GetLevelLeaderboardAsync(Game.Id, SelectedLevel.Id, SelectedCategory.Id, variables, _settingsService.UserSettings.MaxLeaderboardResults)); + + if (_leaderboard != null) + DisplayLeaderboardEntries(); + } IsLoadingLeaderboard = false; }