Skip to content

Commit

Permalink
modal works
Browse files Browse the repository at this point in the history
  • Loading branch information
bz888 committed Jan 20, 2022
1 parent ccbaa52 commit e1b02c2
Show file tree
Hide file tree
Showing 9 changed files with 303 additions and 46 deletions.
1 change: 1 addition & 0 deletions client/components/App.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ function App () {
return (
<>
<GetVid/>

</>
)
}
Expand Down
19 changes: 19 additions & 0 deletions client/components/Backdrop.jsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
import React from 'react'
// import { stateLogger } from '../../stateLogger'
import { motion } from 'framer-motion'

const Backdrop = ({ children, onClick }) => {
return (
<motion.div
className="backdrop"
onClick={onClick}
initial={{ opacity: 0 }}
animate={{ opacity: 1 }}
exit={{ opacity: 0 }}
>
{children}
</motion.div>
)
}

export default Backdrop
1 change: 0 additions & 1 deletion client/components/GetVid.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,6 @@ function GetVid () {

return (
<>

<VideoPlayer id={vidId[index]} setToggle={setToggle} toggle={toggle} minView={minView}/>
</>
)
Expand Down
44 changes: 44 additions & 0 deletions client/components/Modal.jsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
import React from 'react'
import { motion } from 'framer-motion'

import Backdrop from './Backdrop'

function Modal ({ handleClose, text }) {
const dropIn = {
initial: {
y: '0',
opacity: 1
},
visible: {
y: '100vh',
opacity: 1,
transition: {
duration: 0.1,
type: 'spring',
damping: 25,
stiffness: 500
}
},
exit: {
y: '-100vh',
opacity: 0
}
}
return (
<Backdrop onClick={handleClose}>
<motion.div
onClick={(e) => e.stopPropagation()}
className='modal'
variants={dropIn}
initial='initial'
animate='visble'
exit='exit'
>
<h3>{text}</h3>
{/* <button onClick={handleClose}>Begin</button> */}
</motion.div>
</Backdrop>
)
}

export default Modal
20 changes: 14 additions & 6 deletions client/components/VideoPlayer.jsx
Original file line number Diff line number Diff line change
@@ -1,8 +1,15 @@
import React, { useState } from 'react'
import YouTube from 'react-youtube'
import Modal from './Modal'
import { AnimatePresence } from 'framer-motion'

function VideoPlayer ({ id, toggle, setToggle, minView }) {
const [player, setPlayer] = useState(null)
const [modalOpen, setModalOpen] = useState(true)
function close () {
setModalOpen(false)
player.playVideo()
}

const opts = {
height: '390',
Expand All @@ -18,10 +25,6 @@ function VideoPlayer ({ id, toggle, setToggle, minView }) {
setPlayer(event.target)
}

function handleClick () {
player.playVideo()
console.log(player.isMuted())
}
function onPlay () {
player.unMute()
}
Expand All @@ -36,8 +39,13 @@ function VideoPlayer ({ id, toggle, setToggle, minView }) {

return (
<>
{/* <h1 className='viewCount'>View Count: {minView}</h1> */}
<button className='pageEntrance' onClick={handleClick}>Go</button>
<AnimatePresence
initial={false}
exitBeforeEnter={true}
>
{modalOpen && <Modal modalOpen={modalOpen} handleClose={close} text={'begin'}/>}
</AnimatePresence>

<div className='yt-player'>
<YouTube
videoId={id}
Expand Down
13 changes: 13 additions & 0 deletions client/components/useModal.jsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
import { useState } from 'react'

// Centralizes modal control
const useModal = () => {
const [modalOpen, setModalOpen] = useState(false)

const close = () => setModalOpen(false)
const open = () => setModalOpen(true)

return { modalOpen, close, open }
}

export default useModal
Loading

0 comments on commit e1b02c2

Please sign in to comment.