fix(PostIt): disable links without a reader context
All checks were successful
Dotnet build and test / build (push) Successful in 9m57s

Prevent the Markdown viewer's default browser handler from activating when the blog reader has no view model, while keeping reader links bound to PostIt after context changes.

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
This commit is contained in:
Paul Schneider 2026-10-16 16:16:26 +01:00
commit b90f15333d
Signed by: notazof
GPG key ID: AD4B9B545FBD7D12
6 changed files with 21 additions and 17 deletions

View file

@ -20,16 +20,6 @@
* L'administration est maintenant restreinte aux emails configurés dans les paramétres applicatifs de Yavsc.Org (`appsettings-org.json`)
### Fixed
* [PostIt] Correction du rendu des images incorporées dans les billets :
le résolveur fournit désormais un flux mémoire repositionnable, à son
début, pour éviter l'échec du décodage des images issues d'un flux HTTP.
* [PostIt] Suppression des erreurs de binding au démarrage du lecteur
lorsqu'aucun billet n'est sélectionné ; la commande des liens est
raccordée lors du changement de contexte. Les échecs HTTP des images
sont désormais journalisés avec leur URL dans la catégorie `BlogImages`.
## [1.0.8-rc25] - unstable
### Added

BIN
contrib/blog-edit.png Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 60 KiB

BIN
contrib/blog-view.png Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 64 KiB

View file

@ -130,7 +130,8 @@ public class BlogReaderTests
var page = new BlogsPage();
var reader = page.FindControl<MarkdownScrollViewer>("ArticleReader")!;
var engine = Assert.IsAssignableFrom<IMarkdownEngine2>(reader.Engine);
Assert.Null(engine.HyperlinkCommand);
Assert.NotNull(engine.HyperlinkCommand);
Assert.False(engine.HyperlinkCommand.CanExecute("https://example.test/"));
page.DataContext = vm;
var nav = new NavigationPage();
await nav.PushAsync(page);
@ -152,7 +153,8 @@ public class BlogReaderTests
Dispatcher.UIThread.RunJobs();
Assert.Empty(vm.ReaderTitle);
Assert.Null(vm.ReaderDateModified);
Assert.Null(engine.HyperlinkCommand);
Assert.NotNull(engine.HyperlinkCommand);
Assert.False(engine.HyperlinkCommand.CanExecute("https://example.test/"));
Assert.DoesNotContain(sink.Entries, entry => entry.Area == LogArea.Binding);
}
finally

View file

@ -4,20 +4,32 @@ using Avalonia.Controls;
using Avalonia.Platform.Storage;
using Avalonia.Controls.Primitives;
using Avalonia.Interactivity;
using CommunityToolkit.Mvvm.Input;
using Markdown.Avalonia;
namespace PostIt.Views.Blogs;
public partial class BlogsPage : ContentPage
{
private static readonly RelayCommand<string?> DisabledLinkCommand =
new(static _ => { }, static _ => false);
public BlogsPage()
{
InitializeComponent();
DataContextChanged += (_, _) =>
DataContextChanged += (_, _) => UpdateHyperlinkCommand();
UpdateHyperlinkCommand();
}
private void UpdateHyperlinkCommand()
{
if (ArticleReader.Engine is IMarkdownEngine2 engine)
engine.HyperlinkCommand = (DataContext as ViewModels.BlogsViewModel)?.OpenResourceCommand;
};
{
if (DataContext is ViewModels.BlogsViewModel vm)
engine.HyperlinkCommand = vm.OpenResourceCommand;
else
engine.HyperlinkCommand = DisabledLinkCommand;
}
}
protected override async void OnApplyTemplate(TemplateAppliedEventArgs e)