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

Add ReadmeUriTemplateResource for download README from remote sources. #6136

Merged
merged 14 commits into from
Nov 23, 2024
Original file line number Diff line number Diff line change
Expand Up @@ -18,23 +18,41 @@ public sealed class ReadmePreviewViewModel : TitledPageViewModelBase
private string _rawReadme;
private DetailedPackageMetadata _packageMetadata;
private bool _canRenderLocalReadme;
private bool _isBusy;

public ReadmePreviewViewModel(INuGetPackageFileService packageFileService, ItemFilter itemFilter, bool isReadmeFeatureEnabled)
{
_nugetPackageFileService = packageFileService ?? throw new ArgumentNullException(nameof(packageFileService));
_canRenderLocalReadme = CanRenderLocalReadme(itemFilter);
_nugetPackageFileService = packageFileService;
_errorLoadingReadme = false;
_isBusy = false;
_rawReadme = string.Empty;
_packageMetadata = null;
Title = Resources.Label_Readme_Tab;
IsVisible = isReadmeFeatureEnabled;
}

public bool IsReadmeReady { get => !IsBusy && !ErrorLoadingReadme; }

public bool ErrorLoadingReadme
jgonz120 marked this conversation as resolved.
Show resolved Hide resolved
{
get => _errorLoadingReadme;
set => SetAndRaisePropertyChanged(ref _errorLoadingReadme, value);
set
{
SetAndRaisePropertyChanged(ref _errorLoadingReadme, value);
RaisePropertyChanged(nameof(IsReadmeReady));
}
}

public bool IsBusy
{
get => _isBusy;
set
{
SetAndRaisePropertyChanged(ref _isBusy, value);
RaisePropertyChanged(nameof(IsReadmeReady));
}
}

public string ReadmeMarkdown
Expand Down Expand Up @@ -72,12 +90,13 @@ private static bool CanRenderLocalReadme(ItemFilter filter)

private async Task LoadReadmeAsync(CancellationToken cancellationToken)
{
ReadmeMarkdown = Resources.Text_Loading;
IsBusy = true;
jgonz120 marked this conversation as resolved.
Show resolved Hide resolved
if (string.IsNullOrWhiteSpace(_packageMetadata.ReadmeFileUrl))
{
ReadmeMarkdown = _canRenderLocalReadme && !string.IsNullOrWhiteSpace(_packageMetadata.PackagePath) ? Resources.Text_NoReadme : string.Empty;
IsVisible = !string.IsNullOrWhiteSpace(ReadmeMarkdown);
ErrorLoadingReadme = false;
IsBusy = false;
return;
}

Expand All @@ -87,6 +106,7 @@ private async Task LoadReadmeAsync(CancellationToken cancellationToken)
ReadmeMarkdown = string.Empty;
IsVisible = false;
ErrorLoadingReadme = false;
IsBusy = false;
return;
}

Expand All @@ -111,6 +131,7 @@ await ThreadHelper.JoinableTaskFactory.RunAsync(async () =>
ReadmeMarkdown = readme;
IsVisible = !string.IsNullOrWhiteSpace(readme);
ErrorLoadingReadme = false;
IsBusy = false;
}
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,8 @@
xmlns:imagingTheme="clr-namespace:Microsoft.VisualStudio.PlatformUI;assembly=Microsoft.VisualStudio.Imaging"
xmlns:catalog="clr-namespace:Microsoft.VisualStudio.Imaging;assembly=Microsoft.VisualStudio.ImageCatalog"
xmlns:ui="clr-namespace:Microsoft.VisualStudio.PlatformUI;assembly=Microsoft.VisualStudio.Utilities"
Background="{DynamicResource {x:Static nuget:Brushes.DetailPaneBackground}}"
Foreground="{DynamicResource {x:Static nuget:Brushes.UIText}}"
DataContextChanged="UserControl_DataContextChanged"
Unloaded="PackageReadmeControl_Unloaded"
Loaded="PackageReadmeControl_Loaded"
Expand All @@ -28,8 +30,13 @@
x:Uid="descriptionMarkdownPreview"
ClipToBounds="True"
Focusable="False"
Visibility="{Binding Path=ErrorLoadingReadme, Mode=OneWay, Converter={StaticResource NegatedBooleanToVisibilityConverter}}"
Visibility="{Binding Path=IsReadmeReady, Mode=OneWay, Converter={StaticResource BooleanToVisibilityConverter}}"
/>
<TextBlock
TextWrapping="Wrap"
Text="{x:Static nuget:Resources.Text_Loading}"
Visibility="{Binding Path=IsBusy, Mode=OneWay, Converter={StaticResource BooleanToVisibilityConverter}}"
/>
<TextBlock
TextWrapping="Wrap"
Text="{x:Static nuget:Resources.Error_UnableToLoadReadme}"
Expand Down
Loading