fix: envs, arts, etc

This commit is contained in:
Mateusz Pstrucha committed 2021-10-05 11:55:28 +02:00
1 parent abc89ac1c7
commit ca8908aa6e
14 files changed
+150 -45

No files matched your search

+3
View File
@@ -0,0 +1,3 @@
REACT_APP_WS_SERVER=wss://radio.rolniknysa.pl/ws/
REACT_APP_SPOTIFY_REDIRECTURI=http://radio.rolniknysa.pl/api/login/token
+15
View File
@@ -0,0 +1,15 @@
# radio-rolnik
## Resources
https://github.com/Maathias/radio-rolnik-api/
https://github.com/Maathias/radio-rolnik-player/
## .env
Environment variables required
```ini
REACT_APP_WS_SERVER=radio.rolniknysa.pl
```
+10 -3
View File
@@ -5349,9 +5349,9 @@
}
},
"dotenv": {
"version": "8.2.0",
"resolved": "https://registry.npmjs.org/dotenv/-/dotenv-8.2.0.tgz",
"integrity": "sha512-8sJ78ElpbDJBHNeBzUbUVLsqKdccaa/BXF1uPTw3GrvQTBgrQrtObr2mUrE38vzYd8cEv+m/JBfDLioYcfXoaw=="
"version": "10.0.0",
"resolved": "https://registry.npmjs.org/dotenv/-/dotenv-10.0.0.tgz",
"integrity": "sha512-rlBi9d8jpv9Sf1klPjNfFAuWDjKLwTIJJ/VxtoTwIR6hnZxcEOQCZg2oIL3MWBYw5GpUDKOEnND7LXTbIpQ03Q=="
},
"dotenv-expand": {
"version": "5.1.0",
@@ -12766,6 +12766,13 @@
"webpack-dev-server": "3.11.1",
"webpack-manifest-plugin": "2.2.0",
"workbox-webpack-plugin": "5.1.4"
},
"dependencies": {
"dotenv": {
"version": "8.2.0",
"resolved": "https://registry.npmjs.org/dotenv/-/dotenv-8.2.0.tgz",
"integrity": "sha512-8sJ78ElpbDJBHNeBzUbUVLsqKdccaa/BXF1uPTw3GrvQTBgrQrtObr2mUrE38vzYd8cEv+m/JBfDLioYcfXoaw=="
}
}
},
"read-pkg": {
+1
View File
@@ -7,6 +7,7 @@
"@testing-library/jest-dom": "^5.14.1",
"@testing-library/react": "^11.2.7",
"@testing-library/user-event": "^12.8.3",
"dotenv": "^10.0.0",
"fast-average-color": "^6.4.2",
"jsonwebtoken": "^8.5.1",
"ky": "^0.28.5",
+1 -1
View File
@@ -2,7 +2,7 @@ import Jwt from 'jsonwebtoken'
import localStorage from 'local-storage'
const appId = '299948451430584',
redirectUri = `https://radio.rolniknysa.pl/api/login/token`,
redirectUri = process.env.REACT_APP_SPOTIFY_REDIRECTURI,
state = 'stejt'
var credentials = {
+1 -1
View File
@@ -12,7 +12,7 @@ class Track {
* @param {String} tdata.title
* @param {Object} tdata.album
* @param {String} tdata.album.title
* @param {String} tdata.album.art album art url
* @param {Array} tdata.album.art array of available album arts (3)
* @param {Number} tdata.album.year
* @param {Number} tdata.duration duration in milliseconds
* @param {Boolean} tdata.explicit does the track contain explicit language
+6 -1
View File
@@ -6,10 +6,15 @@
}
.history-section > span {
border-bottom: 1px solid #eeec;
display: block;
margin: 1em 0.5em 0;
color: #3a3a3a;
text-align: center;
}
.history-section > .header {
border-bottom: 1px solid #eeec;
text-align: left;
}
.history-section.now > .track {
+13 -7
View File
@@ -6,7 +6,7 @@ import PlayingContext from '../../contexts/Playing'
import './History.css'
function History({ next, tracks }) {
function History({ next, tracks, paused }) {
const playing = useContext(PlayingContext)
return (
@@ -14,18 +14,20 @@ function History({ next, tracks }) {
<Tracklist>
{next && (
<div className="history-section next">
<span>Następny:</span>
<span className="header">Następny:</span>
<Track track={next} timestamp=">" />
</div>
)}
<div className="history-section now">
<span>Gra teraz:</span>
<Track track={playing} timestamp="~" />
</div>
{!paused && (
<div className="history-section now">
<span className="header">Gra teraz:</span>
<Track track={playing} timestamp="~" />
</div>
)}
<div className="history-section previous">
<span>Poprzednie:</span>
<span className="header">Poprzednie:</span>
{tracks.map((track) => {
let time = track.timestamp
@@ -34,6 +36,10 @@ function History({ next, tracks }) {
return <Track key={track.id} track={track} timestamp={time} />
})}
{tracks.length < 1 && (
<span>Tutaj pojawią się poprzednie utwory</span>
)}
</div>
</Tracklist>
</div>
+7 -1
View File
@@ -87,8 +87,14 @@ function Info() {
return (
<div className="wrapper info">
{/* <Image
images={track.album.art}
fallback={def}
className="info-image"
alt="album cover"
/> */}
<img
src={track.album.art ?? def}
src={track.album.art ? track.album.art[0].url : def}
className="info-image"
alt="album cover"
/>
+51 -14
View File
@@ -4,7 +4,7 @@ import {
Route,
Redirect,
} from 'react-router-dom'
import { useEffect, useState } from 'react'
import { useEffect, useRef, useState } from 'react'
import ga from 'react-ga'
import localStorage from 'local-storage'
@@ -41,23 +41,50 @@ document.setTitle = (prefix, suffix) => {
ga.pageview(document.location.pathname)
}
function usePrevious(value) {
const ref = useRef()
useEffect(() => {
ref.current = value
})
return ref.current
}
function Main() {
const [playing, setPlaying] = useState({}),
[elapsed, setElapsed] = useState(0),
[elapsed, setElapsed] = useState([0, 0]),
[paused, setPaused] = useState(true),
[next, setNext] = useState(),
[previous, setPrevious] = useState([]),
[top, setTop] = useState([]),
[topDate, setTopDate] = useState(),
[modalLogin, setModalLogin] = useState(false),
[settings, setSettings] = useState(localStorage('settings') ?? defaults)
[settings, setSettings] = useState(localStorage('settings') ?? defaults),
prevPlaying = usePrevious(playing)
useEffect(() => {
addEvent('status', ({ trackid, progress, paused }) => {
get(trackid)
console.log('effect', prevPlaying?.id, playing?.id)
if (prevPlaying?.id !== playing?.id) {
if (prevPlaying?.id) {
setPrevious((prev) => [prevPlaying, ...prev])
}
}
// setPlaying((playing) => {
// console.log(playing, track, playing.id != track.id)
// if (playing.id != track.id) {
// if (playing.id)
// }
// return track
// })
}, [prevPlaying, playing])
useEffect(() => {
addEvent('status', ({ tid, progress, duration, paused, timestamp }) => {
get(tid)
.then((track) => {
track.timestamp = timestamp // insert timestamp
console.log('new status')
setPlaying(track)
setElapsed(progress)
setElapsed([progress, duration])
setPaused(paused)
})
.catch((err) => {
@@ -66,16 +93,26 @@ function Main() {
})
})
addEvent('next', ({ trackid }) => {
get(trackid)
addEvent('next', ({ tid }) => {
if (tid == null) return setNext(null)
get(tid)
.then((track) => {
setNext(track)
})
.catch((err) => console.error(err))
})
addEvent('previous', ({ trackids, timestamps }) => {
getMultiple(trackids)
addEvent('previous', ({ combo, push }) => {
if (push) {
return get(push).then((track) =>
setPrevious((prev) => [track, ...prev])
)
}
let tids = combo.map((pair) => pair[0]),
timestamps = combo.map((pair) => pair[1])
getMultiple(tids)
.then((tracks) => {
// insert timestamps to tracks
tracks.map((track, i) => (track.timestamp = timestamps[i]))
@@ -84,8 +121,8 @@ function Main() {
.catch((err) => console.error(err))
})
addEvent('top', ({ trackids, timestamp }) => {
Promise.all([getMultiple(trackids), getMultipleStats(trackids)])
addEvent('top', ({ tids, timestamp }) => {
Promise.all([getMultiple(tids), getMultipleStats(tids)])
.then(([tracks, stats]) => {
tracks.map((track, i) => (track.stats = stats[i]))
setTop(tracks)
@@ -93,7 +130,7 @@ function Main() {
})
.catch((err) => console.error(err))
})
}, [])
}, []) // eslint-disable-line
useEffect(() => {
console.log('settings changed')
@@ -117,7 +154,7 @@ function Main() {
<Router>
<Switch>
<Route exact path="/">
<History next={next} tracks={previous} />
<History next={next} tracks={previous} paused={paused} />
</Route>
<Route path="/utwor/:id?">
+6
View File
@@ -14,6 +14,7 @@
text-decoration: none;
max-width: 700px;
margin: auto;
transition: 0.4s cubic-bezier(1, 0, 0, 1);
}
.status-image {
@@ -67,6 +68,11 @@
border-radius: 100%;
}
.status.paused {
transform: scaleX(0);
opacity: 0;
}
.status.paused > .status-progress {
opacity: 0;
}
+7 -4
View File
@@ -10,13 +10,12 @@ import SettingsContext from '../../contexts/Settings'
import './Status.css'
import def from '../../media/default.png'
function Status({ progress, paused }) {
function Status({ progress: [progress, duration], paused }) {
const {
id,
title = '-',
artists = ['-'],
album = {},
duration,
} = useContext(PlayingContext),
[elapsed, setElapsed] = useState(),
{ settings } = useContext(SettingsContext)
@@ -26,7 +25,7 @@ function Status({ progress, paused }) {
useEffect(() => {
if (!settings.hueFromArt) setDefault()
else if (album.art) setColor(album.art, 1)
else if (album.art) setColor(album.art[1].url, 1)
}, [album.art, settings.hueFromArt])
useEffect(() => {
@@ -57,7 +56,11 @@ function Status({ progress, paused }) {
className={['status', paused ? 'paused' : ''].join(' ')}
to={`/utwor/${id}`}
>
<img className="status-image" alt="album cover" src={album.art ?? def} />
<img
className="status-image"
alt="album cover"
src={album.art ? album.art[1].url : def}
/>
<span className="status-track">{title}</span>
<span className="status-artist">{artists.join(', ')}</span>
<i
+24 -12
View File
@@ -59,7 +59,11 @@ function Track({ track, timestamp, displayRank = false }) {
>
{timestamp && <span className="track-timestamp">{timestamp}</span>}
{displayRank && <span className="track-rank">{stats.rank}</span>}
<img className="track-image" src={album.art ?? def} alt="album cover" />
<img
className="track-image"
src={album.art ? album.art[2].url : def}
alt="album cover"
/>
</div>
<div className="track-section-b" onClick={() => info()}>
@@ -76,25 +80,33 @@ function Track({ track, timestamp, displayRank = false }) {
></i>
</div>
<div className="track-more">
<div className="track-more-button" data-set={stats.cast === 'up'}>
<i className="icon-thumbs-up" onClick={(e) => vote('up')}></i>
<div
className="track-more-button"
data-set={stats.cast === 'up'}
onClick={(e) => vote('up')}
>
<i className="icon-thumbs-up"></i>
</div>
<div className="track-more-button" data-set={stats.cast === 'down'}>
<i className="icon-thumbs-down" onClick={(e) => vote('down')}></i>
<div
className="track-more-button"
data-set={stats.cast === 'down'}
onClick={(e) => vote('down')}
>
<i className="icon-thumbs-down"></i>
</div>
<Link to={`/utwor/${id}`} className="track-more-button">
<i className="icon-info"></i>
</Link>
<div className="track-more-button">
<i
className="icon-cancel-circled"
onClick={() => {
tracklist.setActive(false)
}}
></i>
<div
className="track-more-button"
onClick={() => {
tracklist.setActive(false)
}}
>
<i className="icon-cancel-circled"></i>
</div>
</div>
</div>
+5 -1
View File
@@ -1,10 +1,14 @@
// import dotenv from 'dotenv'
// dotenv.config()
const events = {}
let socket,
retries = 0
function open() {
socket = new WebSocket(`wss://${window.location.host}/ws/`)
socket = new WebSocket(process.env.REACT_APP_WS_SERVER)
socket.onopen = () => {
console.info(`Socket: connected`)