Files
Nebula-Auth/NebulaAuth/ViewModel/MainVM_Groups.cs
T
achiez 8ff960189e 1.5.6 Bug fixes and code clean-ups
- Update: Added "Copy Password" to Mafile context menu (if available)
- Update: "Save Password" now pre-fills the current password in the "Login Again" dialog when encryption is enabled
- Fix: Prevented overlapping confirmation cycles in AutoConfirmer
- Fix: Added a Snackbar notification when a confirmation cycle is skipped due to a too frequent timer interval
- Fix: Fixed a rare bug where the previous proxy was used instead of the current one during session refresh
- Fix: Corrected "Session Permanently Expired" message showing on unrelated errors (e.g. network issues)
- UI-Fix: Fixed visual glitch where proxy input appeared non-empty when switching to a mafile-specific proxy
- Cleanup: Refactored and cleaned up codebase, improved styling and formatting via ReSharper
2025-05-02 23:29:24 +03:00

145 lines
3.6 KiB
C#

using System.Collections.ObjectModel;
using System.Linq;
using AchiesUtilities.Extensions;
using CommunityToolkit.Mvvm.ComponentModel;
using CommunityToolkit.Mvvm.Input;
using NebulaAuth.Model;
using NebulaAuth.Model.Entities;
namespace NebulaAuth.ViewModel;
public partial class MainVM //Groups
{
public string? SelectedGroup
{
get => _selectedGroup;
set
{
if (SetProperty(ref _selectedGroup, value))
PerformQuery();
}
}
public string SearchText
{
get => _searchText;
set
{
if (SetProperty(ref _searchText, value))
PerformQuery();
}
}
[ObservableProperty] private ObservableCollection<string> _groups = [];
private string _searchText = string.Empty;
private string? _selectedGroup;
[RelayCommand]
private void AddGroup(string? value)
{
var mafile = SelectedMafile;
if (mafile == null) return;
if (string.IsNullOrEmpty(value)) return;
mafile.Group = value;
Storage.UpdateMafile(mafile);
QueryGroups();
SelectedGroup = value;
OnPropertyChanged(nameof(SelectedMafile)); //For bindings
}
[RelayCommand]
private void AddToGroup(object[]? value)
{
if (value == null) return;
if (value.Length < 2) return;
var group = (string?) value[0];
var mafile = (Mafile?) value[1];
if (group == null || mafile == null) return;
mafile.Group = group;
Storage.UpdateMafile(mafile);
QueryGroups();
PerformQuery();
OnPropertyChanged(nameof(SelectedMafile));
}
[RelayCommand]
private void RemoveGroup(Mafile? mafile)
{
if (mafile?.Group == null) return;
var mafGroup = mafile.Group;
mafile.Group = null;
Storage.UpdateMafile(mafile);
OnPropertyChanged(nameof(SelectedMafile)); //For bindings
QueryGroups();
if (Groups.All(g => g.Equals(mafGroup) == false))
{
SelectedGroup = null;
}
PerformQuery();
}
private void QueryGroups()
{
var groups = Storage.MaFiles
.Where(m => string.IsNullOrWhiteSpace(m.Group) == false)
.Select(m => m.Group)
.Distinct()
.Order()
.ToList();
Groups = new ObservableCollection<string>(groups!);
}
private void PerformQuery()
{
MaacDisplay = false;
if (string.IsNullOrWhiteSpace(SelectedGroup) && string.IsNullOrWhiteSpace(SearchText))
{
MaFiles = Storage.MaFiles;
return;
}
long? searchSteamId = null;
if (long.TryParse(SearchText, out var steamId))
{
searchSteamId = steamId;
}
var query = Storage.MaFiles.AsEnumerable();
if (!string.IsNullOrWhiteSpace(SearchText))
{
query = query.Where(SearchPredicate);
}
if (!string.IsNullOrWhiteSpace(SelectedGroup))
{
query = query.Where(m => m.Group != null && m.Group.Equals(SelectedGroup));
}
var perform = query.ToList();
MaFiles = new ObservableCollection<Mafile>(perform);
SelectedMafile = MaFiles.FirstOrDefault();
return;
bool SearchPredicate(Mafile mafile)
{
return mafile.AccountName.ContainsIgnoreCase(SearchText) || mafile.SteamId.Steam64.Id.Equals(searchSteamId);
}
}
private void ResetQuery()
{
_selectedGroup = null;
_searchText = string.Empty;
PerformQuery();
}
}