summaryrefslogtreecommitdiffhomepage
path: root/packages/app/src/pages/layout
diff options
context:
space:
mode:
Diffstat (limited to 'packages/app/src/pages/layout')
-rw-r--r--packages/app/src/pages/layout/helpers.ts30
1 files changed, 25 insertions, 5 deletions
diff --git a/packages/app/src/pages/layout/helpers.ts b/packages/app/src/pages/layout/helpers.ts
index 2c4b834be..42315e589 100644
--- a/packages/app/src/pages/layout/helpers.ts
+++ b/packages/app/src/pages/layout/helpers.ts
@@ -74,9 +74,29 @@ export const errorMessage = (err: unknown, fallback: string) => {
return fallback
}
-export const syncWorkspaceOrder = (local: string, dirs: string[], existing?: string[]) => {
- if (!existing) return dirs
- const keep = existing.filter((d) => d !== local && dirs.includes(d))
- const missing = dirs.filter((d) => d !== local && !existing.includes(d))
- return [local, ...missing, ...keep]
+export const effectiveWorkspaceOrder = (local: string, dirs: string[], persisted?: string[]) => {
+ const root = workspaceKey(local)
+ const live = new Map<string, string>()
+
+ for (const dir of dirs) {
+ const key = workspaceKey(dir)
+ if (key === root) continue
+ if (!live.has(key)) live.set(key, dir)
+ }
+
+ if (!persisted?.length) return [local, ...live.values()]
+
+ const result = [local]
+ for (const dir of persisted) {
+ const key = workspaceKey(dir)
+ if (key === root) continue
+ const match = live.get(key)
+ if (!match) continue
+ result.push(match)
+ live.delete(key)
+ }
+
+ return [...result, ...live.values()]
}
+
+export const syncWorkspaceOrder = effectiveWorkspaceOrder