From 5b34bd760881778c0d54221ac3e5d186bc887fc2 Mon Sep 17 00:00:00 2001 From: William Pereira Date: Sat, 9 Mar 2024 11:35:53 -0500 Subject: [PATCH] feature: updated the library filter to not clear the directory listing and switch folders. --- .../TeensyRom.Core/Common/PathExtensions.cs | 16 ++++++++++ .../Common/State/Player/PlayerContext.cs | 31 +++---------------- 2 files changed, 21 insertions(+), 26 deletions(-) diff --git a/Source/Windows/TeensyRom.Ui/src/TeensyRom.Core/Common/PathExtensions.cs b/Source/Windows/TeensyRom.Ui/src/TeensyRom.Core/Common/PathExtensions.cs index db71be9e..e008c1b9 100644 --- a/Source/Windows/TeensyRom.Ui/src/TeensyRom.Core/Common/PathExtensions.cs +++ b/Source/Windows/TeensyRom.Ui/src/TeensyRom.Core/Common/PathExtensions.cs @@ -99,5 +99,21 @@ public static string[] ToPathArray(this string path) } return path.Split(new char[] { '/' }, StringSplitOptions.RemoveEmptyEntries); } + + public static string GetCommonBasePath(this IEnumerable directories) + { + if (!directories.Any()) return string.Empty; + + string commonPath = directories.First(); + + foreach (string path in directories) + { + while (!path.StartsWith(commonPath, StringComparison.OrdinalIgnoreCase)) + { + commonPath = commonPath.Substring(0, commonPath.LastIndexOf(Path.DirectorySeparatorChar)); + } + } + return commonPath; + } } } \ No newline at end of file diff --git a/Source/Windows/TeensyRom.Ui/src/TeensyRom.Ui/Features/Common/State/Player/PlayerContext.cs b/Source/Windows/TeensyRom.Ui/src/TeensyRom.Ui/Features/Common/State/Player/PlayerContext.cs index d4f7765b..2e4dd62a 100644 --- a/Source/Windows/TeensyRom.Ui/src/TeensyRom.Ui/Features/Common/State/Player/PlayerContext.cs +++ b/Source/Windows/TeensyRom.Ui/src/TeensyRom.Ui/Features/Common/State/Player/PlayerContext.cs @@ -143,15 +143,14 @@ public async Task LoadDirectory(string path, string? filePathToSelect = null) _directoryState.Value.ClearSelection(); _directoryState.Value.LoadDirectory(cacheItem.ToList(), cacheItem.Path, filePathToSelect); - - _currentPath = cacheItem.Path; + + _currentPath = cacheItem.Path; Application.Current.Dispatcher.Invoke(() => { _tree.Insert(cacheItem.Directories); _tree.SelectDirectory(cacheItem.Path); }); - _directoryState.OnNext(_directoryState.Value); } public Task RefreshDirectory(bool bustCache = true) @@ -374,9 +373,7 @@ public virtual Unit SetPageSize(int pageSize) public Task SwitchLibrary(TeensyLibrary library) { _currentLibrary = library; - _directoryState.Value.ClearSelection(); - _tree.ResetDirectoryTree(library.Path); - return LoadDirectory(library.Path); + return Task.CompletedTask; } public TeensyFileType[] GetFileTypes() @@ -394,7 +391,7 @@ public TeensyFileType[] GetFileTypes() public async Task StoreFiles(IEnumerable files) { - var commonParent = GetCommonBasePath(files.Select(i => i.Path)); + var commonParent = files.Select(i => i.Path).GetCommonBasePath(); var directoryOnly = files.All(i => i.InSubdirectory); foreach (var file in files) @@ -417,24 +414,6 @@ public async Task StoreFiles(IEnumerable files) await _storage.SaveFile(fileInfo); } await RefreshDirectory(bustCache: false); - } - - private static string GetCommonBasePath(IEnumerable directories) - { - if (!directories.Any()) return string.Empty; - - string commonPath = directories.First(); - - foreach (string path in directories) - { - while (!path.StartsWith(commonPath, StringComparison.OrdinalIgnoreCase)) - { - commonPath = commonPath.Substring(0, commonPath.LastIndexOf(Path.DirectorySeparatorChar)); - } - } - return commonPath; - } - - + } } } \ No newline at end of file