From c42c882257d9684f23a389208234e9f05a8e3c20 Mon Sep 17 00:00:00 2001 From: Sebastian Fudalej Date: Wed, 15 Sep 2021 23:33:11 +0200 Subject: [PATCH] feat: show modal as confirmation on song report --- public/index.html | 1 + src/components/Info/Info.js | 32 +++++++++++++- src/components/Modal/Modal.css | 80 ++++++++++++++++++++++++++++++++++ src/components/Modal/Modal.js | 21 +++++++++ 4 files changed, 132 insertions(+), 2 deletions(-) create mode 100644 src/components/Modal/Modal.css create mode 100644 src/components/Modal/Modal.js diff --git a/public/index.html b/public/index.html index f11a0bd..f1cb374 100644 --- a/public/index.html +++ b/public/index.html @@ -35,6 +35,7 @@ +
diff --git a/src/components/Info/Info.js b/src/components/Info/Info.js index fd599ff..2424b85 100644 --- a/src/components/Info/Info.js +++ b/src/components/Info/Info.js @@ -1,6 +1,8 @@ import { useContext, useEffect, useState } from 'react' import { useParams, Redirect } from 'react-router-dom' +import Modal from '../Modal/Modal' + import { get } from '../../Cache' import PlayingContext from '../../contexts/Playing' @@ -19,6 +21,7 @@ function Info() { artists: ['-'], }), [meta, setMeta] = useState('...'), + [showModal, setShowModal] = useState(true), playing = useContext(PlayingContext) if (!id) last = playing.id ?? '' @@ -72,6 +75,11 @@ function Info() { document.setTitle(track.title) + const toggleModal = () => setShowModal(!showModal) + const report = () => { + track.setVote('report') + } + return (
{ - window.confirm(`Napewno chcesz zgłosić ten utwór?`) && - track.setVote('report') + toggleModal() }} >
@@ -159,6 +166,27 @@ function Info() { )} {id} + {showModal ? ( + +
+
+ Czy na pewno chcesz zgłosić utwór{' '} + + {track.title} + + ? +
+
+
+ + +
+
+ ) : null} ) } diff --git a/src/components/Modal/Modal.css b/src/components/Modal/Modal.css new file mode 100644 index 0000000..0f4ffd6 --- /dev/null +++ b/src/components/Modal/Modal.css @@ -0,0 +1,80 @@ +#modal > div { + position: fixed; + width: 100vw; + height: 100vh; + z-index: 100; + display: flex; + justify-content: center; + align-items: center; + background-color: rgba(0, 0, 0, 0.7); + backdrop-filter: blur(5px); +} + +.modal { + background-color: var(--light); + color: var(--dark); + border-radius: 0.5em; + padding: 30px min(9vw, 30px); + max-width: 550px; + width: 100%; + margin: 20px; +} +.modal-text { + font-size: 1.5em; + padding-bottom: 20px; + text-align: center; +} +.modal-button { + margin: 1px; + color: var(--white); + box-sizing: border-box; + padding: 10px 10px; + font-size: 1.4em; + display: inline-block; + border: none; + transition: all 0.4s ease 0s; + cursor: pointer; + background-color: var(--main); +} +.modal-button:hover { + background: var(--dark); + transition: all 0.4s ease 0s; +} + +.modal { + display: grid; + grid-template-columns: 1fr; + grid-template-rows: 1fr; + grid-template-areas: + 'text' + 'modal-buttons'; +} +.text { + grid-area: text; +} + +.modal-button:first-child { + border-radius: 0.5em 0 0 0.5em; +} +.modal-button:last-child { + border-radius: 0 0.5em 0.5em 0; +} +div[class^='modal-buttons-'] { + display: grid; + grid-template-rows: 1fr; + gap: 0px; + grid-area: modal-buttons; +} + +.modal-buttons-1 { + grid-template-columns: 1fr; +} +.modal-buttons-2 { + grid-template-columns: 1fr 1fr; +} +.modal-buttons-3 { + grid-template-columns: 1fr 1fr 1fr; +} +.modal-buttons-4 { + grid-template-columns: 1fr 1fr 1fr 1fr; +} diff --git a/src/components/Modal/Modal.js b/src/components/Modal/Modal.js new file mode 100644 index 0000000..5345998 --- /dev/null +++ b/src/components/Modal/Modal.js @@ -0,0 +1,21 @@ +import { useEffect, useRef } from 'react' +import { createPortal } from 'react-dom' + +import './Modal.css' + +const modalRoot = document.getElementById('modal') + +function Modal({ children }) { + const elRef = useRef(null) + if (!elRef.current) { + elRef.current = document.createElement('div') + } + useEffect(() => { + modalRoot.appendChild(elRef.current) + return () => modalRoot.removeChild(elRef.current) + }, []) + + return createPortal(
{children}
, elRef.current) +} + +export default Modal -- 2.54.0