Merge pull request #11 from Maathias/modal
feat: show modal as confirmation on song report
This commit was merged in pull request #11.
This commit is contained in:
4 files changed
+132
-2
No files matched your search
@@ -35,6 +35,7 @@
|
||||
|
||||
<body>
|
||||
<noscript>You need to enable JavaScript to run this app.</noscript>
|
||||
<div id="modal"></div>
|
||||
<div id="root"></div>
|
||||
</body>
|
||||
|
||||
|
||||
@@ -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 (
|
||||
<div className="wrapper info">
|
||||
<img
|
||||
@@ -129,8 +137,7 @@ function Info() {
|
||||
<i
|
||||
className="icon-flag"
|
||||
onClick={(e) => {
|
||||
window.confirm(`Napewno chcesz zgłosić ten utwór?`) &&
|
||||
track.setVote('report')
|
||||
toggleModal()
|
||||
}}
|
||||
></i>
|
||||
</div>
|
||||
@@ -159,6 +166,27 @@ function Info() {
|
||||
)}
|
||||
</div>
|
||||
<span className="info-data">{id}</span>
|
||||
{showModal ? (
|
||||
<Modal>
|
||||
<div className="modal-text">
|
||||
<div>
|
||||
Czy na pewno chcesz zgłosić utwór{' '}
|
||||
<i>
|
||||
<b>{track.title}</b>
|
||||
</i>
|
||||
?
|
||||
</div>
|
||||
</div>
|
||||
<div className="modal-buttons-2">
|
||||
<button onClick={toggleModal} className="modal-button">
|
||||
Nie
|
||||
</button>
|
||||
<button onClick={report} className="modal-button">
|
||||
Tak
|
||||
</button>
|
||||
</div>
|
||||
</Modal>
|
||||
) : null}
|
||||
</div>
|
||||
)
|
||||
}
|
||||
|
||||
@@ -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;
|
||||
}
|
||||
@@ -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(<div className={'modal'}>{children}</div>, elRef.current)
|
||||
}
|
||||
|
||||
export default Modal
|
||||
Reference in new issue
Block a user