From 3a02d1cdd6a9c53b94c3cd87eaeb547364ba2759 Mon Sep 17 00:00:00 2001 From: Mohamed Boudra Date: Wed, 11 Mar 2026 21:11:10 +0700 Subject: [PATCH] refactor: extract createShortcutTarget and simplify shortcut logic --- packages/app/src/utils/sidebar-shortcuts.ts | 29 ++++++++++++--------- 1 file changed, 17 insertions(+), 12 deletions(-) diff --git a/packages/app/src/utils/sidebar-shortcuts.ts b/packages/app/src/utils/sidebar-shortcuts.ts index 5795673bf..66e645341 100644 --- a/packages/app/src/utils/sidebar-shortcuts.ts +++ b/packages/app/src/utils/sidebar-shortcuts.ts @@ -14,6 +14,15 @@ export interface SidebarShortcutModel { shortcutIndexByWorkspaceKey: Map } +function createShortcutTarget( + workspace: SidebarWorkspaceEntry, +): SidebarShortcutWorkspaceTarget { + return { + serverId: workspace.serverId, + workspaceId: workspace.workspaceId, + } +} + export function buildSidebarShortcutModel(input: { projects: SidebarProjectEntry[] collapsedProjectKeys: ReadonlySet @@ -30,19 +39,15 @@ export function buildSidebarShortcutModel(input: { } for (const workspace of project.workspaces) { - visibleTargets.push({ - serverId: workspace.serverId, - workspaceId: workspace.workspaceId, - }) - const shortcutNumber = - shortcutTargets.length < maxShortcuts ? shortcutTargets.length + 1 : null - if (shortcutNumber !== null) { - shortcutTargets.push({ - serverId: workspace.serverId, - workspaceId: workspace.workspaceId, - }) - shortcutIndexByWorkspaceKey.set(workspace.workspaceKey, shortcutNumber) + visibleTargets.push(createShortcutTarget(workspace)) + + if (shortcutTargets.length >= maxShortcuts) { + continue } + + const shortcutNumber = shortcutTargets.length + 1 + shortcutTargets.push(createShortcutTarget(workspace)) + shortcutIndexByWorkspaceKey.set(workspace.workspaceKey, shortcutNumber) } }