2022-03-31 07:22:36 -04:00
|
|
|
import { memo, useState, useEffect, useRef } from 'react'
|
2021-10-12 04:47:46 -04:00
|
|
|
import { ButtonToolbar } from 'react-bootstrap'
|
2021-11-15 11:33:57 -05:00
|
|
|
import { useTranslation } from 'react-i18next'
|
|
|
|
import { useLayoutContext } from '../../../shared/context/layout-context'
|
2021-10-12 04:47:46 -04:00
|
|
|
import PdfCompileButton from './pdf-compile-button'
|
2022-07-20 10:01:48 -04:00
|
|
|
import SwitchToEditorButton from './switch-to-editor-button'
|
2021-10-12 04:47:46 -04:00
|
|
|
import PdfHybridLogsButton from './pdf-hybrid-logs-button'
|
|
|
|
import PdfHybridDownloadButton from './pdf-hybrid-download-button'
|
|
|
|
import PdfHybridCodeCheckButton from './pdf-hybrid-code-check-button'
|
2021-11-15 11:33:57 -05:00
|
|
|
import PdfOrphanRefreshButton from './pdf-orphan-refresh-button'
|
2021-11-30 09:54:14 -05:00
|
|
|
import { DetachedSynctexControl } from './detach-synctex-control'
|
2022-03-31 07:22:36 -04:00
|
|
|
import Icon from '../../../shared/components/icon'
|
|
|
|
|
|
|
|
const ORPHAN_UI_TIMEOUT_MS = 5000
|
2021-10-12 04:47:46 -04:00
|
|
|
|
|
|
|
function PdfPreviewHybridToolbar() {
|
2021-11-30 09:54:14 -05:00
|
|
|
const { detachRole, detachIsLinked } = useLayoutContext()
|
|
|
|
|
2022-03-31 07:22:36 -04:00
|
|
|
const uiTimeoutRef = useRef()
|
|
|
|
const [orphanPdfTabAfterDelay, setOrphanPdfTabAfterDelay] = useState(false)
|
|
|
|
|
2021-11-30 09:54:14 -05:00
|
|
|
const orphanPdfTab = !detachIsLinked && detachRole === 'detached'
|
2021-11-15 11:33:57 -05:00
|
|
|
|
2022-03-31 07:22:36 -04:00
|
|
|
useEffect(() => {
|
|
|
|
if (uiTimeoutRef.current) {
|
|
|
|
clearTimeout(uiTimeoutRef.current)
|
|
|
|
}
|
|
|
|
|
|
|
|
if (orphanPdfTab) {
|
|
|
|
uiTimeoutRef.current = setTimeout(() => {
|
|
|
|
setOrphanPdfTabAfterDelay(true)
|
|
|
|
}, ORPHAN_UI_TIMEOUT_MS)
|
|
|
|
} else {
|
|
|
|
setOrphanPdfTabAfterDelay(false)
|
|
|
|
}
|
|
|
|
}, [orphanPdfTab])
|
|
|
|
|
|
|
|
let ToolbarInner = null
|
|
|
|
if (orphanPdfTabAfterDelay) {
|
|
|
|
// when the detached tab has been orphan for a while
|
|
|
|
ToolbarInner = <PdfPreviewHybridToolbarOrphanInner />
|
|
|
|
} else if (orphanPdfTab) {
|
|
|
|
ToolbarInner = <PdfPreviewHybridToolbarConnectingInner />
|
|
|
|
} else {
|
|
|
|
// tab is not detached or not orphan
|
|
|
|
ToolbarInner = <PdfPreviewHybridToolbarInner />
|
|
|
|
}
|
|
|
|
|
2021-10-12 04:47:46 -04:00
|
|
|
return (
|
|
|
|
<ButtonToolbar className="toolbar toolbar-pdf toolbar-pdf-hybrid">
|
2022-03-31 07:22:36 -04:00
|
|
|
{ToolbarInner}
|
2021-11-15 11:33:57 -05:00
|
|
|
</ButtonToolbar>
|
|
|
|
)
|
|
|
|
}
|
|
|
|
|
|
|
|
function PdfPreviewHybridToolbarInner() {
|
|
|
|
return (
|
|
|
|
<>
|
2021-10-12 04:47:46 -04:00
|
|
|
<div className="toolbar-pdf-left">
|
|
|
|
<PdfCompileButton />
|
|
|
|
<PdfHybridLogsButton />
|
|
|
|
<PdfHybridDownloadButton />
|
|
|
|
</div>
|
|
|
|
<div className="toolbar-pdf-right">
|
2024-07-19 05:46:55 -04:00
|
|
|
<div className="toolbar-pdf-controls" id="toolbar-pdf-controls" />
|
2021-10-12 04:47:46 -04:00
|
|
|
<PdfHybridCodeCheckButton />
|
2022-07-20 10:01:48 -04:00
|
|
|
<SwitchToEditorButton />
|
2021-11-30 09:54:14 -05:00
|
|
|
<DetachedSynctexControl />
|
2021-10-12 04:47:46 -04:00
|
|
|
</div>
|
2021-11-15 11:33:57 -05:00
|
|
|
</>
|
|
|
|
)
|
|
|
|
}
|
|
|
|
|
|
|
|
function PdfPreviewHybridToolbarOrphanInner() {
|
|
|
|
const { t } = useTranslation()
|
|
|
|
return (
|
|
|
|
<>
|
|
|
|
<div className="toolbar-pdf-orphan">
|
|
|
|
{t('tab_no_longer_connected')}
|
|
|
|
<PdfOrphanRefreshButton />
|
|
|
|
</div>
|
|
|
|
</>
|
2021-10-12 04:47:46 -04:00
|
|
|
)
|
|
|
|
}
|
|
|
|
|
2022-03-31 07:22:36 -04:00
|
|
|
function PdfPreviewHybridToolbarConnectingInner() {
|
|
|
|
const { t } = useTranslation()
|
|
|
|
return (
|
|
|
|
<>
|
|
|
|
<div className="toolbar-pdf-orphan">
|
|
|
|
<Icon type="refresh" fw spin />
|
|
|
|
{t('tab_connecting')}…
|
|
|
|
</div>
|
|
|
|
</>
|
|
|
|
)
|
|
|
|
}
|
|
|
|
|
2021-10-12 04:47:46 -04:00
|
|
|
export default memo(PdfPreviewHybridToolbar)
|