Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Handle show-dashboard event #6837

Merged
merged 4 commits into from
May 26, 2023
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand All @@ -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)
}
}, [])

Expand Down Expand Up @@ -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'
}
}}
/>
<span className="px-2">{projectAsset.title}</span>
Expand Down Expand Up @@ -658,9 +654,7 @@ function Dashboard(props: DashboardProps) {
const onBlur = () => {
setIsFileBeingDragged(false)
}

window.addEventListener('blur', onBlur)

return () => {
window.removeEventListener('blur', onBlur)
}
Expand Down Expand Up @@ -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 => {
Expand Down