mirror of
https://github.com/hedgedoc/hedgedoc.git
synced 2025-05-13 22:54:42 -04:00
Add slide mode with reveal.js
Signed-off-by: Tilman Vatteroth <git@tilmanvatteroth.de>
This commit is contained in:
parent
29565f8f89
commit
36e445e631
70 changed files with 1225 additions and 323 deletions
53
src/components/markdown-renderer/hooks/use-reveal.ts
Normal file
53
src/components/markdown-renderer/hooks/use-reveal.ts
Normal file
|
@ -0,0 +1,53 @@
|
|||
/*
|
||||
* SPDX-FileCopyrightText: 2021 The HedgeDoc developers (see AUTHORS file)
|
||||
*
|
||||
* SPDX-License-Identifier: AGPL-3.0-only
|
||||
*/
|
||||
|
||||
import { useEffect, useState } from 'react'
|
||||
import Reveal from 'reveal.js'
|
||||
import { Logger } from '../../../utils/logger'
|
||||
import { SlideOptions } from '../../common/note-frontmatter/types'
|
||||
|
||||
const log = new Logger('reveal.js')
|
||||
|
||||
export const useReveal = (content: string, slideOptions?: SlideOptions): void => {
|
||||
const [deck, setDeck] = useState<Reveal>()
|
||||
const [isInitialized, setIsInitialized] = useState<boolean>(false)
|
||||
|
||||
useEffect(() => {
|
||||
if (isInitialized) {
|
||||
return
|
||||
}
|
||||
setIsInitialized(true)
|
||||
log.debug('Initialize with slide options', slideOptions)
|
||||
const reveal = new Reveal({})
|
||||
reveal
|
||||
.initialize()
|
||||
.then(() => {
|
||||
reveal.layout()
|
||||
reveal.slide(0, 0, 0)
|
||||
setDeck(reveal)
|
||||
log.debug('Initialisation finished')
|
||||
})
|
||||
.catch((error) => {
|
||||
log.error('Error while initializing reveal.js', error)
|
||||
})
|
||||
}, [isInitialized, slideOptions])
|
||||
|
||||
useEffect(() => {
|
||||
if (!deck) {
|
||||
return
|
||||
}
|
||||
log.debug('Sync deck')
|
||||
deck.layout()
|
||||
}, [content, deck])
|
||||
|
||||
useEffect(() => {
|
||||
if (!deck || slideOptions === undefined || Object.keys(slideOptions).length === 0) {
|
||||
return
|
||||
}
|
||||
log.debug('Apply config', slideOptions)
|
||||
deck.configure(slideOptions)
|
||||
}, [deck, slideOptions])
|
||||
}
|
Loading…
Add table
Add a link
Reference in a new issue