Reveal.tsx 2.5 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394
  1. /*
  2. * <<
  3. * Davinci
  4. * ==
  5. * Copyright (C) 2016 - 2017 EDP
  6. * ==
  7. * Licensed under the Apache License, Version 2.0 (the "License");
  8. * you may not use this file except in compliance with the License.
  9. * You may obtain a copy of the License at
  10. *
  11. * http://www.apache.org/licenses/LICENSE-2.0
  12. *
  13. * Unless required by applicable law or agreed to in writing, software
  14. * distributed under the License is distributed on an "AS IS" BASIS,
  15. * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  16. * See the License for the specific language governing permissions and
  17. * limitations under the License.
  18. * >>
  19. */
  20. import React, { useEffect, useState, useCallback } from 'react'
  21. import { useSelector } from 'react-redux'
  22. import { makeSelectCurrentProject } from 'containers/Projects/selectors'
  23. import { makeSelectCurrentDisplay } from 'containers/Viz/selectors'
  24. import Reveal from 'reveal.js'
  25. import 'reveal.js/dist/reveal.css'
  26. import RevealZoom from 'reveal.js/plugin/zoom/plugin'
  27. import Display from './Display'
  28. import { DefaultDisplayParams } from '../components/Setting/constants'
  29. import { useStatistic } from './hooks'
  30. const DisplayReveal: React.FC = () => {
  31. const [currentSlideIndex, setCurrentSlideIndex] = useState(0)
  32. const currentProject = useSelector(makeSelectCurrentProject())
  33. const currentDisplay = useSelector(makeSelectCurrentDisplay())
  34. useStatistic(currentProject, currentDisplay)
  35. const { autoPlay, autoSlide, transitionStyle, transitionSpeed } =
  36. currentDisplay.config.displayParams || DefaultDisplayParams
  37. useEffect(() => {
  38. Reveal.initialize({
  39. hash: false,
  40. history: false,
  41. controls: true,
  42. controlsLayout: 'edges',
  43. controlsTutorial: false,
  44. progress: false,
  45. loop: true,
  46. width: '100%',
  47. height: '100%',
  48. margin: 0,
  49. minScale: 1,
  50. maxScale: 1,
  51. autoSlide: autoPlay !== false ? autoSlide * 1000 : 0,
  52. transition: transitionStyle,
  53. transitionSpeed,
  54. viewDistance: 100,
  55. plugins: [RevealZoom]
  56. })
  57. }, [])
  58. const slideChanged = useCallback((e) => {
  59. const { indexh: slideIdx } = e
  60. setCurrentSlideIndex(slideIdx)
  61. }, [])
  62. useEffect(() => {
  63. Reveal.addEventListener('slidechanged', slideChanged)
  64. return () => {
  65. Reveal.removeEventListener('slidechanged', slideChanged)
  66. }
  67. }, [])
  68. return (
  69. <div className="reveal">
  70. <div className="slides">
  71. <Display slideIndex={currentSlideIndex} />
  72. </div>
  73. </div>
  74. )
  75. }
  76. export default DisplayReveal