Revert "feat(blog): add Visibility { Private, Public } to gate post reads"
This reverts commit 33ecfa7ebd.
This commit is contained in:
parent
33ecfa7ebd
commit
42625f5ddd
16 changed files with 46 additions and 5427 deletions
|
|
@ -1,21 +1,11 @@
|
|||
<Application xmlns="https://github.com/avaloniaui"
|
||||
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
|
||||
xmlns:local="using:PostIt"
|
||||
xmlns:views="using:PostIt.Views"
|
||||
x:Class="PostIt.App">
|
||||
|
||||
|
||||
<Application.DataTemplates>
|
||||
<local:ViewLocator/>
|
||||
</Application.DataTemplates>
|
||||
|
||||
<Application.Resources>
|
||||
<!-- French labels for the Visibility enum. Used by the
|
||||
ComboBox ItemTemplate in MainPage.axaml. The list
|
||||
of available values lives on MainPageViewModel
|
||||
(AllVisibilities) rather than here — x:Array is
|
||||
awkward to author in Avalonia XAML. -->
|
||||
<views:VisibilityLabelConverter x:Key="VisibilityLabelConverter"/>
|
||||
</Application.Resources>
|
||||
</Application.DataTemplates>
|
||||
|
||||
<Application.Styles>
|
||||
<FluentTheme />
|
||||
|
|
|
|||
|
|
@ -1,5 +1,4 @@
|
|||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Collections.ObjectModel;
|
||||
using System.Linq;
|
||||
using System.Threading.Tasks;
|
||||
|
|
@ -36,25 +35,6 @@ public partial class MainPageViewModel : ViewModelBase
|
|||
[ObservableProperty]
|
||||
public partial string DraftArticle { get; set; }
|
||||
|
||||
/// <summary>Editor buffer for the post visibility. Same
|
||||
/// pattern as <see cref="DraftTitle"/> and
|
||||
/// <see cref="DraftArticle"/>: the Save command reads from
|
||||
/// here so the user can flip a draft to Public without
|
||||
/// selecting an existing post first. Defaults to
|
||||
/// <see cref="Visibility.Private"/> on a fresh draft so
|
||||
/// new posts are private-by-default, matching the server
|
||||
/// contract.</summary>
|
||||
[ObservableProperty]
|
||||
public partial Visibility DraftVisibility { get; set; } = Visibility.Private;
|
||||
|
||||
/// <summary>List of values offered in the visibility
|
||||
/// ComboBox. Exposed as a VM property (rather than an
|
||||
/// <c>x:Array</c> resource) because Avalonia XAML doesn't
|
||||
/// author <c>x:Array</c> cleanly. Order: Private first,
|
||||
/// matching the server default.</summary>
|
||||
public IReadOnlyList<Visibility> AllVisibilities { get; } =
|
||||
new[] { Visibility.Private, Visibility.Public };
|
||||
|
||||
[ObservableProperty]
|
||||
public partial ViewModelBase? CurrentViewModel { get; set; }
|
||||
|
||||
|
|
@ -122,7 +102,6 @@ public partial class MainPageViewModel : ViewModelBase
|
|||
WindowTitle = "PostIt";
|
||||
DraftTitle = string.Empty;
|
||||
DraftArticle = string.Empty;
|
||||
DraftVisibility = Visibility.Private;
|
||||
CurrentViewModel = this;
|
||||
}
|
||||
|
||||
|
|
@ -152,9 +131,6 @@ public partial class MainPageViewModel : ViewModelBase
|
|||
// doesn't show stale content.
|
||||
DraftTitle = value?.Title ?? string.Empty;
|
||||
DraftArticle = value?.Article ?? string.Empty;
|
||||
// Mirror visibility too. Defaults to Private on null
|
||||
// selection so a fresh draft starts private.
|
||||
DraftVisibility = value?.Visibility ?? Visibility.Private;
|
||||
UpdateCommandStates();
|
||||
}
|
||||
|
||||
|
|
@ -219,7 +195,6 @@ public partial class MainPageViewModel : ViewModelBase
|
|||
Article = DraftArticle ?? string.Empty,
|
||||
DateCreated = DateTime.UtcNow,
|
||||
DateModified = DateTime.UtcNow,
|
||||
Visibility = DraftVisibility,
|
||||
};
|
||||
var created = await BlogClient.CreatePostAsync(draft);
|
||||
if (created is not null)
|
||||
|
|
@ -239,7 +214,6 @@ public partial class MainPageViewModel : ViewModelBase
|
|||
Article = DraftArticle ?? string.Empty,
|
||||
DateCreated = SelectedPost.DateCreated,
|
||||
DateModified = DateTime.UtcNow,
|
||||
Visibility = DraftVisibility,
|
||||
};
|
||||
await BlogClient.UpdatePostAsync(SelectedPost.Id, update);
|
||||
StatusMessage = $"Saved post {SelectedPost.Id}.";
|
||||
|
|
|
|||
|
|
@ -81,26 +81,7 @@
|
|||
|
||||
<TextBlock Grid.Row="0" Text="Post detail" FontWeight="SemiBold" />
|
||||
<TextBox Grid.Row="1" Text="{Binding DraftTitle, Mode=TwoWay}" PlaceholderText="Title" />
|
||||
<!-- Visibility toggle: a ComboBox bound to the
|
||||
Yavsc.Blogspot.Visibility enum (Private /
|
||||
Public). The enum serialises as int on the
|
||||
wire; user-facing labels come from the
|
||||
visibility label converter registered in
|
||||
App.axaml. Default is Visibility.Private
|
||||
(set on DraftVisibility), so a fresh draft
|
||||
is private by default. -->
|
||||
<StackPanel Grid.Row="2" Orientation="Horizontal" Spacing="8">
|
||||
<TextBlock Text="Visibilité :" VerticalAlignment="Center"/>
|
||||
<ComboBox SelectedItem="{Binding DraftVisibility, Mode=TwoWay}"
|
||||
ItemsSource="{Binding AllVisibilities}">
|
||||
<ComboBox.ItemTemplate>
|
||||
<DataTemplate x:DataType="models:Visibility">
|
||||
<TextBlock Text="{Binding Converter={StaticResource VisibilityLabelConverter}}"/>
|
||||
</DataTemplate>
|
||||
</ComboBox.ItemTemplate>
|
||||
</ComboBox>
|
||||
</StackPanel>
|
||||
<AvaloniaEdit:TextEditor Grid.Row="3"
|
||||
<AvaloniaEdit:TextEditor Grid.Row="2"
|
||||
views:TextEditorBinding.Text="{Binding DraftArticle, Mode=TwoWay}"
|
||||
ShowLineNumbers="True"
|
||||
FontFamily="Cascadia Code, Consolas, Menlo, Monospace"
|
||||
|
|
@ -109,7 +90,7 @@
|
|||
VerticalAlignment="Stretch"
|
||||
VerticalScrollBarVisibility="Auto"
|
||||
HorizontalScrollBarVisibility="Auto" />
|
||||
<TextBlock Grid.Row="4" Text="{Binding StatusMessage}" Foreground="Gray" />
|
||||
<TextBlock Grid.Row="3" Text="{Binding StatusMessage}" Foreground="Gray" />
|
||||
</Grid>
|
||||
</Border>
|
||||
</Grid>
|
||||
|
|
|
|||
|
|
@ -1,56 +0,0 @@
|
|||
using System;
|
||||
using System.Globalization;
|
||||
using Avalonia.Data.Converters;
|
||||
using Yavsc.Blogspot;
|
||||
|
||||
namespace PostIt.Views;
|
||||
|
||||
/// <summary>
|
||||
/// Converts a <see cref="Visibility"/> enum value to a user-
|
||||
/// facing French label. Used by <c>MainPage.axaml</c> to render
|
||||
/// the visibility ComboBox without exposing the raw enum name
|
||||
/// ("Private" / "Public") to the end user.
|
||||
///
|
||||
/// <para>Bidirectional: <c>ConvertBack</c> returns the value
|
||||
/// unchanged, so the ComboBox can drive the bound
|
||||
/// <c>DraftVisibility</c> property directly through the same
|
||||
/// converter — the ComboBox just happens to use
|
||||
/// <c>SelectedItem</c> binding so ConvertBack is never
|
||||
/// invoked. The symmetry is kept for completeness in case a
|
||||
/// future XAML needs to bind via <c>Text</c>.</para>
|
||||
/// </summary>
|
||||
public sealed class VisibilityLabelConverter : IValueConverter
|
||||
{
|
||||
public object? Convert(object? value, Type targetType, object? parameter, CultureInfo culture)
|
||||
{
|
||||
if (value is Visibility v)
|
||||
{
|
||||
return v switch
|
||||
{
|
||||
Visibility.Private => "Privé",
|
||||
Visibility.Public => "Public",
|
||||
_ => v.ToString(),
|
||||
};
|
||||
}
|
||||
return value;
|
||||
}
|
||||
|
||||
public object? ConvertBack(object? value, Type targetType, object? parameter, CultureInfo culture)
|
||||
{
|
||||
// Reverse mapping: user input is unlikely to be the
|
||||
// raw English enum name (the ComboBox shows French
|
||||
// labels), so ConvertBack falls back to Private on any
|
||||
// unrecognised input. The ComboBox uses SelectedItem
|
||||
// binding so this path is never actually taken today.
|
||||
if (value is string s)
|
||||
{
|
||||
return s switch
|
||||
{
|
||||
"Privé" => Visibility.Private,
|
||||
"Public" => Visibility.Public,
|
||||
_ => Visibility.Private,
|
||||
};
|
||||
}
|
||||
return value;
|
||||
}
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue