Skip to content

Commit

Permalink
NR fix update of selected navigation item - do not execute the comman…
Browse files Browse the repository at this point in the history
…d twice
  • Loading branch information
jbe2277 committed Dec 3, 2023
1 parent c5212f6 commit 2f25a1e
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 20 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -84,18 +84,15 @@ private void ShellViewModelPropertyChanged(object? sender, PropertyChangedEventA
{
if (shellViewModel.CurrentPage is IAddEditFeedView)
{
shellViewModel.SelectedFeed = null;
shellViewModel.SelectedFooterMenu = addFeedNavigationItem;
shellViewModel.SetSelectedFooterMenuCore(addFeedNavigationItem);
}
else if (shellViewModel.CurrentPage is ISettingsView)
{
shellViewModel.SelectedFeed = null;
shellViewModel.SelectedFooterMenu = settingsNavigationItem;
shellViewModel.SetSelectedFooterMenuCore(settingsNavigationItem);
}
else if (shellViewModel.CurrentPage is IFeedView feedView)
{
shellViewModel.SelectedFeed = ((FeedViewModel)feedView.BindingContext!).Feed;
shellViewModel.SelectedFooterMenu = null;
shellViewModel.SetSelectedFeedCore(((FeedViewModel)feedView.BindingContext!).Feed);
}
}
}
Expand Down
35 changes: 21 additions & 14 deletions src/NewsReader/NewsReader.Applications/ViewModels/ShellViewModel.cs
Original file line number Diff line number Diff line change
Expand Up @@ -7,19 +7,16 @@

namespace Waf.NewsReader.Applications.ViewModels;

public class ShellViewModel : ViewModelCore<IShellView>, INavigationService
public class ShellViewModel(IShellView view, IAppInfoService appInfoService) : ViewModelCore<IShellView>(view, false), INavigationService
{
private NavigationItem? selectedFooterMenu;
private ObservableList<Feed> feeds = null!;
private Feed? selectedFeed;
private object? currentPage;
private bool suppressSelectedFooterMenuCommand;
private bool suppressSelectedFeedCommand;

public ShellViewModel(IShellView view, IAppInfoService appInfoService) : base(view, false)
{
AppName = appInfoService.AppName;
}

public string AppName { get; }
public string AppName { get; } = appInfoService.AppName;

public ICommand EditFeedCommand { get; internal set; } = null!;

Expand All @@ -40,16 +37,12 @@ public NavigationItem? SelectedFooterMenu
if (selectedFooterMenu is not null)
{
SelectedFeed = null;
selectedFooterMenu.Command?.Execute(null);
if (!suppressSelectedFooterMenuCommand) selectedFooterMenu.Command?.Execute(null);
}
}
}

public ObservableList<Feed> Feeds
{
get => feeds;
internal set => SetProperty(ref feeds, value);
}
public ObservableList<Feed> Feeds { get => feeds; internal set => SetProperty(ref feeds, value); }

public Feed? SelectedFeed
{
Expand All @@ -60,11 +53,25 @@ public Feed? SelectedFeed
if (selectedFeed is not null)
{
SelectedFooterMenu = null;
ShowFeedViewCommand.Execute(selectedFeed);
if (!suppressSelectedFeedCommand) ShowFeedViewCommand.Execute(selectedFeed);
}
}
}

public void SetSelectedFooterMenuCore(NavigationItem? value)
{
suppressSelectedFooterMenuCommand = true;
SelectedFooterMenu = value;
suppressSelectedFooterMenuCommand = false;
}

public void SetSelectedFeedCore(Feed? value)
{
suppressSelectedFeedCommand = true;
SelectedFeed = value;
suppressSelectedFeedCommand = false;
}

public Task Navigate(IViewModelCore viewModel)
{
ViewCore.CloseFlyout();
Expand Down

0 comments on commit 2f25a1e

Please sign in to comment.