mirror of
https://github.com/overleaf/overleaf.git
synced 2024-12-12 08:27:26 -05:00
e741eb0cb8
GitOrigin-RevId: 9e227fe45d874e01c4282ebbe489d7bd6d2250ac
36 lines
1.1 KiB
JavaScript
36 lines
1.1 KiB
JavaScript
import { useCallback } from 'react'
|
|
import { useDetachCompileContext as useCompileContext } from '../../../shared/context/detach-compile-context'
|
|
import useEventListener from '../../../shared/hooks/use-event-listener'
|
|
import useDetachAction from '../../../shared/hooks/use-detach-action'
|
|
|
|
export default function useCompileTriggers() {
|
|
const { startCompile, setChangedAt } = useCompileContext()
|
|
|
|
// recompile on key press
|
|
const startOrTriggerCompile = useDetachAction(
|
|
'start-compile',
|
|
startCompile,
|
|
'detacher',
|
|
'detached'
|
|
)
|
|
const compileHandler = useCallback(
|
|
event => {
|
|
startOrTriggerCompile(event.detail)
|
|
},
|
|
[startOrTriggerCompile]
|
|
)
|
|
useEventListener('pdf:recompile', compileHandler)
|
|
|
|
// record doc changes when notified by the editor
|
|
const setOrTriggerChangedAt = useDetachAction(
|
|
'set-changed-at',
|
|
setChangedAt,
|
|
'detacher',
|
|
'detached'
|
|
)
|
|
const setChangedAtHandler = useCallback(() => {
|
|
setOrTriggerChangedAt(Date.now())
|
|
}, [setOrTriggerChangedAt])
|
|
useEventListener('doc:changed', setChangedAtHandler)
|
|
useEventListener('doc:saved', setChangedAtHandler) // TODO: store this separately?
|
|
}
|