Skip to content

Commit

Permalink
Added Tag page
Browse files Browse the repository at this point in the history
  • Loading branch information
lpeyr committed Aug 24, 2023
1 parent 1cb949c commit 4809d38
Show file tree
Hide file tree
Showing 4 changed files with 99 additions and 0 deletions.
39 changes: 39 additions & 0 deletions Gavilya/Models/GameList.cs
Original file line number Diff line number Diff line change
Expand Up @@ -84,4 +84,43 @@ public List<GameList> GetSortedGameLists()
todayList, yesterdayList, thisMonthList, otherList
};
}

public List<GameList> GetSortedGameByTag()
{
Dictionary<Tag, List<Game>> tagGamesMap = new Dictionary<Tag, List<Game>>();

// Associate games with their corresponding tags
foreach (var game in this)
{
if (game.Tags != null)
{
foreach (var tag in game.Tags)
{
if (!tagGamesMap.ContainsKey(tag))
{
tagGamesMap[tag] = new List<Game>();
}

tagGamesMap[tag].Add(game);
}
}
}

// Create GameList instances for each tag and add associated games
List<GameList> sortedGameLists = new List<GameList>();
foreach (var kvp in tagGamesMap)
{
var tag = kvp.Key;
var games = kvp.Value;

var gameList = new GameList(tag.Name, tag.HexColorCode);
foreach (var game in games)
{
gameList.Add(game);
}
sortedGameLists.Add(gameList);
}

return sortedGameLists;
}
}
7 changes: 7 additions & 0 deletions Gavilya/ViewModels/LibPageViewModel.cs
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,7 @@ internal class LibPageViewModel : ViewModelBase
public ViewModelBase CurrentViewModel { get => _currentViewModel; set { _currentViewModel = value; OnPropertyChanged(nameof(CurrentViewModel)); } }

public ICommand CardViewCommand { get; }
public ICommand TagViewCommand { get; }
public ICommand ListViewCommand { get; }

public LibPageViewModel(GameList games, List<Tag> tags, MainViewModel mainViewModel)
Expand All @@ -52,6 +53,7 @@ public LibPageViewModel(GameList games, List<Tag> tags, MainViewModel mainViewMo
_currentViewModel = new CardPageViewModel(Games, _tags, _mainViewModel);

CardViewCommand = new RelayCommand(CardView);
TagViewCommand = new RelayCommand(TagView);
ListViewCommand = new RelayCommand(ListView);
}

Expand All @@ -60,6 +62,11 @@ private void CardView(object? obj)
CurrentViewModel = new CardPageViewModel(Games, _tags, _mainViewModel);
}

private void TagView(object? obj)
{
CurrentViewModel = new TagPageViewModel(Games, _tags, _mainViewModel);
}

private void ListView(object? obj)
{
CurrentViewModel = new ListPageViewModel(Games, _tags, _mainViewModel);
Expand Down
49 changes: 49 additions & 0 deletions Gavilya/ViewModels/TagPageViewModel.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,49 @@
/*
MIT License
Copyright (c) Léo Corporation
Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
SOFTWARE.
*/

using Gavilya.Models;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace Gavilya.ViewModels
{
public class TagPageViewModel : ViewModelBase
{
private readonly MainViewModel _mainViewModel;
private readonly List<GameList> _sortedGames;
private readonly List<Tag> _tags;

public List<GameGroupViewModel> GameGroupViewModels => _sortedGames.Where(list => list.Count > 0).Select(list => new GameGroupViewModel(list.Title ?? "", list, _tags, _mainViewModel)).ToList();

public TagPageViewModel(GameList games, List<Tag> tags, MainViewModel mainViewModel)
{
_sortedGames = games.GetSortedGameByTag();
_tags = tags;
_mainViewModel = mainViewModel;
}
}
}
4 changes: 4 additions & 0 deletions Gavilya/Views/LibPageView.xaml
Original file line number Diff line number Diff line change
Expand Up @@ -133,6 +133,7 @@
Padding="5"
VerticalAlignment="Center"
BorderThickness="0"
Command="{Binding TagViewCommand}"
Content="&#xF77D;"
FontFamily="..\Fonts\#FluentSystemIcons-Regular"
FontSize="16"
Expand Down Expand Up @@ -173,6 +174,9 @@
<DataTemplate DataType="{x:Type vm:CardPageViewModel}">
<local:CardPageView />
</DataTemplate>
<DataTemplate DataType="{x:Type vm:TagPageViewModel}">
<local:TagPageView />
</DataTemplate>
<DataTemplate DataType="{x:Type vm:ListPageViewModel}">
<local:ListPageView />
</DataTemplate>
Expand Down

0 comments on commit 4809d38

Please sign in to comment.