From c2e1a975d8a1018422ec107a7a9b9987302b7cd2 Mon Sep 17 00:00:00 2001 From: Flaky Date: Thu, 16 Apr 2026 14:02:39 +0100 Subject: [PATCH] fix datetime not updating while live + parents not updating in some areas after migration to usercontrols --- UI/TagDatabaseService.cs | 6 ++++++ UI/ViewModels/MainWindowViewModel.cs | 7 +++++-- UI/ViewModels/RecentsViewModel.cs | 9 +++++++-- UI/ViewModels/SearchViewModel.cs | 9 ++++++--- 4 files changed, 24 insertions(+), 7 deletions(-) diff --git a/UI/TagDatabaseService.cs b/UI/TagDatabaseService.cs index 6899078..a20066c 100644 --- a/UI/TagDatabaseService.cs +++ b/UI/TagDatabaseService.cs @@ -157,6 +157,12 @@ public class TagDatabaseService : ObservableObject public async Task WriteTagsToDatabase(List tags) { if (this.Database is null) return; + foreach (var tag in tags) + { + tag.CreatedAt ??= DateTime.Now; + tag.UpdatedAt = DateTime.Now; + } + await this.Database.WriteTagsToDatabase(tags); } diff --git a/UI/ViewModels/MainWindowViewModel.cs b/UI/ViewModels/MainWindowViewModel.cs index cd304b2..30a70c5 100644 --- a/UI/ViewModels/MainWindowViewModel.cs +++ b/UI/ViewModels/MainWindowViewModel.cs @@ -1,4 +1,5 @@ using System; +using System.Collections.Generic; using System.ComponentModel; using System.Threading.Tasks; using Avalonia; @@ -17,8 +18,9 @@ namespace TagHierarchyManager.UI.ViewModels; // such as putting search functions and tag editor functions in their own viewmodels. public partial class MainWindowViewModel : ViewModelBase { + internal readonly Func, List> GetParentNamesById; [ObservableProperty] private HierarchyTreeViewModel? _hierarchyTreeViewModel; - + [ObservableProperty] private bool _isDbEnabled; private bool _isSwitching; @@ -44,6 +46,7 @@ public partial class MainWindowViewModel : ViewModelBase if (args.PropertyName == nameof(this.TagDatabaseService.TagCount)) this.OnPropertyChanged(nameof(this.TotalTags)); }; + this.GetParentNamesById = tagDatabaseService.GetParentNamesByIds; } public int TotalTags => this.TagDatabaseService.TagCount; @@ -67,7 +70,7 @@ public partial class MainWindowViewModel : ViewModelBase else { if (this._selectedTag == value) return; - + value.RefreshParentsString(); this._selectedTag = value; this.OnPropertyChanged(); this.TagEditorViewModel?.SelectedTag = value; diff --git a/UI/ViewModels/RecentsViewModel.cs b/UI/ViewModels/RecentsViewModel.cs index 546aa54..d37197d 100644 --- a/UI/ViewModels/RecentsViewModel.cs +++ b/UI/ViewModels/RecentsViewModel.cs @@ -8,19 +8,24 @@ namespace TagHierarchyManager.UI.ViewModels; public partial class RecentsViewModel : ViewModelBase { private readonly MainWindowViewModel _mainWindow; + [ObservableProperty] private ObservableCollection _recentAdded = []; [ObservableProperty] private ObservableCollection _recentEdited = []; public RecentsViewModel(MainWindowViewModel mainWindow) { this._mainWindow = mainWindow; - this.RecentAdded = new ObservableCollection(); + this.RecentAdded = []; foreach (var tag in this._mainWindow.TagDatabaseService.GetRecentTags(true)) if (tag.CreatedAt is not null) this.RecentAdded.Add(new TagRow(tag, tag.CreatedAt.Value)); foreach (var tag in this._mainWindow.TagDatabaseService.GetRecentTags(false)) + { + if (Equals(tag.UpdatedAt, tag.CreatedAt)) continue; this.RecentEdited.Add(new TagRow(tag, tag.UpdatedAt)); + } + } public event Action? RequestClose; @@ -29,7 +34,7 @@ public partial class RecentsViewModel : ViewModelBase { var tag = this._mainWindow.TagDatabaseService.GetTagById(tagRow.Id); if (tag is null) return; - this._mainWindow.SelectedTagId = tagRow.Id; + this._mainWindow.SelectedTag = new TagItemViewModel(tag, this._mainWindow.GetParentNamesById); this.RequestClose?.Invoke(); } diff --git a/UI/ViewModels/SearchViewModel.cs b/UI/ViewModels/SearchViewModel.cs index eb4e167..a4f9ce4 100644 --- a/UI/ViewModels/SearchViewModel.cs +++ b/UI/ViewModels/SearchViewModel.cs @@ -1,4 +1,5 @@ using System; +using System.Collections.Generic; using System.Collections.ObjectModel; using System.Linq; using CommunityToolkit.Mvvm.ComponentModel; @@ -11,6 +12,7 @@ namespace TagHierarchyManager.UI.ViewModels; public partial class SearchViewModel : ViewModelBase, IDisposable { private readonly MainWindowViewModel _mainWindow; + private readonly Func, List> _getParentNamesById; [ObservableProperty] private ObservableCollection _searchResults = []; @@ -19,6 +21,7 @@ public partial class SearchViewModel : ViewModelBase, IDisposable public SearchViewModel(MainWindowViewModel mainWindow) { this._mainWindow = mainWindow; + this._getParentNamesById = this._mainWindow.GetParentNamesById; mainWindow.TagDatabaseService.TagsWritten += this.TagDatabase_OnTagsWritten; } @@ -29,8 +32,8 @@ public partial class SearchViewModel : ViewModelBase, IDisposable partial void OnSelectedSearchResultChanged(TagItemViewModel? value) { - if (value is null || this._mainWindow.SelectedTagId == value.Id) return; - this._mainWindow.SelectedTagId = value.Id; + if (value is null || this._mainWindow.SelectedTag?.Id == value.Id) return; + this._mainWindow.SelectedTag = value; } private void Search(string searchQuery, TagDatabaseSearchMode mode, bool searchAliases) @@ -48,7 +51,7 @@ public partial class SearchViewModel : ViewModelBase, IDisposable } results.Select(tag => - new TagItemViewModel(tag)) + new TagItemViewModel(tag, this._getParentNamesById)) .OrderBy(tag => tag.Name) .ToList() .ForEach(this.SearchResults.Add); -- 2.51.2