Merge pull request #8 from Maathias/defaults-and-placeholders

Defaults and placeholders
This commit was merged in pull request #8.
This commit is contained in:
Mateusz Pstrucha authored and GitHub committed 2021-09-10 20:33:23 +02:00
commit f69f265b34
16 files changed
+161 -58

No files matched your search

+1 -1
View File
@@ -37,4 +37,4 @@ function search(query) {
})
}
export { tracks, get, getMultiple, download, search }
export { tracks, get, getMultiple, search }
+7 -2
View File
@@ -5,9 +5,14 @@
font-family: 'Poppins';
}
.history > span {
.history-section > span {
border-bottom: 1px solid #eeec;
display: block;
margin: 0 0.5em;
margin: 1em 0.5em 0;
color: #3a3a3a;
}
.history-section.now > .track {
background-color: var(--main);
box-shadow: 2px 2px 4px #6363637d;
}
+22 -8
View File
@@ -11,14 +11,28 @@ function History({ next, tracks }) {
return (
<div className="wrapper history">
<span>Następny:</span>
<Track {...next} timestamp=">" />
<span>Gra teraz:</span>
<Track {...playing} timestamp="~" />
<span>Poprzednie:</span>
{tracks.map((track) => {
return <Track key={track.id} {...track} timestamp="14:33" />
})}
{next && (
<div className="history-section next">
<span>Następny:</span>
<Track {...next} timestamp=">" />
</div>
)}
<div className="history-section now">
<span>Gra teraz:</span>
<Track {...playing} timestamp="~" />
</div>
<div className="history-section previous">
<span>Poprzednie:</span>
{tracks.map((track) => {
let time = track.timestamp
? new Date(track.timestamp).toISOString().slice(11, 16)
: '-:-'
return <Track key={track.id} {...track} timestamp={time} />
})}
</div>
</div>
)
}
+4 -1
View File
@@ -8,7 +8,10 @@
}
.info-image {
height: min(20vh, 60vw);
--side: min(20vh, 60vw);
height: var(--side);
width: var(--side);
flex-shrink: 0;
margin: auto;
margin-bottom: 1em;
box-shadow: 0px 4px 16px 0px #000000b8;
+12 -4
View File
@@ -1,17 +1,21 @@
import { useEffect, useState } from 'react'
import { useParams } from 'react-router-dom'
import { get, download } from '../../Cache'
import { get } from '../../Cache'
import './Info.css'
function Info() {
const { id } = useParams(),
[track, setTrack] = useState({ votes: {}, album: {}, artists: [] })
[track, setTrack] = useState({
title: 'Tytuł',
votes: {},
album: {},
artists: ['Autor'],
})
useEffect(() => {
get(id).then((track) => {
console.log('get', track)
setTrack(track)
})
}, [id])
@@ -22,7 +26,11 @@ function Info() {
return (
<div className="wrapper info">
<img src={track.album.art} className="info-image" alt="album cover" />
<img
src={track.album.art ?? '/media/default.png'}
className="info-image"
alt="album cover"
/>
<div className="info-wrapper">
<span className="title">{track.title}</span>
<span className="artist">{track.artists[0]}</span>
+1
View File
@@ -12,4 +12,5 @@
max-width: 600px;
margin: auto;
box-sizing: border-box;
padding-bottom: 8em;
}
+4 -4
View File
@@ -13,7 +13,7 @@ import Info from '../Info/Info'
import Top from '../Top/Top'
import Search from '../Search/Search'
import { get, download } from '../../Cache'
import { get } from '../../Cache'
import PlayingContext from '../../contexts/Playing'
@@ -30,11 +30,11 @@ function Main() {
[top, setTop] = useState([])
useEffect(() => {
download('3OcyTN8Nz3bdne5aq9mMR5').then((track) => {
get('3OcyTN8Nz3bdne5aq9mMR5').then((track) => {
setPlaying(track)
setNext(track)
setPrevious([track, track, track])
setTop([track, track])
setPrevious([track])
setTop([track])
})
}, [])
+4
View File
@@ -44,6 +44,10 @@ nav {
border-radius: 3px;
}
.nav-button:hover {
text-shadow: 0px 0px 5px var(--main);
}
@media only screen and (max-width: 600px) {
.nav-button > span {
display: none;
+7 -1
View File
@@ -10,6 +10,12 @@
border-bottom: 1px solid #fffc;
padding: 0.5em 1em;
width: 100%;
margin-bottom: 1em;
box-sizing: border-box;
}
.search-meta {
display: block;
text-align: left;
margin: 1em;
color: #000a;
}
+48 -15
View File
@@ -1,19 +1,48 @@
import { useEffect, useState } from 'react'
import { createRef, useEffect, useState } from 'react'
import { useParams } from 'react-router-dom'
import Track from '../Track/Track'
import { get, getMultiple, search, tracks } from '../../Cache'
import { getMultiple, search } from '../../Cache'
import './Search.css'
function Search(props) {
const { query } = useParams(),
[results, setResults] = useState([])
let timeout
var timeout
document.setTitle(`"${query}"`)
function Search() {
const { query } = useParams(),
[results, setResults] = useState([]),
[meta, setMeta] = useState(''),
input = createRef()
function run(query) {
query = query.trim()
if (query.length < 1) return
setMeta(`Wyszukiwanie...`)
search(query)
.then(({ tracks, total }) => {
getMultiple(tracks)
.then((tracks) => {
setResults(tracks)
setMeta(`Znaleziono ${total} utworów`)
})
.catch((err) => {
setMeta(`Wystąpił błąd podczas pobierania utworów`)
})
})
.catch((err) => {
setMeta(`Wystąpił błąd podczas wyszukiwania`)
})
}
document.setTitle(query ? `"${query}"` : 'Wyszukaj')
useEffect(() => {
if (input.current.value !== '') {
run(input.current.value)
}
return () => {
clearTimeout(timeout)
}
@@ -27,19 +56,23 @@ function Search(props) {
placeholder="Wyszukaj utwór"
type="text"
defaultValue={query}
ref={input}
onChange={(e) => {
const query = e.target.value
clearTimeout(timeout)
timeout = setTimeout(() => {
search(query).then(({ tracks, total }) => {
getMultiple(tracks).then((tracks) => setResults(tracks))
})
}, 500)
timeout = setTimeout(() => run(e.target.value), 1e3)
}}
onKeyPress={(e) => {
clearTimeout(timeout)
if (e.key === 'Enter') run(e.target.value)
}}
/>
<div className="search-results">
{meta && (
<span className="search-meta">
<i className="icon-align-left"></i>&nbsp;
{meta}
</span>
)}
{results.map((track) => {
return <Track key={track.id} {...track} />
})}
+6 -1
View File
@@ -15,6 +15,7 @@
.status-image {
height: 3em;
width: 3em;
float: left;
margin-right: 0.5em;
border-radius: 0.5em;
@@ -46,7 +47,7 @@
bottom: 0;
border-bottom: 2px solid white;
border-radius: 2px;
transition: 1s linear;
transition: 0.5s linear width, 0.3s ease-out opacity;
}
.status-progress:after {
@@ -59,3 +60,7 @@
background-color: white;
border-radius: 100%;
}
.status.paused > .status-progress {
opacity: 0;
}
+31 -16
View File
@@ -5,43 +5,58 @@ import PlayingContext from '../../contexts/Playing'
import './Status.css'
function Status(props) {
function Status({ progress, paused, onEnd }) {
const {
id,
title,
artists = [],
title = '-',
artists = ['-'],
album = {},
duration,
} = useContext(PlayingContext),
[progress, setProgress] = useState(0)
[elapsed, setElapsed] = useState()
const step = 1 / duration
const step = 500,
tread = step / duration
useEffect(() => {
setElapsed(progress ? progress / duration : 0)
}, [progress, duration])
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
if (!paused) {
if (elapsed < 1) {
anim = setTimeout(() => {
setElapsed(elapsed + tread)
}, step)
} else if (elapsed > 1) {
setElapsed(1) // if FPU decides that 1 / duration * duration !== 1
}
}
return () => {
clearInterval(anim)
clearTimeout(anim)
}
},
[progress, step]
[elapsed, tread, paused]
)
return (
<Link className="status" to={`/utwor/${id}`}>
<img className="status-image" alt="album cover" src={album.art} />
<Link
className={['status', paused ? 'paused' : ''].join(' ')}
to={`/utwor/${id}`}
>
<img
className="status-image"
alt="album cover"
src={album.art ?? '/media/default.png'}
/>
<span className="status-track">{title}</span>
<span className="status-artist">{artists.join(', ')}</span>
<i className="icon-info"></i>
<div
className="status-progress"
style={{ width: `calc(var(--max) * ${progress})` }}
style={{ width: `calc(var(--max) * ${elapsed})` }}
></div>
</Link>
)
+2 -2
View File
@@ -5,8 +5,8 @@ import './Top.css'
function Top(props) {
return (
<div className="wrapper top">
{props.tracks.map((track) => {
return <Track key={track.id} rank={track.votes.rank} {...track} />
{props.tracks.map((track, rank) => {
return <Track key={track.id} rank={rank + 1} {...track} />
})}
</div>
)
+3 -1
View File
@@ -41,6 +41,7 @@
.track-timestamp {
font-size: 0.75em;
margin-left: -0.4em;
}
.track-rank:before {
@@ -48,7 +49,8 @@
}
.track-image {
height: 100%;
height: 2em;
width: 2em;
border-radius: 3px;
}
+8 -1
View File
@@ -2,7 +2,14 @@ import { useState } from 'react'
import { Link } from 'react-router-dom'
import './Track.css'
function Track({ id, title, artists = [], album = {}, timestamp, rank }) {
function Track({
id,
title = '-',
artists = ['-'],
album = {},
timestamp,
rank,
}) {
const [open, setOpen] = useState(false)
return (
+1 -1
View File
@@ -10,7 +10,7 @@ body {
:root {
--deg: 170deg;
--white: hsl(0, 0%, 100%);
--light: hsl(var(--deg) 50% 92%);
--light: hsl(var(--deg) 50% 88%);
--main: hsl(var(--deg), 57%, 52%);
--dark: hsl(var(--deg) 55% 22%);
}