Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[Environments] Auto reload after Extensions page visit; selectable error text #3589

Merged
merged 11 commits into from
Aug 29, 2024
14 changes: 14 additions & 0 deletions common/Environments/Models/ExtensionsPageLoaded.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
// Copyright (c) Microsoft Corporation.
// Licensed under the MIT License.

using CommunityToolkit.Mvvm.Messaging.Messages;

namespace DevHome.Common.Environments.Models;

public class ExtensionsPageLoaded : ValueChangedMessage<bool>
{
public ExtensionsPageLoaded(bool value)
: base(value)
{
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
using System.Threading.Tasks;
using CommunityToolkit.Mvvm.ComponentModel;
using CommunityToolkit.Mvvm.Input;
using CommunityToolkit.Mvvm.Messaging;
huzaifa-d marked this conversation as resolved.
Show resolved Hide resolved
using CommunityToolkit.WinUI;
using CommunityToolkit.WinUI.Behaviors;
using CommunityToolkit.WinUI.Collections;
Expand All @@ -26,7 +27,7 @@ namespace DevHome.Environments.ViewModels;
/// <summary>
/// The main view model for the landing page of the Environments tool.
/// </summary>
public partial class LandingPageViewModel : ObservableObject, IDisposable
public partial class LandingPageViewModel : ObservableObject, IDisposable, IRecipient<ExtensionsPageLoaded>
{
private readonly ILogger _log = Log.ForContext("SourceContext", nameof(LandingPageViewModel));

Expand All @@ -48,6 +49,8 @@ public partial class LandingPageViewModel : ObservableObject, IDisposable

private bool _wasSyncButtonClicked;

private bool _extensionsPageNavigatedTo;

private string _selectedProvider = string.Empty;

public bool IsLoading { get; set; }
Expand Down Expand Up @@ -111,6 +114,7 @@ public LandingPageViewModel(
_lastSyncTime = _stringResource.GetLocalized("MomentsAgo");
ComputeSystemCardsView = new AdvancedCollectionView(ComputeSystemCards);
ComputeSystemCardsView.SortDescriptions.Add(new SortDescription("IsCardCreating", SortDirection.Descending));
WeakReferenceMessenger.Default.Register<ExtensionsPageLoaded>(this);
}

public void Initialize(StackedNotificationsBehavior notificationQueue)
Expand Down Expand Up @@ -216,7 +220,7 @@ private async Task RunSyncTimmer()
/// <summary>
/// Main entry point for loading the view model.
/// </summary>
public async Task LoadModelAsync(bool useDebugValues = false)
public async Task LoadModelAsync()
{
lock (_lock)
{
Expand All @@ -228,8 +232,10 @@ public async Task LoadModelAsync(bool useDebugValues = false)
// If the page has already loaded once, then we don't need to re-load the compute systems as that can take a while.
// The user can click the sync button to refresh the compute systems. However, there may be new operations that have started
// since the last time the page was loaded. So we need to add those to the view model quickly.
// But if the user navigated to the extensions page, we need to reload the compute systems, since they might
// have enabled/disabled an extension.
SetupCreateComputeSystemOperationForUI();
if (HasPageLoadedForTheFirstTime && !_wasSyncButtonClicked)
if (HasPageLoadedForTheFirstTime && !_wasSyncButtonClicked && !_extensionsPageNavigatedTo)
{
return;
}
Expand Down Expand Up @@ -269,6 +275,7 @@ public async Task LoadModelAsync(bool useDebugValues = false)
{
IsLoading = false;
HasPageLoadedForTheFirstTime = true;
_extensionsPageNavigatedTo = false;
}
}

Expand Down Expand Up @@ -552,4 +559,9 @@ private void UpdateCallToActionText()
CallToActionText = callToActionData.CallToActionText;
CallToActionHyperLinkButtonText = callToActionData.CallToActionHyperLinkText;
}

public void Receive(ExtensionsPageLoaded message)
{
_extensionsPageNavigatedTo = true;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,6 @@ public LandingPage()

private async void OnLoaded(object sender, RoutedEventArgs e)
{
await ViewModel.LoadModelAsync(false);
await ViewModel.LoadModelAsync();
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,9 @@
using System.Threading.Tasks;
using CommunityToolkit.Mvvm.ComponentModel;
using CommunityToolkit.Mvvm.Input;
using CommunityToolkit.Mvvm.Messaging;
huzaifa-d marked this conversation as resolved.
Show resolved Hide resolved
using CommunityToolkit.WinUI;
using DevHome.Common.Environments.Models;
using DevHome.Common.Extensions;
using DevHome.Common.Services;
using Microsoft.UI.Dispatching;
Expand Down Expand Up @@ -69,6 +71,10 @@ public async Task LoadedAsync()
{
await GetInstalledPackagesAndExtensionsAsync();
GetAvailablePackages();

// Send a message to the Environments page to let it know that the Extensions page has been loaded.
// And that the Environments page should update its list of environments.
WeakReferenceMessenger.Default.Send(new ExtensionsPageLoaded(true));
huzaifa-d marked this conversation as resolved.
Show resolved Hide resolved
}

private async void OnExtensionsChanged(object? sender, EventArgs e)
Expand Down
Loading