From 98a0274bc9f16e4d3c873dfb123b26ed1d5fea80 Mon Sep 17 00:00:00 2001 From: James Brunton Date: Thu, 18 Sep 2025 15:54:34 +0100 Subject: [PATCH] Refactor --- .../src/components/shared/TopControls.tsx | 113 +++++++++--------- 1 file changed, 57 insertions(+), 56 deletions(-) diff --git a/frontend/src/components/shared/TopControls.tsx b/frontend/src/components/shared/TopControls.tsx index 684d65cc1..bf42b773f 100644 --- a/frontend/src/components/shared/TopControls.tsx +++ b/frontend/src/components/shared/TopControls.tsx @@ -20,63 +20,64 @@ const viewOptionStyle = { // Build view options showing text always const createViewOptions = (currentView: WorkbenchType, switchingTo: WorkbenchType | null, isToolSelected: boolean) => { - const options = [ - { - label: ( -
- {switchingTo === "viewer" ? ( - - ) : ( - - )} - Viewer -
- ), - value: "viewer", - }, - { - label: ( -
- {currentView === "fileEditor" ? ( - <> - {switchingTo === "fileEditor" ? : } - Active Files - - ) : ( - <> - {switchingTo === "fileEditor" ? : } - Active Files - - )} -
- ), - value: "fileEditor", - }, + const viewerOption = { + label: ( +
+ {switchingTo === "viewer" ? ( + + ) : ( + + )} + Viewer +
+ ), + value: "viewer", + }; + + const pageEditorOption = { + label: ( +
+ {currentView === "pageEditor" ? ( + <> + {switchingTo === "pageEditor" ? : } + Page Editor + + ) : ( + <> + {switchingTo === "pageEditor" ? : } + Page Editor + + )} +
+ ), + value: "pageEditor", + }; + + const fileEditorOption = { + label: ( +
+ {currentView === "fileEditor" ? ( + <> + {switchingTo === "fileEditor" ? : } + Active Files + + ) : ( + <> + {switchingTo === "fileEditor" ? : } + Active Files + + )} +
+ ), + value: "fileEditor", + }; + + // Build options array conditionally + return [ + viewerOption, + ...(isToolSelected ? [] : [pageEditorOption]), + fileEditorOption, ]; - - // Only add Page Editor option when not in a tool - if (!isToolSelected) { - options.splice(1, 0, { - label: ( -
- {currentView === "pageEditor" ? ( - <> - {switchingTo === "pageEditor" ? : } - Page Editor - - ) : ( - <> - {switchingTo === "pageEditor" ? : } - Page Editor - - )} -
- ), - value: "pageEditor", - }); - } - - return options; }; interface TopControlsProps {