Skip to content

Commit

Permalink
chore: refactor authentication and navigation services
Browse files Browse the repository at this point in the history
Signed-off-by: Russell Camo <[email protected]>
  • Loading branch information
russkyc committed Aug 28, 2023
1 parent 4dbc89d commit 0e1a8a4
Show file tree
Hide file tree
Showing 7 changed files with 20 additions and 43 deletions.
5 changes: 5 additions & 0 deletions GroomWise.Application/ViewModels/AppViewModel.cs
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
// without written, signed consent from the author is strictly prohibited.

using GroomWise.Application.Enums;
using GroomWise.Domain.Enums;
using GroomWise.Infrastructure.Authentication.Enums;
using GroomWise.Infrastructure.Authentication.Interfaces;
using GroomWise.Infrastructure.Navigation.Interfaces;
Expand All @@ -25,9 +26,13 @@ public partial class AppViewModel
[Property]
private ViewModelBase _pageContext;

[Property]
private IList<Role> _authenticatedUserRoles;

partial void OnInitialize()
{
PageContext = DashboardViewModel;
AuthenticatedUserRoles = AuthenticationService.GetSession()?.Roles!;
}

[Command]
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,12 +3,12 @@
// Unauthorized copying or redistribution of all files, in source and binary forms via any medium
// without written, signed consent from the author is strictly prohibited.

using GroomWise.Infrastructure.Authentication.Entities;
using GroomWise.Infrastructure.Authentication.Enums;
using GroomWise.Infrastructure.Authentication.Interfaces;
using GroomWise.Infrastructure.Authentication.Mappers;
using GroomWise.Infrastructure.Database;
using GroomWise.Infrastructure.Encryption.Interfaces;
using GroomWise.Infrastructure.Session.Entities;
using Injectio.Attributes;
using Role = GroomWise.Domain.Enums.Role;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,11 +3,9 @@
// Unauthorized copying or redistribution of all files, in source and binary forms via any medium
// without written, signed consent from the author is strictly prohibited.

using GroomWise.Domain.Entities;
using GroomWise.Domain.Interfaces;
using LiteDB;
using GroomWise.Domain.Enums;

namespace GroomWise.Infrastructure.Session.Entities;
namespace GroomWise.Infrastructure.Authentication.Entities;

public record SessionInfo
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,8 @@
// without written, signed consent from the author is strictly prohibited.

using GroomWise.Domain.Enums;
using GroomWise.Infrastructure.Authentication.Entities;
using GroomWise.Infrastructure.Authentication.Enums;
using GroomWise.Infrastructure.Session.Entities;

namespace GroomWise.Infrastructure.Authentication.Interfaces;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
// without written, signed consent from the author is strictly prohibited.

using GroomWise.Domain.Entities;
using GroomWise.Infrastructure.Session.Entities;
using GroomWise.Infrastructure.Authentication.Entities;
using Mapster;

namespace GroomWise.Infrastructure.Authentication.Mappers;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,9 +8,7 @@ namespace GroomWise.Infrastructure.Navigation.Interfaces;
public interface INavigationService
{
IWindow CurrentWindow { get; }
IPage CurrentPage { get; }
void Add(Enum key, IWindow instance);
void Add(Enum key, IPage instance);
void Navigate(Enum key);
void Navigate(Enum key, bool hidePrevious = true);
void Initialize(SynchronizationContext? context, IWindow? mainWindow);
}
42 changes: 9 additions & 33 deletions GroomWise.Infrastructure/Navigation/NavigationService.cs
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,6 @@ public class NavigationService : INavigationService
private SynchronizationContext? _synchronizationContext;
private Dictionary<Enum, object?>? _views;
private static IWindow? _currentWindow;
private static IPage _currentPage;
private static readonly object Lock = new();

public IWindow CurrentWindow
Expand All @@ -28,35 +27,12 @@ public IWindow CurrentWindow
}
}

public IPage CurrentPage
{
get
{
lock (Lock)
{
return _currentPage;
}
}
private set
{
lock (Lock)
{
_currentPage = value;
}
}
}

public void Add(Enum key, IWindow instance)
{
_views?.Add(key, instance);
}

public void Add(Enum key, IPage instance)
{
_views?.Add(key, instance);
}

public void Navigate(Enum key)
public void Navigate(Enum key, bool hidePrevious = true)
{
_synchronizationContext?.Send(
_ =>
Expand All @@ -65,14 +41,14 @@ public void Navigate(Enum key)
if (view is IWindow window)
{
window.Show();
_currentWindow?.Hide();
_currentWindow = window;
return;
}
if (view is IPage page)
{
CurrentPage = page;
lock (Lock)
{
if (hidePrevious)
{
_currentWindow?.Hide();
}
_currentWindow = window;
}
}
},
null
Expand Down

0 comments on commit 0e1a8a4

Please sign in to comment.