diff --git a/app/ide-desktop/lib/dashboard/src/authentication/src/dashboard/components/dashboard.tsx b/app/ide-desktop/lib/dashboard/src/authentication/src/dashboard/components/dashboard.tsx index cc483bcb637a..2d14fcccf8dd 100644 --- a/app/ide-desktop/lib/dashboard/src/authentication/src/dashboard/components/dashboard.tsx +++ b/app/ide-desktop/lib/dashboard/src/authentication/src/dashboard/components/dashboard.tsx @@ -288,6 +288,24 @@ function Dashboard(props: DashboardProps) { const directory = directoryStack[directoryStack.length - 1] const parentDirectory = directoryStack[directoryStack.length - 2] + const switchToIdeTab = react.useCallback(() => { + setTab(Tab.ide) + const ideElement = document.getElementById(IDE_ELEMENT_ID) + if (ideElement) { + ideElement.style.top = '' + ideElement.style.display = 'absolute' + } + }, []) + + const switchToDashboardTab = react.useCallback(() => { + setTab(Tab.dashboard) + const ideElement = document.getElementById(IDE_ELEMENT_ID) + if (ideElement) { + ideElement.style.top = '-100vh' + ideElement.style.display = 'fixed' + } + }, []) + react.useEffect(() => { const onProjectManagerLoadingFailed = () => { setLoadingProjectManagerDidFail(true) @@ -312,31 +330,14 @@ function Dashboard(props: DashboardProps) { react.useEffect(() => { if (supportsLocalBackend) { - new localBackend.LocalBackend() + setBackend(new localBackend.LocalBackend()) } }, []) react.useEffect(() => { - const onKeyDown = (event: KeyboardEvent) => { - if ( - // On macOS, we need to check for combination of `alt` + `d` which is `∂` (`del`). - (event.key === 'd' || event.key === '∂') && - event.ctrlKey && - event.altKey && - !event.shiftKey && - !event.metaKey - ) { - setTab(Tab.dashboard) - const ideElement = document.getElementById(IDE_ELEMENT_ID) - if (ideElement) { - ideElement.style.top = '-100vh' - ideElement.style.display = 'fixed' - } - } - } - document.addEventListener('keydown', onKeyDown) + document.addEventListener('show-dashboard', switchToDashboardTab) return () => { - document.removeEventListener('keydown', onKeyDown) + document.removeEventListener('show-dashboard', switchToDashboardTab) } }, []) @@ -438,15 +439,10 @@ function Dashboard(props: DashboardProps) { setProject(null) }} openIde={async () => { - setTab(Tab.ide) + switchToIdeTab() if (project?.projectId !== projectAsset.id) { setProject(await backend.getProjectDetails(projectAsset.id)) } - const ideElement = document.getElementById(IDE_ELEMENT_ID) - if (ideElement) { - ideElement.style.top = '' - ideElement.style.display = 'absolute' - } }} /> {projectAsset.title} @@ -658,9 +654,7 @@ function Dashboard(props: DashboardProps) { const onBlur = () => { setIsFileBeingDragged(false) } - window.addEventListener('blur', onBlur) - return () => { window.removeEventListener('blur', onBlur) } @@ -731,19 +725,9 @@ function Dashboard(props: DashboardProps) { tab={tab} toggleTab={() => { if (project && tab === Tab.dashboard) { - setTab(Tab.ide) - const ideElement = document.getElementById(IDE_ELEMENT_ID) - if (ideElement) { - ideElement.style.top = '' - ideElement.style.display = 'absolute' - } + switchToIdeTab() } else { - setTab(Tab.dashboard) - const ideElement = document.getElementById(IDE_ELEMENT_ID) - if (ideElement) { - ideElement.style.top = '-100vh' - ideElement.style.display = 'fixed' - } + switchToDashboardTab() } }} setBackendType={newBackendType => {