fix: ony one context menu per track

This commit is contained in:
Mateusz Pstrucha committed 2021-09-19 22:12:53 +02:00
1 parent faceaab33d
commit 1dee5061a1
6 files changed
+116 -58

No files matched your search

+22 -19
View File
@@ -1,6 +1,6 @@
import { useContext } from 'react'
import Track from '../Track/Track'
import Track, { Tracklist } from '../Track/Track'
import PlayingContext from '../../contexts/Playing'
@@ -11,28 +11,31 @@ function History({ next, tracks }) {
return (
<div className="wrapper history">
{next && (
<div className="history-section next">
<span>Następny:</span>
<Track track={next} timestamp=">" />
<Tracklist>
{next && (
<div className="history-section next">
<span>Następny:</span>
<Track track={next} timestamp=">" />
</div>
)}
<div className="history-section now">
<span>Gra teraz:</span>
<Track track={playing} timestamp="~" />
</div>
)}
<div className="history-section now">
<span>Gra teraz:</span>
<Track track={playing} timestamp="~" />
</div>
<div className="history-section previous">
<span>Poprzednie:</span>
<div className="history-section previous">
<span>Poprzednie:</span>
{tracks.map((track) => {
let time = track.timestamp
? new Date(track.timestamp).toISOString().slice(11, 16)
: '-:-'
{tracks.map((track) => {
let time = track.timestamp
? new Date(track.timestamp).toISOString().slice(11, 16)
: '-:-'
return <Track key={track.id} track={track} timestamp={time} />
})}
</div>
return <Track key={track.id} track={track} timestamp={time} />
})}
</div>
</Tracklist>
</div>
)
}
+11 -6
View File
@@ -1,7 +1,7 @@
import { createRef, useEffect, useState } from 'react'
import { useParams } from 'react-router-dom'
import { useParams, useHistory } from 'react-router-dom'
import Track from '../Track/Track'
import Track, { Tracklist } from '../Track/Track'
import { getMultiple, search } from '../../Cache'
import './Search.css'
@@ -12,7 +12,8 @@ function Search() {
const { query } = useParams(),
[results, setResults] = useState([]),
[meta, setMeta] = useState(''),
input = createRef()
input = createRef(),
history = useHistory()
function run(query) {
query = query.trim()
@@ -20,6 +21,8 @@ function Search() {
setMeta(`Wyszukiwanie...`)
history.replace(`/wyszukaj/${query}`)
search(query)
.then(({ tracks, total }) => {
getMultiple(tracks)
@@ -73,9 +76,11 @@ function Search() {
{meta}
</span>
)}
{results.map((track) => {
return <Track key={track.id} track={track} />
})}
<Tracklist>
{results.map((track) => {
return <Track key={track.id} track={track} />
})}
</Tracklist>
</div>
</div>
)
+8
View File
@@ -0,0 +1,8 @@
.top-header {
border-bottom: 1px solid #eeec;
display: block;
margin: 1em 0.5em 0;
color: var(--dark);
text-align: center;
font-weight: bold;
}
+16 -5
View File
@@ -1,13 +1,24 @@
import Track from '../Track/Track'
import Track, { Tracklist } from '../Track/Track'
import './Top.css'
function Top(props) {
function Top({ tracks, timestamp }) {
const date = timestamp ?? new Date(),
weekName = ['Poniedziak', 'Wtorek', 'Środa', 'Czwartek', 'Piątek'][
date.getDay()
],
day = date.toLocaleString('pl-PL')
return (
<div className="wrapper top">
{props.tracks.map((track, rank) => {
return <Track key={track.id} rank={rank + 1} track={track} />
})}
<span className="top-header">
TOP: {weekName} {timestamp ? day : '-'}
</span>
<Tracklist>
{tracks.map((track, rank) => {
return <Track key={track.id} track={track} displayRank={true} />
})}
</Tracklist>
</div>
)
}
+18 -5
View File
@@ -41,7 +41,6 @@
white-space: nowrap;
display: flex;
flex-direction: row;
align-items: center;
margin-right: 1em;
}
@@ -89,17 +88,29 @@
left: 100%;
top: 0;
border-radius: inherit;
background: hsl(12deg, 4%, 20%);
transition: 0.3s cubic-bezier(0.7, 0, 0.3, 1);
display: flex;
flex-direction: row;
color: #fff;
padding: 0.5em;
box-sizing: border-box;
justify-content: space-around;
backdrop-filter: blur(1px);
background-color: hsla(var(--deg), 35%, 22%, 71%);
}
/* .track-more:before {
content: '';
width: 100%;
height: 100%;
position: absolute;
background-color: var(--dark);
filter: blur(2px);
z-index: -1;
left: 0;
top: 0;
} */
.track.open > .track-more {
left: 0;
}
@@ -116,15 +127,17 @@
.track-more-button > i {
width: 100%;
border-radius: 1em;
margin: 0 0.5em;
}
.track-more-button > i[data-set='true'] {
.track-more-button[data-set='true'] > i {
background-color: var(--dark);
color: var(--main);
cursor: default;
}
.track-more-button:hover {
.track-more-button:not([data-set='true']):hover > i {
background-color: #fff2;
}
+41 -23
View File
@@ -1,18 +1,38 @@
import { useState } from 'react'
import { useState, createContext, useContext } from 'react'
import { Link, useHistory } from 'react-router-dom'
import './Track.css'
import def from '../../media/default.png'
function Track({ track, timestamp, rank }) {
const [open, setOpen] = useState(false),
{ id, title = '-', artists = ['-'], album = {}, cast = '' } = track ?? {},
history = useHistory()
const TracklistContext = createContext({})
function Tracklist({ children }) {
const [active, setActive] = useState(''),
value = { active, setActive }
return (
<TracklistContext.Provider value={value}>
{children}
</TracklistContext.Provider>
)
}
function Track({ track, timestamp, displayRank = false }) {
const {
id,
title = '-',
artists = ['-'],
album = {},
cast = '',
stats = {},
} = track ?? {},
history = useHistory(),
tracklist = useContext(TracklistContext)
function vote(value) {
track
.setVote(value)
.then((ok) => ok && setOpen(false))
.then((ok) => ok && tracklist.setActive(false))
.catch((err) => console.error(err))
}
@@ -21,13 +41,18 @@ function Track({ track, timestamp, rank }) {
}
return (
<div className={['track', open ? 'open' : ''].join(' ')} id={id}>
<div
className={['track', tracklist.active === id ? 'open' : ''].join(' ')}
id={id}
>
<div
className={'track-section-a ' + (timestamp || rank ? '' : 'empty')}
className={
'track-section-a ' + (timestamp || displayRank ? '' : 'empty')
}
onClick={() => info()}
>
{timestamp && <span className="track-timestamp">{timestamp}</span>}
{rank && <span className="track-rank">{rank}</span>}
{displayRank && <span className="track-rank">{stats.rank}</span>}
<img className="track-image" src={album.art ?? def} alt="album cover" />
</div>
@@ -40,25 +65,17 @@ function Track({ track, timestamp, rank }) {
<i
className="icon-ellipsis-vert"
onClick={() => {
setOpen(true)
tracklist.setActive(id)
}}
></i>
</div>
<div className="track-more">
<div className="track-more-button">
<i
className="icon-thumbs-up"
data-set={cast === 'up'}
onClick={(e) => vote('up')}
></i>
<div className="track-more-button" data-set={cast === 'up'}>
<i className="icon-thumbs-up" onClick={(e) => vote('up')}></i>
</div>
<div className="track-more-button">
<i
className="icon-thumbs-down"
data-set={cast === 'down'}
onClick={(e) => vote('down')}
></i>
<div className="track-more-button" data-set={cast === 'down'}>
<i className="icon-thumbs-down" onClick={(e) => vote('down')}></i>
</div>
<Link to={`/utwor/${id}`} className="track-more-button">
@@ -69,7 +86,7 @@ function Track({ track, timestamp, rank }) {
<i
className="icon-cancel-circled"
onClick={() => {
setOpen(false)
tracklist.setActive(false)
}}
></i>
</div>
@@ -79,3 +96,4 @@ function Track({ track, timestamp, rank }) {
}
export default Track
export { Track, Tracklist }