mirror of
https://github.com/bookorbit/bookorbit.git
synced 2026-11-03 08:21:39 -06:00
fix(library): preserve folder creation order
Keep unrelated folder selections in the order users add them, and make API reads deterministic so web and iOS defaults use the same first folder. Fixes #1412
This commit is contained in:
@@ -11,6 +11,10 @@ describe('folder path selection', () => {
|
||||
expect(consolidateFolderPaths(['/books/fiction', '/audio', '/books', '/books/fantasy'])).toEqual(['/audio', '/books'])
|
||||
})
|
||||
|
||||
it('preserves the order of unrelated folders', () => {
|
||||
expect(consolidateFolderPaths(['/library/zz', '/library/alpha-long', '/library/m'])).toEqual(['/library/zz', '/library/alpha-long', '/library/m'])
|
||||
})
|
||||
|
||||
it('finds the selected path that already covers a nested folder', () => {
|
||||
expect(coveringFolderPath('/books/fiction/scifi', ['/books', '/books/fiction'])).toBe('/books/fiction')
|
||||
})
|
||||
|
||||
@@ -15,8 +15,8 @@ export function coveringFolderPath(path: string, candidates: string[]): string |
|
||||
}
|
||||
|
||||
export function consolidateFolderPaths(paths: string[]): string[] {
|
||||
const unique = [...new Set(paths.map(normalizeFolderPath))].sort((a, b) => a.length - b.length || a.localeCompare(b))
|
||||
return unique.filter((path, index) => !unique.slice(0, index).some((candidate) => isPathInside(path, candidate)))
|
||||
const unique = [...new Set(paths.map(normalizeFolderPath))]
|
||||
return unique.filter((path) => !unique.some((candidate) => candidate !== path && isPathInside(path, candidate)))
|
||||
}
|
||||
|
||||
function isPathInside(path: string, parent: string): boolean {
|
||||
|
||||
Reference in New Issue
Block a user