Skip to content

Commit

Permalink
Code Quality: Renamed PageNavigationEntry
Browse files Browse the repository at this point in the history
  • Loading branch information
0x5bfa committed Jul 31, 2023
1 parent b3b4d73 commit d29e889
Show file tree
Hide file tree
Showing 6 changed files with 56 additions and 43 deletions.
43 changes: 29 additions & 14 deletions src/FluentHub.App/Data/Items/NavigationHistory.cs
Original file line number Diff line number Diff line change
@@ -1,8 +1,6 @@
// Copyright (c) FluentHub
// Licensed under the MIT License. See the LICENSE.

using FluentHub.App.Services;
using Microsoft.Extensions.DependencyInjection;
using Microsoft.UI.Xaml.Controls;

namespace FluentHub.App.Data.Items
Expand All @@ -20,16 +18,28 @@ public NavigationHistory()
}

private bool _CanGoBack;
public bool CanGoBack { get => _CanGoBack; private set => SetProperty(ref _CanGoBack, value); }
public bool CanGoBack
{
get => _CanGoBack;
private set => SetProperty(ref _CanGoBack, value);
}

private bool _CanGoForward;
public bool CanGoForward { get => _CanGoForward; private set => SetProperty(ref _CanGoForward, value); }
public bool CanGoForward
{
get => _CanGoForward;
private set => SetProperty(ref _CanGoForward, value);
}

private PageNavigationEntry? _CurrentItem;
public PageNavigationEntry? CurrentItem { get => _CurrentItem; private set => SetProperty(ref _CurrentItem, value); }
private NavigationHistoryItem? _CurrentItem;
public NavigationHistoryItem? CurrentItem
{
get => _CurrentItem;
private set => SetProperty(ref _CurrentItem, value);
}

private readonly ObservableCollection<PageNavigationEntry> _Items;
public ReadOnlyObservableCollection<PageNavigationEntry> Items { get; }
private readonly ObservableCollection<NavigationHistoryItem> _Items;
public ReadOnlyObservableCollection<NavigationHistoryItem> Items { get; }

private int _CurrentItemIndex;
public int CurrentItemIndex
Expand All @@ -44,22 +54,22 @@ public int CurrentItemIndex
else
throw new ArgumentOutOfRangeException(nameof(value));

_CurrentItemIndex = value;

OnPropertyChanged(nameof(CurrentItemIndex));
SetProperty(ref _CurrentItemIndex, value);
Update();
}
}

public PageNavigationEntry this[int index]
public NavigationHistoryItem this[int index]
=> Items[index];

public bool GoBack()
{
if (CanGoBack)
{
CurrentItemIndex--;

Update();

return true;
}

Expand All @@ -71,22 +81,25 @@ public bool GoForward()
if (CanGoForward)
{
CurrentItemIndex++;

Update();

return true;
}

return false;
}

public void NavigateTo(PageNavigationEntry item)
public void NavigateTo(NavigationHistoryItem item)
{
_Items.Add(item);

CurrentItemIndex = _Items.Count - 1;

Update();
}

public void NavigateTo(PageNavigationEntry item, int index)
public void NavigateTo(NavigationHistoryItem item, int index)
{
// Valid
if (index >= 0 && index <= _Items.Count)
Expand All @@ -108,6 +121,7 @@ public void NavigateTo(PageNavigationEntry item, int index)
public void ClearHistory()
{
_Items.Clear();

CurrentItemIndex = -1;

Update();
Expand All @@ -123,6 +137,7 @@ public static void SetCurrentItem(string header, string description, string url,
{
INavigationService navigationService;
navigationService = App.Current.Services.GetRequiredService<INavigationService>();

var currentItem = navigationService.TabView.SelectedItem.NavigationHistory.CurrentItem;

currentItem.Header = header;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@

namespace FluentHub.App.Data.Items
{
public class PageNavigationEntry : ObservableObject
public class NavigationHistoryItem : ObservableObject
{
private string? _Header;
public string? Header { get => _Header; set => SetProperty(ref _Header, value); }
Expand All @@ -32,5 +32,7 @@ public class PageNavigationEntry : ObservableObject

private FrameNavigationParameter? _Context;
public FrameNavigationParameter? Context { get => _Context; set => SetProperty(ref _Context, value); }

public bool NewlyCreated { get; set; }
}
}
2 changes: 1 addition & 1 deletion src/FluentHub.App/Data/Items/TabViewItem.cs
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ private void OnFrameNavigating(object sender, NavigatingCancelEventArgs e)
switch (e.NavigationMode)
{
case NavigationMode.New:
NavigationHistory.NavigateTo(new PageNavigationEntry(), NavigationHistory.CurrentItemIndex + 1);
NavigationHistory.NavigateTo(new NavigationHistoryItem(), NavigationHistory.CurrentItemIndex + 1);
break;
case NavigationMode.Back:
NavigationHistory.GoBack();
Expand Down
4 changes: 2 additions & 2 deletions src/FluentHub.App/Services/INavigationService.cs
Original file line number Diff line number Diff line change
Expand Up @@ -38,9 +38,9 @@ public interface INavigationService

bool CanGoForward();

PageNavigationEntry GetCurrentTabItem();
NavigationHistoryItem GetCurrentTabItem();

void SetCurrentTabItem(PageNavigationEntry newEntry);
void SetCurrentTabItem(NavigationHistoryItem newEntry);

public void SaveContextToCurrentTabItem(FrameNavigationParameter context);
}
Expand Down
12 changes: 4 additions & 8 deletions src/FluentHub.App/Services/NavigationService.cs
Original file line number Diff line number Diff line change
Expand Up @@ -75,9 +75,7 @@ public void GoBack()
{
EnsureConfigured();

var tab = TabView.SelectedItem;
if (tab is null)
throw new InvalidOperationException("No tab selected");
var tab = TabView.SelectedItem ?? throw new InvalidOperationException("No tab selected");

tab.Frame.GoBack();
}
Expand All @@ -86,9 +84,7 @@ public void GoForward()
{
EnsureConfigured();

var tab = TabView.SelectedItem;
if (tab is null)
throw new InvalidOperationException("No tab selected");
var tab = TabView.SelectedItem ?? throw new InvalidOperationException("No tab selected");

tab.Frame.GoForward();
}
Expand All @@ -107,12 +103,12 @@ public bool CanGoForward()
return TabView.SelectedItem?.Frame?.CanGoForward == true;
}

public PageNavigationEntry GetCurrentTabItem()
public NavigationHistoryItem GetCurrentTabItem()
{
return TabView.SelectedItem.NavigationHistory.CurrentItem;
}

public void SetCurrentTabItem(PageNavigationEntry newEntry)
public void SetCurrentTabItem(NavigationHistoryItem newEntry)
{
var currentItem = TabView.SelectedItem.NavigationHistory.CurrentItem;

Expand Down
34 changes: 17 additions & 17 deletions src/FluentHub.App/Views/Users/OverviewPage.xaml.cs
Original file line number Diff line number Diff line change
Expand Up @@ -6,24 +6,24 @@

namespace FluentHub.App.Views.Users
{
public sealed partial class OverviewPage : LocatablePage
{
public OverviewViewModel ViewModel { get; }
public sealed partial class OverviewPage : LocatablePage
{
public OverviewViewModel ViewModel { get; }

public OverviewPage()
: base(NavigationBarPageKind.User, NavigationBarItemKey.Overview)
{
InitializeComponent();
public OverviewPage()
: base(NavigationBarPageKind.User, NavigationBarItemKey.Overview)
{
InitializeComponent();

var provider = App.Current.Services;
ViewModel = provider.GetRequiredService<OverviewViewModel>();
}
var provider = App.Current.Services;
ViewModel = provider.GetRequiredService<OverviewViewModel>();
}

protected override void OnNavigatedTo(NavigationEventArgs e)
{
var command = ViewModel.LoadUserOverviewCommand;
if (command.CanExecute(null))
command.Execute(null);
}
}
protected override void OnNavigatedTo(NavigationEventArgs e)
{
var command = ViewModel.LoadUserOverviewCommand;
if (command.CanExecute(null))
command.Execute(null);
}
}
}

0 comments on commit d29e889

Please sign in to comment.