Skip to content

Commit

Permalink
fix: Crash when pressing enter without selecting a charater when movi…
Browse files Browse the repository at this point in the history
…ng mods.
  • Loading branch information
Jorixon committed Sep 3, 2023
1 parent fcc3e3f commit 6234d01
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 6 deletions.
21 changes: 16 additions & 5 deletions src/GIMI-ModManager.WinUI/ViewModels/SubVms/MoveModsFlyoutVM.cs
Original file line number Diff line number Diff line change
Expand Up @@ -201,12 +201,15 @@ private async Task TextChanged(string searchString)
return;

SuggestedCharacters.Clear();
var eligibleCharacters =
var searchResultKeyValue =
await Task.Run(() =>
_genshinService.GetCharacters(searchString, fuzzRatio: 40).OrderByDescending(kv => kv.Value));
var eligibleCharacters = searchResultKeyValue.Select(kv => kv.Key).Where(ch => ch != _shownCharacter).Take(5);


foreach (var eligibleCharacter in eligibleCharacters)
SuggestedCharacters.Add(eligibleCharacter.Key);
SuggestedCharacters.Add(eligibleCharacter);



if (SuggestedCharacters.Count == 0)
Expand All @@ -221,12 +224,20 @@ private void ResetState()
SearchText = string.Empty;
}

[RelayCommand]
private void SelectCharacter(GenshinCharacter character)
public bool SelectCharacter(GenshinCharacter? character)
{
if (character == _noCharacterFound) return;
if (character == _noCharacterFound) return false;
if (character is null)
{
if (SuggestedCharacters.Any(ch => ch != _noCharacterFound))
character = SuggestedCharacters.First(ch => ch != _noCharacterFound);
else
return false;
}

SuggestedCharacters.Clear();
SelectedCharacter = character;
SearchText = character.DisplayName;
return true;
}
}
4 changes: 3 additions & 1 deletion src/GIMI-ModManager.WinUI/Views/CharacterDetailsPage.xaml.cs
Original file line number Diff line number Diff line change
Expand Up @@ -334,8 +334,10 @@ private void MoveRowFlyout_OnClosed(object? sender, object e)

private void MoveModSearch_OnQuerySubmitted(AutoSuggestBox sender, AutoSuggestBoxQuerySubmittedEventArgs args)
{
var anyCharacterFound = ViewModel.MoveModsFlyoutVM.SelectCharacter(args.ChosenSuggestion as GenshinCharacter);
if (!anyCharacterFound)
return;
sender.IsEnabled = false;
ViewModel.MoveModsFlyoutVM.SelectCharacterCommand.Execute(args.ChosenSuggestion);
MoveModsButton.Focus(FocusState.Programmatic);
}
}

0 comments on commit 6234d01

Please sign in to comment.