Const overhaul #4
No files matched your search
@@ -6,17 +6,17 @@ import PlayingContext from '../../contexts/Playing'
|
||||
|
||||
import './History.css'
|
||||
|
||||
function History(props) {
|
||||
let playing = useContext(PlayingContext)
|
||||
function History({ next, tracks }) {
|
||||
const playing = useContext(PlayingContext)
|
||||
|
||||
return (
|
||||
<div className="wrapper history">
|
||||
<span>Następny:</span>
|
||||
<Track {...props.next} timestamp=">" />
|
||||
<Track {...next} timestamp=">" />
|
||||
<span>Gra teraz:</span>
|
||||
<Track {...playing} timestamp="~" />
|
||||
<span>Poprzednie:</span>
|
||||
{props.tracks.map((track) => {
|
||||
{tracks.map((track) => {
|
||||
return <Track key={track.id} {...track} timestamp="14:33" />
|
||||
})}
|
||||
</div>
|
||||
|
||||
@@ -5,10 +5,10 @@ import { get } from '../../Cache'
|
||||
import './Info.css'
|
||||
|
||||
function Info() {
|
||||
let { id } = useParams(),
|
||||
const { id } = useParams(),
|
||||
track = get(id)
|
||||
|
||||
let percent = (track.votes.up / (track.votes.up + track.votes.down)) * 100
|
||||
const percent = (track.votes.up / (track.votes.up + track.votes.down)) * 100
|
||||
|
||||
document.title = `${track.title} | radio-rolnik`
|
||||
|
||||
|
||||
@@ -24,7 +24,7 @@ document.setTitle = (prefix, suffix) => {
|
||||
}
|
||||
|
||||
function Main() {
|
||||
let [playing] = useState({
|
||||
const [playing] = useState({
|
||||
...get('2340q8ghedsnawg1'),
|
||||
})
|
||||
|
||||
|
||||
+17
-18
@@ -2,25 +2,24 @@ import { useEffect, useState } from 'react'
|
||||
import { Link } from 'react-router-dom'
|
||||
import { useLocation } from 'react-router-dom'
|
||||
|
||||
|
||||
import './Nav.css'
|
||||
|
||||
function Button(props) {
|
||||
function Button({ to, onClick, active, icon, label }) {
|
||||
return (
|
||||
<Link
|
||||
to={props.to}
|
||||
onClick={props.onClick}
|
||||
className={`nav-button ${props.active ? 'active' : ''}`}
|
||||
to={to}
|
||||
onClick={onClick}
|
||||
className={`nav-button ${active ? 'active' : ''}`}
|
||||
>
|
||||
<i className={`icon-${props.icon}`}></i>
|
||||
<span>{props.label}</span>
|
||||
<i className={`icon-${icon}`}></i>
|
||||
<span>{label}</span>
|
||||
</Link>
|
||||
)
|
||||
}
|
||||
|
||||
function Nav(props) {
|
||||
function Nav({ buttons }) {
|
||||
function getTab() {
|
||||
return props.buttons
|
||||
return buttons
|
||||
.slice()
|
||||
.reverse()
|
||||
.find((button) =>
|
||||
@@ -28,12 +27,12 @@ function Nav(props) {
|
||||
).label
|
||||
}
|
||||
|
||||
let [current, setCurrent] = useState(getTab()),
|
||||
const [current, setCurrent] = useState(getTab()),
|
||||
location = useLocation()
|
||||
|
||||
useEffect(() => {
|
||||
setCurrent(getTab())
|
||||
let label = (function () {
|
||||
const label = (function () {
|
||||
switch (current) {
|
||||
default:
|
||||
case 'History':
|
||||
@@ -52,14 +51,14 @@ function Nav(props) {
|
||||
|
||||
return (
|
||||
<nav className="nav">
|
||||
{props.buttons.map((button) => (
|
||||
{buttons.map(({ label, icon, to }) => (
|
||||
<Button
|
||||
key={button.label}
|
||||
label={button.label}
|
||||
icon={button.icon}
|
||||
active={button.label === current}
|
||||
to={button.to}
|
||||
onClick={() => setCurrent(button.label)}
|
||||
key={label}
|
||||
label={label}
|
||||
icon={icon}
|
||||
active={label === current}
|
||||
to={to}
|
||||
onClick={() => setCurrent(label)}
|
||||
/>
|
||||
))}
|
||||
</nav>
|
||||
|
||||
@@ -7,9 +7,9 @@ import { search } from '../../Cache'
|
||||
import './Search.css'
|
||||
|
||||
function Search(props) {
|
||||
let { query } = useParams(),
|
||||
[results, setResults] = useState([]),
|
||||
timeout
|
||||
const { query } = useParams(),
|
||||
[results, setResults] = useState([])
|
||||
let timeout
|
||||
|
||||
document.setTitle(`"${query}"`)
|
||||
|
||||
@@ -17,7 +17,7 @@ function Search(props) {
|
||||
return () => {
|
||||
clearTimeout(timeout)
|
||||
}
|
||||
}, [])
|
||||
}, []) // eslint-disable-line react-hooks/exhaustive-deps
|
||||
|
||||
return (
|
||||
<div className="wrapper search">
|
||||
|
||||
@@ -6,23 +6,32 @@ import PlayingContext from '../../contexts/Playing'
|
||||
import './Status.css'
|
||||
|
||||
function Status(props) {
|
||||
let playing = useContext(PlayingContext),
|
||||
const { id, album, title, duration, artists } = useContext(PlayingContext),
|
||||
[progress, setProgress] = useState(0)
|
||||
|
||||
let step = 1 / playing.duration
|
||||
const step = 1 / duration
|
||||
|
||||
useEffect(() => {
|
||||
let anim = setInterval(() => {
|
||||
setProgress((progress += step))
|
||||
if (progress >= 1) clearInterval(anim)
|
||||
}, 1e3)
|
||||
}, [])
|
||||
useEffect(
|
||||
(anim) => {
|
||||
if (progress < 1) {
|
||||
anim = setTimeout(() => {
|
||||
setProgress(progress + step)
|
||||
}, 1e3)
|
||||
} else if (progress > 1) {
|
||||
setProgress(1) // if FPU decides that 1 / duration * duration !== 1
|
||||
}
|
||||
return () => {
|
||||
clearInterval(anim)
|
||||
}
|
||||
},
|
||||
[progress, step]
|
||||
)
|
||||
|
||||
return (
|
||||
<Link className="status" to={`/utwor/${playing.id}`}>
|
||||
<img className="status-image" alt="album cover" src={playing.album.art} />
|
||||
<span className="status-track">{playing.title}</span>
|
||||
<span className="status-artist">{playing.artists.join(', ')}</span>
|
||||
<Link className="status" to={`/utwor/${id}`}>
|
||||
<img className="status-image" alt="album cover" src={album.art} />
|
||||
<span className="status-track">{title}</span>
|
||||
<span className="status-artist">{artists.join(', ')}</span>
|
||||
<i className="icon-info"></i>
|
||||
<div
|
||||
className="status-progress"
|
||||
|
||||
@@ -2,32 +2,26 @@ import { useState } from 'react'
|
||||
import { Link } from 'react-router-dom'
|
||||
import './Track.css'
|
||||
|
||||
function Track(props) {
|
||||
let [open, setOpen] = useState(false)
|
||||
function Track({ timestamp, rank, album, id, title, artists }) {
|
||||
const [open, setOpen] = useState(false)
|
||||
|
||||
return (
|
||||
<div className={['track', open ? 'open' : ''].join(' ')}>
|
||||
<div
|
||||
className={
|
||||
'track-section-a ' + (props.timestamp || props.rank ? '' : 'empty')
|
||||
}
|
||||
>
|
||||
{props.timestamp && (
|
||||
<span className="track-timestamp">{props.timestamp}</span>
|
||||
)}
|
||||
{props.rank && <span className="track-rank">{props.rank}</span>}
|
||||
<div className={'track-section-a ' + (timestamp || rank ? '' : 'empty')}>
|
||||
{timestamp && <span className="track-timestamp">{timestamp}</span>}
|
||||
{rank && <span className="track-rank">{rank}</span>}
|
||||
<img
|
||||
className="track-image"
|
||||
src={props.album.art ?? '/media/default.png'}
|
||||
src={album.art ?? '/media/default.png'}
|
||||
alt="album cover"
|
||||
/>
|
||||
</div>
|
||||
|
||||
<div className="track-section-b">
|
||||
<Link to={`/utwor/${props.id}`} className="track-title">
|
||||
{props.title}
|
||||
<Link to={`/utwor/${id}`} className="track-title">
|
||||
{title}
|
||||
</Link>
|
||||
<span className="track-artist">{props.artists.join(', ')}</span>
|
||||
<span className="track-artist">{artists.join(', ')}</span>
|
||||
</div>
|
||||
|
||||
<div className="track-icons">
|
||||
@@ -45,7 +39,7 @@ function Track(props) {
|
||||
<div className="track-more-button">
|
||||
<i className="icon-thumbs-down"></i>
|
||||
</div>
|
||||
<Link to={`/utwor/${props.id}`} className="track-more-button">
|
||||
<Link to={`/utwor/${id}`} className="track-more-button">
|
||||
<i className="icon-info"></i>
|
||||
</Link>
|
||||
<div
|
||||
|
||||
Reference in new issue
Block a user