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

App adjustments #320

Merged
merged 5 commits into from
Dec 9, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 5 additions & 5 deletions global.json
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,8 @@
"sdk": {
"allowPrerelease": false
},
"msbuild-sdks": {
"Uno.Sdk": "5.6.0-dev.250",
"Microsoft.Build.NoTargets": "3.7.56"
}
}
"msbuild-sdks": {
"Uno.Sdk": "5.6.0-dev.264",
"Microsoft.Build.NoTargets": "3.7.56"
}
}
2 changes: 1 addition & 1 deletion src/app/MZikmund.App.Core/Services/Account/UserService.cs
Original file line number Diff line number Diff line change
Expand Up @@ -102,7 +102,7 @@ private async Task EnsureIdentityClientAsync()
_identityClient = PublicClientApplicationBuilder
.Create(AuthenticationConstants.ApplicationId)
.WithAuthority(AzureCloudInstance.AzurePublic, AuthenticationConstants.TenantId)
.WithRedirectUri("https://login.microsoftonline.com/common/oauth2/nativeclient")
.WithRedirectUri("http://localhost")
.WithUnoHelpers()
.Build();

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@

namespace MZikmund.ViewModels.Admin;

public class CategoryPickerDialogViewModel : DialogViewModel
public partial class CategoryPickerDialogViewModel : DialogViewModel
{
private readonly Guid[] _initialSelection;
private readonly IMZikmundApi _api;
Expand All @@ -15,6 +15,12 @@ public CategoryPickerDialogViewModel(Guid[] selectedCategoryIds, IMZikmundApi ap
_api = api;
}

[ObservableProperty]
public Category[] _allCategories = Array.Empty<Category>();

[ObservableProperty]
public Category[] _selectedCategories = Array.Empty<Category>();

public override async void OnOpened(ContentDialog contentDialog)
{
try
Expand All @@ -28,8 +34,4 @@ public override async void OnOpened(ContentDialog contentDialog)
// TODO: Handle dialog exception
}
}

public Category[] AllCategories { get; private set; } = Array.Empty<Category>();

public Category[] SelectedCategories { get; set; } = Array.Empty<Category>();
}
62 changes: 32 additions & 30 deletions src/app/MZikmund.App.Core/ViewModels/Admin/PostEditorViewModel.cs
Original file line number Diff line number Diff line change
Expand Up @@ -17,11 +17,34 @@ public partial class PostEditorViewModel : PageViewModel
private readonly ILoadingIndicator _loadingIndicator;
private readonly IPostContentProcessor _postContentProcessor;
private readonly ITimerFactory _timerFactory;
private string _postTitle = "";
private DispatcherQueueTimer? _previewTimer;
private bool _isPreviewDirty = true;

[ObservableProperty]
private string _postContent = "";

[ObservableProperty]
private string _postRouteName = "";

[ObservableProperty]
private string _tags = "";

[ObservableProperty]
private string _postTitle = "";

[ObservableProperty]
private string _htmlPreview = "";

[ObservableProperty]
[NotifyPropertyChangedFor(nameof(CategoriesText))]
private Category[] _categories = Array.Empty<Category>();

[ObservableProperty]
private Post? _post = null;

[ObservableProperty]
private bool _isPublished;

public PostEditorViewModel(IMZikmundApi api, IDialogService dialogService, ILoadingIndicator loadingIndicator, IPostContentProcessor postContentProcessor, ITimerFactory timerFactory)
{
_api = api;
Expand All @@ -31,44 +54,22 @@ public PostEditorViewModel(IMZikmundApi api, IDialogService dialogService, ILoad
_timerFactory = timerFactory;
}

public override string Title => Post?.Title ?? "";

public string PostTitle
partial void OnPostTitleChanged(string value)
{
get => _postTitle;
set
{
_postTitle = value;
PostRouteName = _postTitle.GenerateRouteName();
}
PostRouteName = value.GenerateRouteName();
}

public string PostRouteName { get; set; } = "";

public string Tags { get; set; } = "";

public Category[] Categories { get; set; } = Array.Empty<Category>();

public string PostContent
partial void OnPostContentChanged(string value)
{
get => _postContent;
set
{
if (SetProperty(ref _postContent, value))
{
_isPreviewDirty = true;
}
}
_isPreviewDirty = true;
}

public string HtmlPreview { get; set; } = "";
public override string Title => Post?.Title ?? "";

public string CategoriesText => Categories is null or { Length: 0 } ?
Localizer.Instance.GetString("NoCategoriesSelected") :
string.Join(", ", Categories.Select(c => c.DisplayName));

public Post? Post { get; set; }

[RelayCommand]
private async Task PickCategoriesAsync()
{
Expand Down Expand Up @@ -96,8 +97,8 @@ private async Task SaveAsync()
Post.RouteName = PostRouteName;
Post.Tags = tags;
Post.Categories = Categories;
Post.IsPublished = true;
Post.PublishedDate = DateTimeOffset.UtcNow; // TODO: Don't always publish!
Post.IsPublished = IsPublished;
Post.PublishedDate = Post.PublishedDate ?? DateTimeOffset.UtcNow;
Post.Content = PostContent;

if (Post.Id == Guid.Empty)
Expand Down Expand Up @@ -170,5 +171,6 @@ private void PopulateInfo(Post post)
PostTitle = post.Title;
PostRouteName = post.RouteName;
PostContent = post.Content;
IsPublished = post.PublishedDate is not null; // TODO: This logic is wrong, we should work with post status!
}
}
2 changes: 1 addition & 1 deletion src/app/MZikmund.App/App.xaml.cs
Original file line number Diff line number Diff line change
Expand Up @@ -74,7 +74,7 @@ protected override void OnLaunched(LaunchActivatedEventArgs args)
MainWindow = builder.Window;

#if DEBUG
MainWindow.EnableHotReload();
MainWindow.UseStudio();
#endif

Host = builder.Build();
Expand Down
Original file line number Diff line number Diff line change
@@ -1,16 +1,17 @@
using MZikmund.DataContracts.Blog;
using MZikmund.App.Core.ViewModels.Admin;
using MZikmund.DataContracts.Blog;
using MZikmund.ViewModels.Admin;

namespace MZikmund.Dialogs.Admin;

public sealed partial class CategoryPickerDialog : CategoryPickerDialogBase
public sealed partial class CategoryPickerDialog : CategoryPickerDialogBase, ICategoryPickerDialog
{
public CategoryPickerDialog()
{
InitializeComponent();
}

internal void SetSelectedItems(IEnumerable<Category> itemsToSelect)
public void SetSelectedItems(IEnumerable<Category> itemsToSelect)
{
foreach (var category in itemsToSelect)
{
Expand Down
10 changes: 10 additions & 0 deletions src/app/MZikmund.App/MZikmund.App.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,16 @@
</UnoFeatures>
</PropertyGroup>

<PropertyGroup Condition="'$(TargetFramework)'=='net9.0-windows10.0.22621'">
<!-- Workaround for https://github.com/unoplatform/uno/issues/18552 -->
<PlatformTarget Condition=" '$(PlatformTarget)' == '' AND $(Platform) == 'AnyCPU' AND '$(NETCoreSdkRuntimeIdentifier)' == 'win-x86'">x86</PlatformTarget>
<PlatformTarget Condition=" '$(PlatformTarget)' == '' AND $(Platform) == 'AnyCPU' AND '$(NETCoreSdkRuntimeIdentifier)' == 'win-x64'">x64</PlatformTarget>
<PlatformTarget Condition=" '$(PlatformTarget)' == '' AND $(Platform) == 'AnyCPU' AND '$(NETCoreSdkRuntimeIdentifier)' == 'win-arm64'">arm64</PlatformTarget>
</PropertyGroup>
<ItemGroup>
<EmbeddedResource Include="Templates\PostPreviewTemplate.html" />
</ItemGroup>

<ItemGroup>
<ProjectReference Include="..\MZikmund.App.Core\MZikmund.App.Core.csproj" />
</ItemGroup>
Expand Down
63 changes: 33 additions & 30 deletions src/app/MZikmund.App/Views/Admin/PostEditorView.xaml
Original file line number Diff line number Diff line change
Expand Up @@ -8,78 +8,81 @@
Background="{ThemeResource ApplicationPageBackgroundThemeBrush}"
mc:Ignorable="d">

<Grid
<Grid
Padding="20"
ColumnDefinitions="*, *"
ColumnSpacing="8"
RowDefinitions="Auto, Auto, *, Auto"
RowSpacing="8">
<TextBox
<TextBox
Grid.ColumnSpan="1"
FontSize="20"
Header="Title"
Text="{x:Bind ViewModel.PostTitle, Mode=TwoWay}" />
<TextBox
<TextBox
Grid.Column="1"
Grid.ColumnSpan="1"
FontSize="20"
Header="Route"
Text="{x:Bind ViewModel.PostRouteName, Mode=TwoWay}" />
<StackPanel
<StackPanel
Grid.Row="1"
Grid.Column="1"
Orientation="Vertical">
<TextBlock Text="Categories" />
<Button
<TextBlock Text="Categories" />
<Button
Margin="0,0,0,4"
HorizontalAlignment="Stretch"
Command="{x:Bind ViewModel.PickCategoriesCommand}"
Content="{x:Bind ViewModel.CategoriesText, Mode=OneWay}" />
<TextBlock Text="Tags" />
<TextBox Text="{x:Bind ViewModel.Tags, Mode=TwoWay}" />
<TextBlock Text="Hero image URL" />
<TextBox Text="{x:Bind ViewModel.Post.HeroImageUrl, Mode=TwoWay}" />
<TextBlock Text="Hero image ALT" />
<TextBox Text="{x:Bind ViewModel.Post.HeroImageAlt, Mode=TwoWay}" />
</StackPanel>
<TextBox
<TextBlock Text="Tags" />
<TextBox Text="{x:Bind ViewModel.Tags, Mode=TwoWay}" />
<TextBlock Text="Hero image URL" />
<TextBox Text="{x:Bind ViewModel.Post.HeroImageUrl, Mode=TwoWay}" />
<TextBlock Text="Hero image ALT" />
<TextBox Text="{x:Bind ViewModel.Post.HeroImageAlt, Mode=TwoWay}" />
</StackPanel>
<TextBox
Grid.Row="1"
AcceptsReturn="True"
FontFamily="{StaticResource CodeFont}"
Header="Abstract"
Text="{x:Bind ViewModel.Post.Abstract, Mode=TwoWay}"
TextWrapping="Wrap" />
<TextBox
<TextBox
Grid.Row="2"
AcceptsReturn="True"
FontFamily="{StaticResource CodeFont}"
Header="Content"
Text="{x:Bind ViewModel.PostContent, Mode=TwoWay, UpdateSourceTrigger=PropertyChanged}"
TextWrapping="Wrap" />

<Grid
<Grid
Grid.Row="2"
Grid.Column="1"
RowSpacing="4">
<Grid.RowDefinitions>
<RowDefinition Height="Auto" />
<RowDefinition Height="*" />
</Grid.RowDefinitions>
<TextBlock Text="Preview" />
<ContentControl
<Grid.RowDefinitions>
<RowDefinition Height="Auto" />
<RowDefinition Height="*" />
</Grid.RowDefinitions>
<TextBlock Text="Preview" />
<ContentControl
x:Name="PreviewWebViewContainer"
Grid.Row="1"
HorizontalAlignment="Stretch"
VerticalAlignment="Stretch"
HorizontalContentAlignment="Stretch"
VerticalContentAlignment="Stretch" />
</Grid>
</Grid>

<Button Grid.Row="3" Command="{x:Bind ViewModel.SaveCommand}">
<StackPanel Orientation="Horizontal" Spacing="8">
<SymbolIcon Symbol="Save" />
<TextBlock Text="Save" />
</StackPanel>
</Button>
</Grid>
<StackPanel Orientation="Horizontal" Spacing="8" Grid.Row="3">
<Button Command="{x:Bind ViewModel.SaveCommand}">
<StackPanel Orientation="Horizontal" Spacing="8">
<SymbolIcon Symbol="Save" />
<TextBlock Text="Save" />
</StackPanel>
</Button>
<CheckBox IsChecked="{x:Bind ViewModel.IsPublished, Mode=TwoWay}" Content="Published" Grid.Column="1" />
</StackPanel>
</Grid>
</local:PostEditorViewBase>
2 changes: 1 addition & 1 deletion src/app/MZikmund.App/Views/Admin/PostEditorView.xaml.cs
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ public PostEditorView()
{
InitializeComponent();
// Read the template from the embedded resource
_postPreviewTemplate = typeof(PostEditorView).Assembly.GetManifestResourceStream("MZikmund.App.Assets.PostPreviewTemplate.html")!.ReadToEnd()!;
_postPreviewTemplate = typeof(PostEditorView).Assembly.GetManifestResourceStream("MZikmund.App.Templates.PostPreviewTemplate.html")!.ReadToEnd()!;
PreviewWebViewContainer.Content = _previewWebView = new WebView2();
this.Loaded += PostEditorView_Loaded;
this.Unloaded += PostEditorView_Unloaded;
Expand Down
2 changes: 1 addition & 1 deletion src/app/MZikmund.App/Views/PostView.xaml.cs
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ public PostView()
{
InitializeComponent();
// Read the template from the embedded resource
_postPreviewTemplate = typeof(PostView).Assembly.GetManifestResourceStream("MZikmund.App.Assets.PostPreviewTemplate.html")?.ReadToEnd()!;
_postPreviewTemplate = typeof(PostView).Assembly.GetManifestResourceStream("MZikmund.App.Templates.PostPreviewTemplate.html")?.ReadToEnd()!;
PreviewWebViewContainer.Content = _previewWebView = new WebView2();
this.Loaded += PostEditorView_Loaded;
this.Unloaded += PostEditorView_Unloaded;
Expand Down
1 change: 1 addition & 0 deletions src/app/MZikmund.DataContracts/Blog/Post.cs
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ public string Content
get => _content.ReplaceLineEndings("\r\n");
set => _content = value;
}

public string Abstract { get; set; } = "";

public string? HeroImageUrl { get; set; }
Expand Down
Loading