feat: add modals, working settings
This commit is contained in:
1 parent
8ae286d248
commit
09a065d11f
16 files changed
+292
-202
No files matched your search
+10
-11
@@ -88,9 +88,7 @@ class Track {
|
||||
this.stats.cast = cast
|
||||
resolve(cast)
|
||||
})
|
||||
.catch((err) => {
|
||||
console.error(err)
|
||||
})
|
||||
.catch((err) => reject(err))
|
||||
})
|
||||
}
|
||||
|
||||
@@ -105,9 +103,7 @@ class Track {
|
||||
this.stats = stats
|
||||
resolve(stats)
|
||||
})
|
||||
.catch((err) => {
|
||||
console.error(err)
|
||||
})
|
||||
.catch((err) => reject(err))
|
||||
})
|
||||
}
|
||||
}
|
||||
@@ -158,10 +154,12 @@ function getMultiple(ids = []) {
|
||||
if (missing.length < 1) return resolve(ids.map((id) => Tracks[id]))
|
||||
else {
|
||||
// fetch missing tracks
|
||||
downloadMultiple(ids).then((tracks) => {
|
||||
tracks.map((track) => (Tracks[track.id] = track)) // add to cache
|
||||
return resolve(ids.map((id) => Tracks[id])) // resolve from cache
|
||||
})
|
||||
downloadMultiple(ids)
|
||||
.then((tracks) => {
|
||||
tracks.map((track) => (Tracks[track.id] = track)) // add to cache
|
||||
return resolve(ids.map((id) => Tracks[id])) // resolve from cache
|
||||
})
|
||||
.catch((err) => reject(err))
|
||||
}
|
||||
})
|
||||
}
|
||||
@@ -176,6 +174,7 @@ function getMultipleStats(tids) {
|
||||
.then((stats) => {
|
||||
resolve(stats)
|
||||
})
|
||||
.catch((err) => reject(err))
|
||||
})
|
||||
}
|
||||
|
||||
@@ -205,7 +204,7 @@ function downloadMultiple(tids) {
|
||||
.then((tracks) => {
|
||||
resolve(tracks.map((tdata) => new Track(tdata)))
|
||||
})
|
||||
.catch((err) => {})
|
||||
.catch((err) => reject(err))
|
||||
})
|
||||
}
|
||||
|
||||
|
||||
+6
-2
@@ -1,7 +1,7 @@
|
||||
import FastAverageColor from 'fast-average-color'
|
||||
|
||||
var fac = new FastAverageColor(),
|
||||
def = document.documentElement.style.getPropertyValue('--deg')
|
||||
def = 0
|
||||
|
||||
function setColor(target, lvl) {
|
||||
fac
|
||||
@@ -20,4 +20,8 @@ function setColor(target, lvl) {
|
||||
})
|
||||
}
|
||||
|
||||
export { setColor }
|
||||
function setDefault() {
|
||||
document.documentElement.style.setProperty('--deg', def + 'deg')
|
||||
}
|
||||
|
||||
export { setColor, setDefault }
|
||||
@@ -71,6 +71,7 @@
|
||||
|
||||
.info-list > .buttons {
|
||||
padding: 0;
|
||||
padding-bottom: 0.25em;
|
||||
}
|
||||
|
||||
.info-list > .buttons > i {
|
||||
@@ -84,6 +85,7 @@
|
||||
background-color: var(--light);
|
||||
color: var(--main);
|
||||
cursor: default;
|
||||
border-radius: 1em;
|
||||
}
|
||||
|
||||
.info-list > .buttons > i:hover {
|
||||
|
||||
+43
-33
@@ -4,8 +4,10 @@ import { useParams, Redirect } from 'react-router-dom'
|
||||
import Modal from '../Modal/Modal'
|
||||
|
||||
import { get } from '../../Cache'
|
||||
import { credentials } from '../../Auth'
|
||||
|
||||
import PlayingContext from '../../contexts/Playing'
|
||||
import ModalLoginContext from '../../contexts/ModalLogin'
|
||||
|
||||
import './Info.css'
|
||||
import def from '../../media/default.png'
|
||||
@@ -21,7 +23,8 @@ function Info() {
|
||||
artists: ['-'],
|
||||
}),
|
||||
[meta, setMeta] = useState('...'),
|
||||
[showModal, setShowModal] = useState(true),
|
||||
[modalReport, setModalReport] = useState(false),
|
||||
{ setModalLogin } = useContext(ModalLoginContext),
|
||||
playing = useContext(PlayingContext)
|
||||
|
||||
if (!id) last = playing.id ?? ''
|
||||
@@ -35,18 +38,23 @@ function Info() {
|
||||
.getStats()
|
||||
.then((stats) => {
|
||||
setTrack(track)
|
||||
setMeta(false).catch((err) => console.error(err))
|
||||
setMeta(false)
|
||||
})
|
||||
.catch((err) => console.error(err))
|
||||
.catch((err) =>
|
||||
setMeta(`Wystąpił błąd przy pobieraniu statystyk utworu`)
|
||||
)
|
||||
})
|
||||
.catch((err) => {
|
||||
.catch((err) =>
|
||||
setMeta(`Wystąpił błąd przy pobieraniu informacji o utworze`)
|
||||
})
|
||||
)
|
||||
}, [last]) // eslint-disable-line
|
||||
|
||||
if (!id && last) return <Redirect to={`/utwor/${last}`} />
|
||||
|
||||
function vote(value) {
|
||||
if (!credentials.token) return setModalLogin(true)
|
||||
|
||||
setMeta('Zmienianie głosu...')
|
||||
track
|
||||
.setVote(value)
|
||||
.then((ok) => {
|
||||
@@ -55,11 +63,18 @@ function Info() {
|
||||
.then(() => {
|
||||
ok
|
||||
? setMeta(`Zmieniono głos na ${{ up: '👍', down: '👎' }[value]}`)
|
||||
: setMeta('Wystąpił bład przy zmienianiu głosu')
|
||||
: setMeta('Głos nie został zmieniony')
|
||||
})
|
||||
.catch((err) => console.error(err))
|
||||
.catch((err) =>
|
||||
setMeta('Wystąpił błąd przy aktualizacji statystyk utworu')
|
||||
)
|
||||
})
|
||||
.catch((err) => console.error(err))
|
||||
.catch((err) => setMeta('Wystąpił błąd podczas wysyłania głosu'))
|
||||
}
|
||||
|
||||
function report() {
|
||||
track.setVote('report')
|
||||
setModalReport(false)
|
||||
}
|
||||
|
||||
const total = track.stats.up + track.stats.down,
|
||||
@@ -70,11 +85,6 @@ function Info() {
|
||||
|
||||
document.setTitle(track.title)
|
||||
|
||||
const toggleModal = () => setShowModal(!showModal)
|
||||
const report = () => {
|
||||
track.setVote('report')
|
||||
}
|
||||
|
||||
return (
|
||||
<div className="wrapper info">
|
||||
<img
|
||||
@@ -96,7 +106,7 @@ function Info() {
|
||||
</div>
|
||||
</div>
|
||||
|
||||
{meta && <span className="info-meta">{meta}</span>}
|
||||
<span className="info-meta"> {meta}</span>
|
||||
|
||||
{track.id && (
|
||||
<div className="info-list">
|
||||
@@ -133,15 +143,14 @@ function Info() {
|
||||
></i>
|
||||
<i
|
||||
className="icon-flag"
|
||||
onClick={(e) => {
|
||||
toggleModal()
|
||||
}}
|
||||
onClick={(e) => setModalReport(true)}
|
||||
></i>
|
||||
</div>
|
||||
|
||||
<div>
|
||||
<span>{track.artists.join(', ')}</span>
|
||||
</div>
|
||||
|
||||
<div>
|
||||
<span>
|
||||
{track.album.name ?? '-'} ({track.album.year ?? '-'})
|
||||
@@ -151,14 +160,14 @@ function Info() {
|
||||
{total > 0 && (
|
||||
<div>
|
||||
<i className="icon-thumbs-up"></i> Liczba głosów:
|
||||
<strong>{total}</strong>
|
||||
<b>{total}</b>
|
||||
</div>
|
||||
)}
|
||||
|
||||
{track.stats.rank > 0 && (
|
||||
<div>
|
||||
<i className="icon-list-numbered"></i> Miejsce:
|
||||
<strong>#{track.stats.rank}</strong>
|
||||
<b>#{track.stats.rank}</b>
|
||||
</div>
|
||||
)}
|
||||
|
||||
@@ -181,27 +190,28 @@ function Info() {
|
||||
)}
|
||||
</div>
|
||||
<span className="info-data">{id}</span>
|
||||
{showModal ? (
|
||||
{modalReport && (
|
||||
<Modal>
|
||||
<div className="modal-text">
|
||||
<div>
|
||||
Czy na pewno chcesz zgłosić utwór{' '}
|
||||
<i>
|
||||
<b>{track.title}</b>
|
||||
</i>
|
||||
?
|
||||
</div>
|
||||
<div class="modal-title">Czy na pewno chcesz zgłosić utwór?</div>
|
||||
<div class="modal-body">
|
||||
Zgłoszone utwory trafiają do sprawdzenia przez administrację. Jeżeli
|
||||
<b> {track.title}</b> zawiera treści nieodpowiednie lub
|
||||
<i> bardzo</i> nie chciałbyś go usłyszeć na korytarzu, zalecamy
|
||||
zgłoszanie tego utworu.
|
||||
</div>
|
||||
<div className="modal-buttons-2">
|
||||
<button onClick={toggleModal} className="modal-button">
|
||||
Nie
|
||||
<div className="modal-buttons">
|
||||
<button
|
||||
onClick={() => setModalReport(false)}
|
||||
className="modal-button"
|
||||
>
|
||||
Anuluj
|
||||
</button>
|
||||
<button onClick={report} className="modal-button">
|
||||
Tak
|
||||
Zgłoś
|
||||
</button>
|
||||
</div>
|
||||
</Modal>
|
||||
) : null}
|
||||
)}
|
||||
</div>
|
||||
)
|
||||
}
|
||||
|
||||
+85
-59
@@ -6,6 +6,7 @@ import {
|
||||
} from 'react-router-dom'
|
||||
import { useEffect, useState } from 'react'
|
||||
import ga from 'react-ga'
|
||||
import localStorage from 'local-storage'
|
||||
|
||||
import Nav from '../Nav/Nav'
|
||||
import History from '../History/History'
|
||||
@@ -13,13 +14,17 @@ import Status from '../Status/Status'
|
||||
import Info from '../Info/Info'
|
||||
import Top from '../Top/Top'
|
||||
import Search from '../Search/Search'
|
||||
import Settings from '../Settings/Settings'
|
||||
import Settings, { defaults } from '../Settings/Settings'
|
||||
import Modal from '../Modal/Modal'
|
||||
|
||||
import { get, getMultiple, getMultipleStats } from '../../Cache'
|
||||
import { addEvent } from '../../socket'
|
||||
import { promptLogin } from '../../Auth'
|
||||
|
||||
import PlayingContext from '../../contexts/Playing'
|
||||
import GaContext from '../../contexts/Ga'
|
||||
import ModalLoginContext from '../../contexts/ModalLogin'
|
||||
import SettingsContext from '../../contexts/Settings'
|
||||
|
||||
import './Main.css'
|
||||
|
||||
@@ -43,7 +48,9 @@ function Main() {
|
||||
[next, setNext] = useState(),
|
||||
[previous, setPrevious] = useState([]),
|
||||
[top, setTop] = useState([]),
|
||||
[topDate, setTopDate] = useState()
|
||||
[topDate, setTopDate] = useState(),
|
||||
[modalLogin, setModalLogin] = useState(false),
|
||||
[settings, setSettings] = useState(localStorage('settings') ?? defaults)
|
||||
|
||||
useEffect(() => {
|
||||
addEvent('status', ({ trackid, progress, paused }) => {
|
||||
@@ -54,6 +61,7 @@ function Main() {
|
||||
setPaused(paused)
|
||||
})
|
||||
.catch((err) => {
|
||||
console.error(err)
|
||||
setPaused(true)
|
||||
})
|
||||
})
|
||||
@@ -77,75 +85,93 @@ function Main() {
|
||||
})
|
||||
|
||||
addEvent('top', ({ trackids, timestamp }) => {
|
||||
Promise.all([getMultiple(trackids), getMultipleStats(trackids)]).then(
|
||||
([tracks, stats]) => {
|
||||
Promise.all([getMultiple(trackids), getMultipleStats(trackids)])
|
||||
.then(([tracks, stats]) => {
|
||||
tracks.map((track, i) => (track.stats = stats[i]))
|
||||
setTop(tracks)
|
||||
setTopDate(new Date(timestamp))
|
||||
}
|
||||
)
|
||||
// getMultiple(trackids)
|
||||
// .then((tracks) => {
|
||||
// Promise.all(tracks.map((track) => track.getStats()))
|
||||
// .then(() => {
|
||||
// setTop(tracks)
|
||||
// setTopDate(new Date(timestamp))
|
||||
// })
|
||||
// .catch((err) => {
|
||||
// console.error(err)
|
||||
// })
|
||||
// })
|
||||
// .catch((err) => console.error(err))
|
||||
})
|
||||
.catch((err) => console.error(err))
|
||||
})
|
||||
}, [])
|
||||
|
||||
useEffect(() => {
|
||||
console.log('settings changed')
|
||||
console.log(settings)
|
||||
localStorage('settings', settings)
|
||||
}, [settings])
|
||||
|
||||
return (
|
||||
<GaContext.Provider value={ga}>
|
||||
<PlayingContext.Provider value={playing}>
|
||||
<div className="main">
|
||||
<Router>
|
||||
<Switch>
|
||||
<Route exact path="/">
|
||||
<History next={next} tracks={previous} />
|
||||
</Route>
|
||||
<SettingsContext.Provider
|
||||
value={{
|
||||
settings,
|
||||
setSettings: (key, value) => {
|
||||
setSettings((settings) => ({ ...settings, [key]: !value }))
|
||||
},
|
||||
}}
|
||||
>
|
||||
<ModalLoginContext.Provider value={{ modalLogin, setModalLogin }}>
|
||||
<GaContext.Provider value={ga}>
|
||||
<PlayingContext.Provider value={playing}>
|
||||
<div className="main">
|
||||
<Router>
|
||||
<Switch>
|
||||
<Route exact path="/">
|
||||
<History next={next} tracks={previous} />
|
||||
</Route>
|
||||
|
||||
<Route path="/utwor/:id?">
|
||||
<Info />
|
||||
</Route>
|
||||
<Route path="/utwor/:id?">
|
||||
<Info />
|
||||
</Route>
|
||||
|
||||
<Route path="/top">
|
||||
<Top tracks={top} timestamp={topDate} />
|
||||
</Route>
|
||||
<Route path="/top">
|
||||
<Top tracks={top} timestamp={topDate} />
|
||||
</Route>
|
||||
|
||||
<Route path="/wyszukaj/:query?">
|
||||
<Search />
|
||||
</Route>
|
||||
<Route path="/wyszukaj/:query?">
|
||||
<Search />
|
||||
</Route>
|
||||
|
||||
<Route path="/ustawienia">
|
||||
<Settings />
|
||||
</Route>
|
||||
<Route path="/ustawienia">
|
||||
<Settings />
|
||||
</Route>
|
||||
|
||||
<Route render={() => <Redirect to="/" />} />
|
||||
</Switch>
|
||||
<Nav
|
||||
buttons={[
|
||||
{ label: 'Historia', to: '/', icon: 'align-left' },
|
||||
{ label: 'Wyszukaj', to: '/wyszukaj', icon: 'search' },
|
||||
{ label: 'Top', to: '/top', icon: 'list-numbered' },
|
||||
{
|
||||
label: 'Utwór',
|
||||
path: '/utwor',
|
||||
to: `/utwor`,
|
||||
icon: 'info',
|
||||
},
|
||||
{ label: 'Ustawienia', to: '/ustawienia', icon: 'cog-alt' },
|
||||
]}
|
||||
/>
|
||||
<Status progress={elapsed} paused={paused} />
|
||||
</Router>
|
||||
</div>
|
||||
</PlayingContext.Provider>
|
||||
</GaContext.Provider>
|
||||
<Route render={() => <Redirect to="/" />} />
|
||||
</Switch>
|
||||
<Nav
|
||||
buttons={[
|
||||
{ label: 'Historia', to: '/', icon: 'align-left' },
|
||||
{ label: 'Wyszukaj', to: '/wyszukaj', icon: 'search' },
|
||||
{ label: 'Top', to: '/top', icon: 'list-numbered' },
|
||||
{
|
||||
label: 'Utwór',
|
||||
path: '/utwor',
|
||||
to: `/utwor`,
|
||||
icon: 'info',
|
||||
},
|
||||
{ label: 'Ustawienia', to: '/ustawienia', icon: 'cog-alt' },
|
||||
]}
|
||||
/>
|
||||
<Status progress={elapsed} paused={paused} />
|
||||
{modalLogin && (
|
||||
<Modal
|
||||
title="Zaloguj się aby głosować"
|
||||
content="Niestety głosowanie bez logowania nie jest i raczej nie będzie możliwe. Powodowałoby zbyt duży chaos. Logowanie przez facebooka bierze tylko publiczne dane, wyłącznie do autoryzacji"
|
||||
buttons={[
|
||||
['Zamknij', () => setModalLogin(false)],
|
||||
[
|
||||
'Zaloguj',
|
||||
() => promptLogin().then(() => setModalLogin(false)),
|
||||
],
|
||||
]}
|
||||
/>
|
||||
)}
|
||||
</Router>
|
||||
</div>
|
||||
</PlayingContext.Provider>
|
||||
</GaContext.Provider>
|
||||
</ModalLoginContext.Provider>
|
||||
</SettingsContext.Provider>
|
||||
)
|
||||
}
|
||||
|
||||
|
||||
@@ -11,70 +11,49 @@
|
||||
}
|
||||
|
||||
.modal {
|
||||
background-color: var(--light);
|
||||
background-color: var(--white);
|
||||
color: var(--dark);
|
||||
border-radius: 0.5em;
|
||||
padding: 30px min(9vw, 30px);
|
||||
border-radius: 3px;
|
||||
padding: 1.25em 1.5em;
|
||||
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';
|
||||
.modal > div.modal-title {
|
||||
font-size: 1.2em;
|
||||
font-weight: bold;
|
||||
border-bottom: 1px solid;
|
||||
padding-bottom: 0.3em;
|
||||
}
|
||||
.text {
|
||||
grid-area: text;
|
||||
|
||||
.modal > div.modal-body {
|
||||
margin: 1em 0 4em;
|
||||
color: #777;
|
||||
}
|
||||
|
||||
.modal-buttons {
|
||||
text-align: right;
|
||||
}
|
||||
|
||||
.modal-button {
|
||||
color: var(--white);
|
||||
background-color: var(--main);
|
||||
font-size: 1em;
|
||||
padding: 0.4em 1.6em;
|
||||
margin: 0;
|
||||
box-sizing: border-box;
|
||||
display: inline-block;
|
||||
border: none;
|
||||
cursor: pointer;
|
||||
border-radius: 3px;
|
||||
}
|
||||
|
||||
.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;
|
||||
margin-right: 0.5em;
|
||||
background-color: var(--white);
|
||||
color: var(--dark);
|
||||
}
|
||||
|
||||
.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;
|
||||
.modal-button:hover {
|
||||
filter: brightness(0.9);
|
||||
}
|
||||
@@ -5,7 +5,7 @@ import './Modal.css'
|
||||
|
||||
const modalRoot = document.getElementById('modal')
|
||||
|
||||
function Modal({ children }) {
|
||||
function Modal({ children, title, content, buttons }) {
|
||||
const elRef = useRef(null)
|
||||
if (!elRef.current) {
|
||||
elRef.current = document.createElement('div')
|
||||
@@ -15,7 +15,24 @@ function Modal({ children }) {
|
||||
return () => modalRoot.removeChild(elRef.current)
|
||||
}, [])
|
||||
|
||||
return createPortal(<div className={'modal'}>{children}</div>, elRef.current)
|
||||
return createPortal(
|
||||
<div className={'modal'}>
|
||||
{children ?? (
|
||||
<>
|
||||
<div className="modal-title">{title}</div>
|
||||
<div className="modal-body">{content}</div>
|
||||
<div className="modal-buttons">
|
||||
{buttons.map(([label, e]) => (
|
||||
<button onClick={e} className="modal-button" key={label}>
|
||||
{label}
|
||||
</button>
|
||||
))}
|
||||
</div>
|
||||
</>
|
||||
)}
|
||||
</div>,
|
||||
elRef.current
|
||||
)
|
||||
}
|
||||
|
||||
export default Modal
|
||||
@@ -24,11 +24,16 @@ function Search() {
|
||||
history.replace(`/wyszukaj/${query}`)
|
||||
|
||||
search(query)
|
||||
.then(({ tracks, total }) => {
|
||||
getMultiple(tracks)
|
||||
.then((tracks) => {
|
||||
setResults(tracks)
|
||||
setMeta(`Znaleziono ${total} utworów`)
|
||||
.then(({ tids, total, elapsed }) => {
|
||||
getMultiple(tids)
|
||||
.then((tids) => {
|
||||
setResults(tids)
|
||||
setMeta(
|
||||
`Znaleziono ${total} utworów (${(
|
||||
elapsed[0] +
|
||||
elapsed[1] / 1e9
|
||||
).toPrecision(2)}s)`
|
||||
)
|
||||
})
|
||||
.catch((err) => {
|
||||
setMeta(`Wystąpił błąd podczas pobierania utworów`)
|
||||
|
||||
@@ -41,7 +41,7 @@
|
||||
cursor: pointer;
|
||||
}
|
||||
|
||||
.settings-toggle {
|
||||
.settings-sub {
|
||||
display: flex;
|
||||
justify-content: space-between;
|
||||
align-items: center;
|
||||
@@ -50,22 +50,22 @@
|
||||
margin-bottom: 0.2em;
|
||||
text-decoration: none;
|
||||
color: inherit;
|
||||
cursor: pointer;
|
||||
}
|
||||
|
||||
.settings-toggle i {
|
||||
.settings-sub i {
|
||||
color: var(--dark);
|
||||
}
|
||||
|
||||
.settings-toggle[data-value='true'] i {
|
||||
.settings-sub.toggle[data-value='true'] .toggle i {
|
||||
color: var(--main);
|
||||
}
|
||||
|
||||
.settings-toggle:hover {
|
||||
.settings-sub.external:hover,
|
||||
.settings-sub.toggle:hover {
|
||||
color: var(--main);
|
||||
}
|
||||
|
||||
.toggle {
|
||||
font-size: 1.2em;
|
||||
cursor: pointer;
|
||||
}
|
||||
|
||||
.toggle i {
|
||||
font-size: 1.2em;
|
||||
}
|
||||
@@ -1,8 +1,15 @@
|
||||
import { useState } from 'react/cjs/react.development'
|
||||
import { useContext, useState } from 'react/cjs/react.development'
|
||||
|
||||
import { promptLogin, credentials, clearCredentials } from '../../Auth'
|
||||
|
||||
import SettingsContext from '../../contexts/Settings'
|
||||
|
||||
import './Settings.css'
|
||||
|
||||
const defaults = {
|
||||
hueFromArt: true,
|
||||
}
|
||||
|
||||
function Toggle({ value }) {
|
||||
return (
|
||||
<div className="toggle">
|
||||
@@ -11,13 +18,34 @@ function Toggle({ value }) {
|
||||
)
|
||||
}
|
||||
|
||||
function SettingToggle({ children, defaultValue }) {
|
||||
const [value, setValue] = useState(defaultValue ?? false)
|
||||
function External({ href, content, target = '_blank' }) {
|
||||
return (
|
||||
<a href={href} target={target} className="settings-sub external">
|
||||
{content} <i className="icon-export"></i>
|
||||
</a>
|
||||
)
|
||||
}
|
||||
|
||||
function Plain({ content }) {
|
||||
return (
|
||||
<div className="settings-sub plain">
|
||||
{content} <i className="icon-info"></i>
|
||||
</div>
|
||||
)
|
||||
}
|
||||
|
||||
function SettingToggle({ children, id }) {
|
||||
const { settings, setSettings } = useContext(SettingsContext),
|
||||
[value, setValue] = useState(settings[id] ?? defaults[id] ?? false)
|
||||
|
||||
return (
|
||||
<div
|
||||
className="settings-toggle"
|
||||
className="settings-sub toggle"
|
||||
data-value={value}
|
||||
onClick={() => setValue((value) => !value)}
|
||||
onClick={() => {
|
||||
setValue((value) => !value)
|
||||
setSettings(id, value)
|
||||
}}
|
||||
>
|
||||
{children}
|
||||
<Toggle value={value} />
|
||||
@@ -54,29 +82,33 @@ function Settings() {
|
||||
|
||||
{creds.token ? null : (
|
||||
<div className="settings-part body">
|
||||
<strong>Zaloguj się</strong> aby móc głosować więcej niż na jeden
|
||||
utwór
|
||||
<b>Zaloguj się</b> aby móc głosować więcej niż na jeden utwór
|
||||
</div>
|
||||
)}
|
||||
|
||||
<div className="settings-part">
|
||||
<SettingToggle defaultValue={false}>
|
||||
<SettingToggle id="hueFromArt">
|
||||
Ustawiaj kolorystyke strony na podstawie okładki albumu
|
||||
</SettingToggle>
|
||||
<SettingToggle>Lorem ipsum dolor sit amet</SettingToggle>
|
||||
</div>
|
||||
|
||||
{/* Terms of Service and other usefull links */}
|
||||
<div className="settings-part">
|
||||
<a href="/tos.html" target="_blank" className="settings-toggle">
|
||||
Regulamin korzystania ze strony <i className="icon-export"></i>
|
||||
</a>
|
||||
<a href="/privacy.html" target="_blank" className="settings-toggle">
|
||||
Zasady prywatności (RODO) <i className="icon-export"></i>
|
||||
</a>
|
||||
<External href="/tos.html" content="Regulamin korzystania ze strony" />
|
||||
<External href="/privacy.html" content="Zasady prywatności (RODO)" />
|
||||
</div>
|
||||
|
||||
<div className="settings-part">
|
||||
<Plain
|
||||
content={`Autorzy aplikacji: ${[
|
||||
'Mateusz Pstrucha',
|
||||
'Sebastian Fudalej',
|
||||
].join(', ')}`}
|
||||
/>
|
||||
</div>
|
||||
</div>
|
||||
)
|
||||
}
|
||||
|
||||
export default Settings
|
||||
export { defaults }
|
||||
@@ -1,10 +1,11 @@
|
||||
import { useContext, useEffect, useState } from 'react'
|
||||
import { Link } from 'react-router-dom'
|
||||
|
||||
import { setColor } from '../../Color'
|
||||
import { setColor, setDefault } from '../../Color'
|
||||
import { socket } from '../../socket'
|
||||
|
||||
import PlayingContext from '../../contexts/Playing'
|
||||
import SettingsContext from '../../contexts/Settings'
|
||||
|
||||
import './Status.css'
|
||||
import def from '../../media/default.png'
|
||||
@@ -17,14 +18,16 @@ function Status({ progress, paused }) {
|
||||
album = {},
|
||||
duration,
|
||||
} = useContext(PlayingContext),
|
||||
[elapsed, setElapsed] = useState()
|
||||
[elapsed, setElapsed] = useState(),
|
||||
{ settings } = useContext(SettingsContext)
|
||||
|
||||
const step = 1e3,
|
||||
tread = step / duration
|
||||
|
||||
useEffect(() => {
|
||||
if (album.art) setColor(album.art, 1)
|
||||
}, [album.art])
|
||||
if (!settings.hueFromArt) setDefault()
|
||||
else if (album.art) setColor(album.art, 1)
|
||||
}, [album.art, settings.hueFromArt])
|
||||
|
||||
useEffect(() => {
|
||||
setElapsed(progress ? progress / duration : 0)
|
||||
|
||||
@@ -1,6 +1,10 @@
|
||||
import { useState, createContext, useContext } from 'react'
|
||||
import { Link, useHistory } from 'react-router-dom'
|
||||
|
||||
import { credentials } from '../../Auth'
|
||||
|
||||
import ModalLoginContext from '../../contexts/ModalLogin'
|
||||
|
||||
import './Track.css'
|
||||
import def from '../../media/default.png'
|
||||
|
||||
@@ -26,13 +30,16 @@ function Track({ track, timestamp, displayRank = false }) {
|
||||
stats = {},
|
||||
} = track ?? {},
|
||||
history = useHistory(),
|
||||
tracklist = useContext(TracklistContext)
|
||||
tracklist = useContext(TracklistContext),
|
||||
{ setModalLogin } = useContext(ModalLoginContext)
|
||||
|
||||
function vote(value) {
|
||||
if (!credentials.token) return setModalLogin(true)
|
||||
|
||||
track
|
||||
.setVote(value)
|
||||
.then((ok) => ok && tracklist.setActive(false))
|
||||
.catch((err) => console.error(err))
|
||||
.catch((err) => console.error(err)) // TODO: alert on error
|
||||
}
|
||||
|
||||
function info() {
|
||||
|
||||
@@ -0,0 +1,5 @@
|
||||
import { createContext } from 'react'
|
||||
|
||||
const ModalLoginContext = createContext()
|
||||
|
||||
export default ModalLoginContext
|
||||
@@ -0,0 +1,5 @@
|
||||
import { createContext } from 'react'
|
||||
|
||||
const SettingsContext = createContext('settings')
|
||||
|
||||
export default SettingsContext
|
||||
+1
-5
@@ -6,7 +6,7 @@ body {
|
||||
-webkit-font-smoothing: antialiased;
|
||||
-moz-osx-font-smoothing: grayscale;
|
||||
|
||||
background-image: url('https://i1.wp.com/www.estidia.eu/wp-content/uploads/2018/04/Savin-NY-Website-Background-Web.jpg?fit=848%2C477');
|
||||
background-image: url('./media/skyline.jpg');
|
||||
background-size: cover;
|
||||
background-color: var(--light);
|
||||
background-blend-mode: multiply;
|
||||
@@ -40,7 +40,3 @@ body {
|
||||
background-color: var(--main);
|
||||
}
|
||||
}
|
||||
|
||||
strong {
|
||||
font-weight: bold;
|
||||
}
|
||||
File renamed without changes.
Reference in new issue
Block a user