Compare commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
eb1dc891e2 | ||
|
|
0cd0b3920c | ||
|
|
a0f7acfecf | ||
|
|
21d1c45c94 | ||
|
|
b57fc7bd80 | ||
|
|
ed3673bbbe | ||
|
|
e71cc10f91 | ||
|
|
7b98f02f0e | ||
|
|
f5cde7a24c | ||
|
|
4ceb4694cc | ||
|
|
04d6c4a0be | ||
|
|
20a53744f7 | ||
|
|
5b72299c82 | ||
|
|
e15943050f | ||
|
|
9364444a03 | ||
|
|
7488b96a7d | ||
|
|
9dec4cf96f | ||
|
|
771789ba8e | ||
|
|
836cd10f77 | ||
|
|
ba8bbf45ac | ||
|
|
1ca53d7bea | ||
|
|
d3638a10d7 | ||
|
|
ca8908aa6e | ||
|
|
abc89ac1c7 | ||
|
|
09a065d11f | ||
|
|
8ae286d248 | ||
|
|
94d10d52cf | ||
|
|
38407959a6 | ||
|
|
1dee5061a1 | ||
|
|
b65088204e | ||
|
|
faceaab33d |
No files matched your search
@@ -0,0 +1,5 @@
|
|||||||
|
REACT_APP_WS_SERVER=wss://radio.rolniknysa.pl/ws/
|
||||||
|
REACT_APP_DOMAIN=radio.rolniknysa.pl
|
||||||
|
REACT_APP_NAME=radio-rolnik
|
||||||
|
|
||||||
|
REACT_APP_FB_REDIRECTURI=https://radio.rolniknysa.pl/api/login/token
|
||||||
-12
@@ -1,12 +0,0 @@
|
|||||||
FROM node:14-stretch AS build
|
|
||||||
WORKDIR /build
|
|
||||||
COPY package-lock.json package.json ./
|
|
||||||
RUN npm ci
|
|
||||||
COPY . .
|
|
||||||
|
|
||||||
|
|
||||||
FROM node:14-alpine AS deploy
|
|
||||||
USER node
|
|
||||||
WORKDIR /home/node/src
|
|
||||||
COPY --from=build --chown=node:node /build .
|
|
||||||
CMD ["npm", "start"]
|
|
||||||
@@ -0,0 +1,29 @@
|
|||||||
|
# radio-rolnik
|
||||||
|
|
||||||
|
<p float="left">
|
||||||
|
<img src="img/ss_history.png" width="49%" />
|
||||||
|
<img src="img/ss_track.png" width="49%" />
|
||||||
|
</p>
|
||||||
|
|
||||||
|
|
||||||
|
## Resources
|
||||||
|
|
||||||
|
API - [Maathias/radio-rolnik-api/](https://github.com/Maathias/radio-rolnik-api/)
|
||||||
|
|
||||||
|
Player - [Maathias/radio-rolnik-player/](https://github.com/Maathias/radio-rolnik-player/)
|
||||||
|
|
||||||
|
## .env
|
||||||
|
|
||||||
|
```ini
|
||||||
|
REACT_APP_WS_SERVER=wss://radio.rolniknysa.pl/ws/
|
||||||
|
REACT_APP_DOMAIN=radio.rolniknysa.pl
|
||||||
|
REACT_APP_NAME=radio-rolnik
|
||||||
|
|
||||||
|
REACT_APP_FB_REDIRECTURI=https://radio.rolniknysa.pl/api/login/token
|
||||||
|
```
|
||||||
|
|
||||||
|
## Usage
|
||||||
|
|
||||||
|
`yarn start` for develompent server
|
||||||
|
|
||||||
|
`yarn build` for production build
|
||||||
@@ -1,7 +0,0 @@
|
|||||||
version: '3'
|
|
||||||
|
|
||||||
services:
|
|
||||||
web:
|
|
||||||
build: .
|
|
||||||
ports:
|
|
||||||
- 3000:3000
|
|
||||||
Binary file not shown.
|
After Width: | Height: | Size: 104 KiB |
Binary file not shown.
|
After Width: | Height: | Size: 116 KiB |
Generated
-16545
File diff suppressed because it is too large.
Load diff
+4
-1
@@ -7,8 +7,11 @@
|
|||||||
"@testing-library/jest-dom": "^5.14.1",
|
"@testing-library/jest-dom": "^5.14.1",
|
||||||
"@testing-library/react": "^11.2.7",
|
"@testing-library/react": "^11.2.7",
|
||||||
"@testing-library/user-event": "^12.8.3",
|
"@testing-library/user-event": "^12.8.3",
|
||||||
|
"dotenv": "^10.0.0",
|
||||||
"fast-average-color": "^6.4.2",
|
"fast-average-color": "^6.4.2",
|
||||||
|
"jsonwebtoken": "^8.5.1",
|
||||||
"ky": "^0.28.5",
|
"ky": "^0.28.5",
|
||||||
|
"local-storage": "^2.0.0",
|
||||||
"react": "^17.0.2",
|
"react": "^17.0.2",
|
||||||
"react-dom": "^17.0.2",
|
"react-dom": "^17.0.2",
|
||||||
"react-ga": "^3.3.0",
|
"react-ga": "^3.3.0",
|
||||||
@@ -41,4 +44,4 @@
|
|||||||
"last 1 safari version"
|
"last 1 safari version"
|
||||||
]
|
]
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
+9
-10
@@ -14,23 +14,22 @@
|
|||||||
<meta name="keywords" content="radio, rolnik">
|
<meta name="keywords" content="radio, rolnik">
|
||||||
<meta name="author" content="Mathias">
|
<meta name="author" content="Mathias">
|
||||||
<title>radio-rolnik</title>
|
<title>radio-rolnik</title>
|
||||||
|
<meta name="google-site-verification" content="X202JcXlBt0U8ej5LjzpYFGRrwSHZrIN8QwfNEcqaig" />
|
||||||
<link rel="stylesheet" href="/fontello.css">
|
<link rel="stylesheet" href="/fontello.css">
|
||||||
|
|
||||||
<!-- Social embed properties -->
|
<!-- Social embed properties -->
|
||||||
<!-- <meta property="og:type" content="website" />
|
<meta property="og:type" content="website" />
|
||||||
<meta property="og:url" content="https://radio-rolnik.mtps.pl/" />
|
<meta property="og:url" content="https://%REACT_APP_DOMAIN%/" />
|
||||||
|
|
||||||
<meta property="og:title" content="radio-rolnik" />
|
<meta property="og:title" content="%REACT_APP_NAME%" />
|
||||||
<meta property="twitter:title" content="radio-rolnik" />
|
<meta property="twitter:title" content="%REACT_APP_NAME%" />
|
||||||
|
|
||||||
<meta property="og:description" content="radio-rolnik" />
|
<meta property="og:description" content="%REACT_APP_NAME%" />
|
||||||
<meta property="twitter:description" content="radio-rolnik" />
|
<meta property="twitter:description" content="%REACT_APP_NAME%" />
|
||||||
|
|
||||||
<meta property="og:image" content="https://radio-rolnik.mtps.pl/media/thumbnail.png" />
|
<meta property="og:image" content="https://%REACT_APP_DOMAIN%/media/banner.png" />
|
||||||
<meta property="twitter:image" content="https://radio-rolnik.mtps.pl/media/thumbnail.png" /> -->
|
<meta property="twitter:image" content="https://%REACT_APP_DOMAIN%/media/banner.png" />
|
||||||
|
|
||||||
<!-- <script src="https://www.google.com/recaptcha/api.js?render=6LfdNtIaAAAAAMY6rU7Q9tMlJtlz8k49ke5rUOaU"></script> -->
|
|
||||||
</head>
|
</head>
|
||||||
|
|
||||||
<body>
|
<body>
|
||||||
|
|||||||
Binary file not shown.
|
After Width: | Height: | Size: 2.4 MiB |
Binary file not shown.
|
After Width: | Height: | Size: 6.0 KiB |
@@ -0,0 +1,49 @@
|
|||||||
|
<!DOCTYPE html>
|
||||||
|
<html lang="en">
|
||||||
|
|
||||||
|
<head>
|
||||||
|
<meta charset="UTF-8">
|
||||||
|
<meta http-equiv="X-UA-Compatible" content="IE=edge">
|
||||||
|
<meta name="viewport" content="width=device-width, initial-scale=1.0">
|
||||||
|
<title>Polityka Prywatności</title>
|
||||||
|
</head>
|
||||||
|
|
||||||
|
<body>
|
||||||
|
<h1>Polityka prywatności</h1>
|
||||||
|
<ol style="max-width: min(100%, 40rem);">
|
||||||
|
<li>Logowanie
|
||||||
|
</li>
|
||||||
|
<p>Strona używa logowania przez platformę Facebook do autentykacji użytkowników, w celu zminimalizowania spamu i
|
||||||
|
nadużywania systemu głosowania</p>
|
||||||
|
|
||||||
|
<li>
|
||||||
|
Jakie dane są wykorzystywane?
|
||||||
|
</li>
|
||||||
|
<p>
|
||||||
|
Do implementacji logowania używamy nazwy profilu użytego do logowania (najczęściej imię i nazwisko) oraz jego ID.
|
||||||
|
</p>
|
||||||
|
|
||||||
|
<li>
|
||||||
|
W jakim celu używamy twoich danych?
|
||||||
|
</li>
|
||||||
|
<p>
|
||||||
|
Nazwa i ID to minimalna ilość danych które potrzebujemy aby stworzyć profil użytkownika, potrzebny do rejestracji
|
||||||
|
twoich głosów. Są wykorzystywane tylko i wyłącznie wewnętrznie, nie są dostępne dla innych użytkowników.
|
||||||
|
</p>
|
||||||
|
|
||||||
|
<li>Czy przekazujemy komuś twoje dane?</li>
|
||||||
|
<p>
|
||||||
|
Nie. Wszystkie informacje o użytkownikach, ich głosach oraz innych statystykach nigdy nie opuszczają naszej bazy
|
||||||
|
danych.
|
||||||
|
</p>
|
||||||
|
|
||||||
|
<li>Jak usunąć moje konto?</li>
|
||||||
|
<p>
|
||||||
|
Głosy przedawniają się po miesiącu, a jeżeli interesuje cie usunięcie u nas wszystkich śladów po sobie, napisz
|
||||||
|
maila do "pstrucha.mateusz@gmail.com", w ciągu dwóch dni roboczych dane zostaną usunięte.
|
||||||
|
</p>
|
||||||
|
</ol>
|
||||||
|
<span>radio-rolnik, 2021</span>
|
||||||
|
</body>
|
||||||
|
|
||||||
|
</html>
|
||||||
@@ -0,0 +1 @@
|
|||||||
|
terms of service
|
||||||
@@ -0,0 +1,16 @@
|
|||||||
|
import ky from 'ky'
|
||||||
|
|
||||||
|
import { credentials } from './Auth'
|
||||||
|
|
||||||
|
const admin = {
|
||||||
|
ban: (tid) => {
|
||||||
|
return ky
|
||||||
|
.get(`/api/admin/ban/`, {
|
||||||
|
searchParams: { tid },
|
||||||
|
headers: { authorization: credentials.token },
|
||||||
|
})
|
||||||
|
.json()
|
||||||
|
},
|
||||||
|
}
|
||||||
|
|
||||||
|
export default admin
|
||||||
+48
@@ -0,0 +1,48 @@
|
|||||||
|
import localStorage from 'local-storage'
|
||||||
|
|
||||||
|
const appId = '299948451430584',
|
||||||
|
redirectUri = process.env.REACT_APP_FB_REDIRECTURI,
|
||||||
|
state = 'stejt'
|
||||||
|
|
||||||
|
var credentials = {
|
||||||
|
token: localStorage('token') ?? '',
|
||||||
|
udata: localStorage('udata') ?? {},
|
||||||
|
}
|
||||||
|
|
||||||
|
function promptLogin() {
|
||||||
|
return new Promise((resolve, reject) => {
|
||||||
|
let popup = window.open(
|
||||||
|
`https://www.facebook.com/v11.0/dialog/oauth?client_id=${appId}&redirect_uri=${redirectUri}&state=${state}`,
|
||||||
|
`Zaloguj się przez Facebook`,
|
||||||
|
`scrollbars=no,resizable=no,status=no,location=no,toolbar=no,menubar=no,width=400,height=550`
|
||||||
|
)
|
||||||
|
|
||||||
|
let interval = setInterval(() => {
|
||||||
|
if (popup.closed) {
|
||||||
|
credentials = {
|
||||||
|
token: localStorage('token'),
|
||||||
|
udata: localStorage('udata'),
|
||||||
|
}
|
||||||
|
|
||||||
|
resolve(credentials)
|
||||||
|
clearInterval(interval)
|
||||||
|
}
|
||||||
|
}, 500)
|
||||||
|
})
|
||||||
|
}
|
||||||
|
|
||||||
|
function clearCredentials() {
|
||||||
|
return new Promise((resolve, reject) => {
|
||||||
|
credentials = {
|
||||||
|
token: '',
|
||||||
|
udata: {},
|
||||||
|
}
|
||||||
|
|
||||||
|
localStorage('token', credentials.token)
|
||||||
|
localStorage('udata', credentials.udata)
|
||||||
|
|
||||||
|
resolve(credentials)
|
||||||
|
})
|
||||||
|
}
|
||||||
|
|
||||||
|
export { promptLogin, clearCredentials, credentials }
|
||||||
+131
-47
@@ -1,37 +1,60 @@
|
|||||||
import ky from 'ky'
|
import ky from 'ky'
|
||||||
|
import { credentials } from './Auth'
|
||||||
|
|
||||||
var tracks = {}
|
var Tracks = {}
|
||||||
|
|
||||||
|
/** Object representation for track metadata */
|
||||||
class Track {
|
class Track {
|
||||||
|
/**
|
||||||
|
*
|
||||||
|
* @param {Object} tdata track information fetched from API
|
||||||
|
* @param {String} tdata.id
|
||||||
|
* @param {String} tdata.title
|
||||||
|
* @param {Object} tdata.album
|
||||||
|
* @param {String} tdata.album.title
|
||||||
|
* @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
|
||||||
|
* @param {Boolean} tdata.banned is the track blocked from Top
|
||||||
|
*/
|
||||||
constructor(tdata) {
|
constructor(tdata) {
|
||||||
Object.assign(this, tdata)
|
Object.assign(this, tdata)
|
||||||
|
|
||||||
this.stats = {
|
// this.getVote()
|
||||||
up: -1,
|
|
||||||
down: -1,
|
|
||||||
}
|
|
||||||
this.rank = -1
|
|
||||||
this.cast = ''
|
|
||||||
|
|
||||||
this.getVote()
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Link to track's playback
|
||||||
|
*/
|
||||||
get listen() {
|
get listen() {
|
||||||
return `https://open.spotify.com/track/${this.id}`
|
return `https://open.spotify.com/track/${this.id}`
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Self link to open Track's Info page
|
||||||
|
*/
|
||||||
get share() {
|
get share() {
|
||||||
return `https://${document.location.origin}/utwor/${this.id}`
|
return `${document.location.origin}/utwor/${this.id}`
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Change users vote for track
|
||||||
|
* @param {('up'|'down'|'report'|'')} value
|
||||||
|
* @returns {Promise} was the vote changed? (Boolean)
|
||||||
|
*/
|
||||||
setVote(value) {
|
setVote(value) {
|
||||||
return new Promise((resolve, reject) => {
|
return new Promise((resolve, reject) => {
|
||||||
if (value === this.cast) return
|
if (value === this.stats.cast) return
|
||||||
ky.patch(`/api/vote/${this.id}`, { json: { uid: 'mathias', value } })
|
ky.patch(`/api/vote/${this.id}`, {
|
||||||
|
json: { value },
|
||||||
|
headers: { authorization: credentials.token },
|
||||||
|
})
|
||||||
.json()
|
.json()
|
||||||
.then((ok) => {
|
.then((ok) => {
|
||||||
if (ok) {
|
if (ok) {
|
||||||
this.cast = value
|
if (value === 'report') return
|
||||||
|
this.stats.cast = value
|
||||||
this.getStats()
|
this.getStats()
|
||||||
}
|
}
|
||||||
resolve(ok)
|
resolve(ok)
|
||||||
@@ -40,37 +63,56 @@ class Track {
|
|||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Get user's vote for track
|
||||||
|
* @returns {Promise} vote value
|
||||||
|
*/
|
||||||
getVote() {
|
getVote() {
|
||||||
return new Promise((resolve, reject) => {
|
return new Promise((resolve, reject) => {
|
||||||
ky.get(`/api/vote/${this.id}/cast`, { searchParams: { uid: 'mathias' } })
|
if (!credentials.token) {
|
||||||
|
return resolve('')
|
||||||
|
}
|
||||||
|
|
||||||
|
ky.get(`/api/vote/${this.id}/cast`, {
|
||||||
|
headers: { authorization: credentials.token },
|
||||||
|
})
|
||||||
.text()
|
.text()
|
||||||
.then((cast) => {
|
.then((cast) => {
|
||||||
this.cast = cast
|
this.stats.cast = cast
|
||||||
resolve(cast)
|
resolve(cast)
|
||||||
})
|
})
|
||||||
.catch((err) => {
|
.catch((err) => reject(err))
|
||||||
console.error(err)
|
|
||||||
})
|
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Update Track's stats
|
||||||
|
* @returns {Promise} stats object
|
||||||
|
*/
|
||||||
getStats() {
|
getStats() {
|
||||||
return new Promise((resolve, reject) => {
|
if (this._stats) return this._stats
|
||||||
getStats(this.id)
|
else
|
||||||
.then((stats) => {
|
return (this._stats = new Promise((resolve, reject) => {
|
||||||
this.stats = stats
|
getStats(this.id)
|
||||||
resolve(stats)
|
.then((stats) => {
|
||||||
})
|
this.stats = stats
|
||||||
.catch((err) => {
|
resolve(this)
|
||||||
console.error(err)
|
})
|
||||||
})
|
.catch((err) => reject(err))
|
||||||
})
|
}))
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Requests Track stats (votes upd and down)
|
||||||
|
* @param {String} id track id
|
||||||
|
* @returns {Promise} stats object
|
||||||
|
*/
|
||||||
function getStats(id) {
|
function getStats(id) {
|
||||||
return new Promise((resolve, reject) => {
|
return new Promise((resolve, reject) => {
|
||||||
ky.get(`/api/vote/${id}`)
|
ky.get(`/api/vote/${id}`, {
|
||||||
|
headers: { authorization: credentials.token },
|
||||||
|
})
|
||||||
.json()
|
.json()
|
||||||
.then((stats) => {
|
.then((stats) => {
|
||||||
resolve(stats)
|
resolve(stats)
|
||||||
@@ -79,38 +121,80 @@ function getStats(id) {
|
|||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Get Track from cache of fetch
|
||||||
|
* @param {String} id track id
|
||||||
|
* @returns {Track} Track object
|
||||||
|
*/
|
||||||
function get(id) {
|
function get(id) {
|
||||||
return new Promise((resolve, reject) => {
|
if (typeof Tracks[id] === 'undefined') {
|
||||||
if (typeof tracks[id] === 'undefined') {
|
Tracks[id] = download(id)
|
||||||
download(id)
|
}
|
||||||
.then((track) => resolve(track))
|
|
||||||
.catch((err) => reject(err))
|
return Tracks[id]
|
||||||
} else resolve(tracks[id])
|
|
||||||
})
|
|
||||||
}
|
}
|
||||||
|
|
||||||
function getMultiple(ids) {
|
/**
|
||||||
return new Promise((resolve, reject) => {
|
* Get multiple Tracks
|
||||||
Promise.all(ids.map((id) => get(id)))
|
* @param {Array} ids Array of track ids
|
||||||
.then((tracks) => resolve(tracks))
|
* @returns {Array} Array of Tracks
|
||||||
.catch((err) => {
|
*/
|
||||||
console.error(err)
|
function getMultiple(ids = []) {
|
||||||
})
|
let missing = ids.filter((id) => !Tracks[id]) // filter tracks missing from cache
|
||||||
})
|
|
||||||
|
// if none are missing, return from cache
|
||||||
|
if (missing.length < 1) return ids.map((id) => Tracks[id])
|
||||||
|
else {
|
||||||
|
return downloadMultiple(missing)
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Fetch track data from API
|
||||||
|
* @param {String} id track id
|
||||||
|
* @returns {Track} Track object
|
||||||
|
*/
|
||||||
function download(id) {
|
function download(id) {
|
||||||
return new Promise((resolve, reject) => {
|
return new Promise((resolve, reject) => {
|
||||||
ky.get('/api/track/' + id)
|
ky.get('/api/track/' + id)
|
||||||
.json()
|
.json()
|
||||||
.then((track) => {
|
.then((track) => {
|
||||||
tracks[track.id] = new Track(track)
|
resolve(new Track(track))
|
||||||
resolve(tracks[track.id])
|
|
||||||
})
|
})
|
||||||
.catch((err) => reject(err))
|
.catch((err) => reject(err))
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
|
function downloadMultiple(tids) {
|
||||||
|
let promises = {}
|
||||||
|
|
||||||
|
// prepare promises
|
||||||
|
// store res, rej
|
||||||
|
tids.forEach((tid) => {
|
||||||
|
Tracks[tid] = new Promise((resolve, reject) => {
|
||||||
|
promises[tid] = { resolve, reject }
|
||||||
|
})
|
||||||
|
})
|
||||||
|
|
||||||
|
ky.post('/api/track/batch', {
|
||||||
|
json: { tids },
|
||||||
|
})
|
||||||
|
.json()
|
||||||
|
.then((tracks) => {
|
||||||
|
tracks.forEach((tdata) => {
|
||||||
|
promises[tdata.id].resolve(new Track(tdata))
|
||||||
|
})
|
||||||
|
})
|
||||||
|
.catch((err) => console.error(err))
|
||||||
|
|
||||||
|
return tids.map((tid) => Tracks[tid])
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Runs a text query for tracks
|
||||||
|
* @param {String} query
|
||||||
|
* @returns {Array} Array of track ids
|
||||||
|
*/
|
||||||
function search(query) {
|
function search(query) {
|
||||||
return new Promise((resolve, reject) => {
|
return new Promise((resolve, reject) => {
|
||||||
ky.get('/api/search/track/' + query)
|
ky.get('/api/search/track/' + query)
|
||||||
@@ -120,4 +204,4 @@ function search(query) {
|
|||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
export { tracks, get, getMultiple, search, getStats }
|
export { Tracks as tracks, get, getMultiple, search, getStats }
|
||||||
+6
-2
@@ -1,7 +1,7 @@
|
|||||||
import FastAverageColor from 'fast-average-color'
|
import FastAverageColor from 'fast-average-color'
|
||||||
|
|
||||||
var fac = new FastAverageColor(),
|
var fac = new FastAverageColor(),
|
||||||
def = document.documentElement.style.getPropertyValue('--deg')
|
def = 0
|
||||||
|
|
||||||
function setColor(target, lvl) {
|
function setColor(target, lvl) {
|
||||||
fac
|
fac
|
||||||
@@ -20,4 +20,8 @@ function setColor(target, lvl) {
|
|||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
export { setColor }
|
function setDefault() {
|
||||||
|
document.documentElement.style.setProperty('--deg', def + 'deg')
|
||||||
|
}
|
||||||
|
|
||||||
|
export { setColor, setDefault }
|
||||||
@@ -6,10 +6,19 @@
|
|||||||
}
|
}
|
||||||
|
|
||||||
.history-section > span {
|
.history-section > span {
|
||||||
border-bottom: 1px solid #eeec;
|
|
||||||
display: block;
|
display: block;
|
||||||
margin: 1em 0.5em 0;
|
margin: 1em 0.5em 0;
|
||||||
color: #3a3a3a;
|
color: #3a3a3a;
|
||||||
|
text-align: center;
|
||||||
|
}
|
||||||
|
|
||||||
|
.history > .history-section:first-child > span {
|
||||||
|
margin-top: unset;
|
||||||
|
}
|
||||||
|
|
||||||
|
.history-section > .header {
|
||||||
|
border-bottom: 1px solid #eeec;
|
||||||
|
text-align: left;
|
||||||
}
|
}
|
||||||
|
|
||||||
.history-section.now > .track {
|
.history-section.now > .track {
|
||||||
|
|||||||
@@ -1,38 +1,62 @@
|
|||||||
import { useContext } from 'react'
|
import { useContext } from 'react'
|
||||||
|
|
||||||
import Track from '../Track/Track'
|
import Track, { Tracklist } from '../Track/Track'
|
||||||
|
|
||||||
|
import { getMultiple } from '../../Cache'
|
||||||
|
|
||||||
import PlayingContext from '../../contexts/Playing'
|
import PlayingContext from '../../contexts/Playing'
|
||||||
|
|
||||||
import './History.css'
|
import './History.css'
|
||||||
|
import './playing.css'
|
||||||
|
|
||||||
function History({ next, tracks }) {
|
function History({ next, tracks, paused }) {
|
||||||
const playing = useContext(PlayingContext)
|
const { tid } = useContext(PlayingContext)
|
||||||
|
|
||||||
|
getMultiple(tracks.map(([tid]) => tid))
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<div className="wrapper history">
|
<div className="wrapper history">
|
||||||
{next && (
|
<Tracklist>
|
||||||
<div className="history-section next">
|
{next && (
|
||||||
<span>Następny:</span>
|
<div className="history-section next">
|
||||||
<Track track={next} timestamp=">" />
|
<span className="header">Następny:</span>
|
||||||
|
<Track tid={next} timestamp=">" />
|
||||||
|
</div>
|
||||||
|
)}
|
||||||
|
|
||||||
|
{!paused && (
|
||||||
|
<div className="history-section now">
|
||||||
|
<span className="header">Gra teraz:</span>
|
||||||
|
<Track tid={tid} timestamp="~" />
|
||||||
|
</div>
|
||||||
|
)}
|
||||||
|
|
||||||
|
<div className="history-section previous">
|
||||||
|
<span className="header">Poprzednie:</span>
|
||||||
|
|
||||||
|
{tracks.map(([tid, timestamp]) => {
|
||||||
|
let time = timestamp ? new Date(timestamp) : '-:-'
|
||||||
|
|
||||||
|
if (timestamp) {
|
||||||
|
let h = time.getHours(),
|
||||||
|
m = time.getMinutes()
|
||||||
|
|
||||||
|
h = h < 10 ? '0' + h : h
|
||||||
|
m = m < 10 ? '0' + m : m
|
||||||
|
|
||||||
|
time = h + ':' + m
|
||||||
|
}
|
||||||
|
|
||||||
|
return (
|
||||||
|
<Track key={tid + '_' + timestamp} tid={tid} timestamp={time} />
|
||||||
|
)
|
||||||
|
})}
|
||||||
|
|
||||||
|
{tracks.length < 1 && (
|
||||||
|
<span>Tutaj pojawią się poprzednie utwory</span>
|
||||||
|
)}
|
||||||
</div>
|
</div>
|
||||||
)}
|
</Tracklist>
|
||||||
|
|
||||||
<div className="history-section now">
|
|
||||||
<span>Gra teraz:</span>
|
|
||||||
<Track 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={track} timestamp={time} />
|
|
||||||
})}
|
|
||||||
</div>
|
|
||||||
</div>
|
</div>
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -0,0 +1,30 @@
|
|||||||
|
.now > .track {
|
||||||
|
height: 4em;
|
||||||
|
align-items: center;
|
||||||
|
}
|
||||||
|
|
||||||
|
.now > .track .track-timestamp {
|
||||||
|
display: none;
|
||||||
|
}
|
||||||
|
|
||||||
|
.now > .track .track-icons {
|
||||||
|
display: none;
|
||||||
|
}
|
||||||
|
|
||||||
|
.now > .track .track-section-a {
|
||||||
|
width: auto;
|
||||||
|
}
|
||||||
|
|
||||||
|
.now > .track .track-section-b {
|
||||||
|
flex-wrap: wrap;
|
||||||
|
}
|
||||||
|
|
||||||
|
.now > .track .track-image {
|
||||||
|
width: 4em;
|
||||||
|
height: 4em;
|
||||||
|
}
|
||||||
|
|
||||||
|
.now > .track .track-title {
|
||||||
|
width: 100%;
|
||||||
|
font-size: 1.2em;
|
||||||
|
}
|
||||||
@@ -4,7 +4,6 @@
|
|||||||
display: flex;
|
display: flex;
|
||||||
flex-direction: column;
|
flex-direction: column;
|
||||||
align-items: stretch;
|
align-items: stretch;
|
||||||
height: 100%;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
.info-image {
|
.info-image {
|
||||||
@@ -12,17 +11,16 @@
|
|||||||
height: var(--side);
|
height: var(--side);
|
||||||
width: var(--side);
|
width: var(--side);
|
||||||
flex-shrink: 0;
|
flex-shrink: 0;
|
||||||
margin: auto;
|
margin: 1em auto;
|
||||||
margin-bottom: 1em;
|
|
||||||
box-shadow: 0px 4px 16px 0px #000000b8;
|
box-shadow: 0px 4px 16px 0px #000000b8;
|
||||||
}
|
}
|
||||||
|
|
||||||
.info-wrapper {
|
.info-wrapper {
|
||||||
border-radius: 0.5em;
|
border-radius: 0.5em;
|
||||||
background: linear-gradient(180deg, white, transparent);
|
|
||||||
height: 100%;
|
height: 100%;
|
||||||
padding: 1em;
|
padding: 1em;
|
||||||
box-shadow: 0 -1px 11px 2px #6b6b6b52;
|
box-shadow: 0 -1px 11px 2px #6b6b6b52;
|
||||||
|
background-color: hsl(var(--deg) 4% 98% / 70%);
|
||||||
}
|
}
|
||||||
|
|
||||||
.info-wrapper > .title {
|
.info-wrapper > .title {
|
||||||
@@ -32,12 +30,17 @@
|
|||||||
|
|
||||||
.info-balance {
|
.info-balance {
|
||||||
width: 100%;
|
width: 100%;
|
||||||
font-size: 0.75em;
|
font-family: monospace;
|
||||||
background-color: var(--light);
|
background-color: var(--light);
|
||||||
margin: 1em 0;
|
margin: 1em 0;
|
||||||
display: flex;
|
display: flex;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
.info-balance[disabled] {
|
||||||
|
filter: grayscale();
|
||||||
|
opacity: 0.4;
|
||||||
|
}
|
||||||
|
|
||||||
.info-balance > div {
|
.info-balance > div {
|
||||||
display: inline-block;
|
display: inline-block;
|
||||||
min-width: 2em;
|
min-width: 2em;
|
||||||
@@ -48,18 +51,26 @@
|
|||||||
color: white;
|
color: white;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
.info-list {
|
||||||
|
display: flex;
|
||||||
|
flex-wrap: wrap;
|
||||||
|
}
|
||||||
|
|
||||||
.info-list > div {
|
.info-list > div {
|
||||||
padding: 0.7em;
|
padding: 0.7em;
|
||||||
display: flex;
|
display: flex;
|
||||||
justify-content: space-around;
|
justify-content: center;
|
||||||
|
width: 100%;
|
||||||
|
box-sizing: border-box;
|
||||||
}
|
}
|
||||||
|
|
||||||
.info-list > div:not(:last-child) {
|
.info-list > div:not(:last-child) {
|
||||||
border-bottom: 1px solid #cccc;
|
border-bottom: 1px solid #cccc;
|
||||||
}
|
}
|
||||||
|
|
||||||
.info-list > div:nth-child(-n + 2) {
|
.info-list > .buttons {
|
||||||
padding: 0;
|
padding: 0;
|
||||||
|
padding-bottom: 0.25em;
|
||||||
}
|
}
|
||||||
|
|
||||||
.info-list > .buttons > i {
|
.info-list > .buttons > i {
|
||||||
@@ -73,9 +84,10 @@
|
|||||||
background-color: var(--light);
|
background-color: var(--light);
|
||||||
color: var(--main);
|
color: var(--main);
|
||||||
cursor: default;
|
cursor: default;
|
||||||
|
border-radius: 1em;
|
||||||
}
|
}
|
||||||
|
|
||||||
.info-list > div > i:hover {
|
.info-list > .buttons > i:hover {
|
||||||
/* background-color: #cccc; */
|
/* background-color: #cccc; */
|
||||||
color: var(--main);
|
color: var(--main);
|
||||||
}
|
}
|
||||||
|
|||||||
+96
-53
@@ -4,15 +4,18 @@ import { useParams, Redirect } from 'react-router-dom'
|
|||||||
import Modal from '../Modal/Modal'
|
import Modal from '../Modal/Modal'
|
||||||
|
|
||||||
import { get } from '../../Cache'
|
import { get } from '../../Cache'
|
||||||
|
import { credentials } from '../../Auth'
|
||||||
|
|
||||||
import PlayingContext from '../../contexts/Playing'
|
import PlayingContext from '../../contexts/Playing'
|
||||||
|
import ModalLoginContext from '../../contexts/ModalLogin'
|
||||||
|
|
||||||
import './Info.css'
|
import './Info.css'
|
||||||
import def from '../../media/default.png'
|
import def from '../../media/default.png'
|
||||||
|
import admin from '../../Admin'
|
||||||
|
|
||||||
var last
|
var last
|
||||||
|
|
||||||
function Info() {
|
function Info({ top }) {
|
||||||
const { id } = useParams(),
|
const { id } = useParams(),
|
||||||
[track, setTrack] = useState({
|
[track, setTrack] = useState({
|
||||||
title: '-',
|
title: '-',
|
||||||
@@ -21,11 +24,12 @@ function Info() {
|
|||||||
artists: ['-'],
|
artists: ['-'],
|
||||||
}),
|
}),
|
||||||
[meta, setMeta] = useState('...'),
|
[meta, setMeta] = useState('...'),
|
||||||
[showModal, setShowModal] = useState(true),
|
[modalReport, setModalReport] = useState(false),
|
||||||
|
{ setModalLogin } = useContext(ModalLoginContext),
|
||||||
playing = useContext(PlayingContext)
|
playing = useContext(PlayingContext)
|
||||||
|
|
||||||
if (!id) last = playing.id ?? ''
|
if (id) last = id
|
||||||
else last = id
|
if (!last) last = id ?? playing.id ?? top ?? ''
|
||||||
|
|
||||||
useEffect(() => {
|
useEffect(() => {
|
||||||
setMeta(`Pobieranie... ${last}`)
|
setMeta(`Pobieranie... ${last}`)
|
||||||
@@ -34,84 +38,94 @@ function Info() {
|
|||||||
track
|
track
|
||||||
.getStats()
|
.getStats()
|
||||||
.then((stats) => {
|
.then((stats) => {
|
||||||
track
|
setTrack(track)
|
||||||
.getVote()
|
setMeta(false)
|
||||||
.then(() => {
|
|
||||||
setTrack(track)
|
|
||||||
setMeta(false)
|
|
||||||
})
|
|
||||||
.catch((err) => console.error(err))
|
|
||||||
})
|
})
|
||||||
.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`)
|
setMeta(`Wystąpił błąd przy pobieraniu informacji o utworze`)
|
||||||
})
|
)
|
||||||
}, [last]) // eslint-disable-line
|
}, [last]) // eslint-disable-line
|
||||||
|
|
||||||
if (!id && last) return <Redirect to={`/utwor/${last}`} />
|
if (!id && last) return <Redirect to={`/utwor/${last}`} />
|
||||||
|
|
||||||
function vote(value) {
|
function vote(value) {
|
||||||
|
if (!credentials.token) return setModalLogin(true) // prompt for login
|
||||||
|
if (track.stats.cast === value) return // ignore vote
|
||||||
|
|
||||||
|
setMeta('Zmienianie głosu...')
|
||||||
|
|
||||||
track
|
track
|
||||||
.setVote(value)
|
.setVote(value)
|
||||||
.then((ok) => {
|
.then((ok) => {
|
||||||
track
|
track
|
||||||
.getStats()
|
.getStats()
|
||||||
.then(() => {
|
.then(() => {
|
||||||
|
// http ok, vote accepted?
|
||||||
ok
|
ok
|
||||||
? setMeta(`Zmieniono głos na ${{ up: '👍', down: '👎' }[value]}`)
|
? 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) => {
|
||||||
|
// http error on update stats
|
||||||
|
setMeta('Wystąpił błąd przy aktualizacji statystyk utworu')
|
||||||
|
console.error(err)
|
||||||
})
|
})
|
||||||
.catch((err) => console.error(err))
|
|
||||||
})
|
})
|
||||||
.catch((err) => console.error(err))
|
.catch((err) => {
|
||||||
|
// http error on send
|
||||||
|
setMeta('Wystąpił błąd podczas wysyłania głosu')
|
||||||
|
console.error(err)
|
||||||
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
const total = track.stats.up + track.stats.down,
|
function report() {
|
||||||
percent =
|
track.setVote('report')
|
||||||
total > 0
|
setModalReport(false)
|
||||||
? (track.stats.up / (track.stats.up + track.stats.down)) * 100
|
}
|
||||||
: 50
|
|
||||||
|
const total = track.stats?.up + track.stats?.down,
|
||||||
|
percent = total > 0 ? (track.stats?.up / total) * 100 : 50
|
||||||
|
|
||||||
document.setTitle(track.title)
|
document.setTitle(track.title)
|
||||||
|
|
||||||
const toggleModal = () => setShowModal(!showModal)
|
|
||||||
const report = () => {
|
|
||||||
track.setVote('report')
|
|
||||||
}
|
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<div className="wrapper info">
|
<div className="wrapper info">
|
||||||
<img
|
<img
|
||||||
src={track.album.art ?? def}
|
src={track.album.art ? track.album.art[0].url : def}
|
||||||
className="info-image"
|
className="info-image"
|
||||||
alt="album cover"
|
alt="album cover"
|
||||||
/>
|
/>
|
||||||
<div className="info-wrapper">
|
<div className="info-wrapper">
|
||||||
<span className="title">{track.title}</span>
|
<span className="title">{track.title}</span>
|
||||||
|
|
||||||
<span className="artist">{track.artists[0]}</span>
|
<span className="artist">{track.artists[0]}</span>
|
||||||
<div className="info-balance">
|
|
||||||
|
<div className="info-balance" disabled={total < 1}>
|
||||||
<div className="up" style={{ width: `${percent}%` }}>
|
<div className="up" style={{ width: `${percent}%` }}>
|
||||||
{track.stats.up}
|
{track.stats.up}
|
||||||
</div>
|
</div>
|
||||||
<div className="down" style={{ width: `${100 - percent}%` }}>
|
<div className="down" style={{ width: `${100 - percent}%` }}>
|
||||||
{track.stats.down}
|
{track.stats.down}
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
{meta && <span className="info-meta">{meta}</span>}
|
<span className="info-meta"> {meta}</span>
|
||||||
|
|
||||||
{track.id && (
|
{track.id && (
|
||||||
<div className="info-list">
|
<div className="info-list">
|
||||||
<div className="buttons">
|
<div className="buttons">
|
||||||
<i
|
<i
|
||||||
className="icon-thumbs-up"
|
className="icon-thumbs-up"
|
||||||
data-set={track.cast === 'up'}
|
data-set={track.stats.cast === 'up'}
|
||||||
onClick={(e) => vote('up')}
|
onClick={(e) => vote('up')}
|
||||||
></i>
|
></i>
|
||||||
<i
|
<i
|
||||||
className="icon-thumbs-down"
|
className="icon-thumbs-down"
|
||||||
data-set={track.cast === 'down'}
|
data-set={track.stats.cast === 'down'}
|
||||||
onClick={(e) => vote('down')}
|
onClick={(e) => vote('down')}
|
||||||
></i>
|
></i>
|
||||||
</div>
|
</div>
|
||||||
@@ -136,29 +150,57 @@ function Info() {
|
|||||||
></i>
|
></i>
|
||||||
<i
|
<i
|
||||||
className="icon-flag"
|
className="icon-flag"
|
||||||
onClick={(e) => {
|
onClick={(e) => setModalReport(true)}
|
||||||
toggleModal()
|
|
||||||
}}
|
|
||||||
></i>
|
></i>
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
|
{credentials.udata.perms > 0 && (
|
||||||
|
<div className="buttons">
|
||||||
|
<i
|
||||||
|
className="icon-cancel-circled"
|
||||||
|
onClick={(e) => {
|
||||||
|
admin.ban(track.id).then((ok) => console.log(ok))
|
||||||
|
}}
|
||||||
|
></i>
|
||||||
|
</div>
|
||||||
|
)}
|
||||||
|
|
||||||
<div>
|
<div>
|
||||||
<span>{track.artists.join(', ')}</span>
|
<span>{track.artists.join(', ')}</span>
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
<div>
|
<div>
|
||||||
<span>
|
<span>
|
||||||
{track.album.name ?? '-'} ({track.album.year ?? '-'})
|
{track.album.name ?? '-'} ({track.album.year ?? '-'})
|
||||||
</span>
|
</span>
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
<div>Liczba głosów: {total}</div>
|
{total > 0 && (
|
||||||
|
<div>
|
||||||
|
<i className="icon-thumbs-up"></i> Liczba głosów:
|
||||||
|
<b>{total}</b>
|
||||||
|
</div>
|
||||||
|
)}
|
||||||
|
|
||||||
<div>Miejsce: #{track.stats.rank}</div>
|
{track.stats.rank > 0 && (
|
||||||
|
<div>
|
||||||
|
<i className="icon-list-numbered"></i> Miejsce:
|
||||||
|
<b>#{track.stats.rank}</b>
|
||||||
|
</div>
|
||||||
|
)}
|
||||||
|
|
||||||
{track.banned && (
|
{track.banned && (
|
||||||
<div>
|
<div>
|
||||||
<span>
|
<span>
|
||||||
Utwór zablokowany <i className="icon-cancel-circled"></i>
|
<i className="icon-cancel-circled"></i> Utwór zablokowany
|
||||||
|
</span>
|
||||||
|
</div>
|
||||||
|
)}
|
||||||
|
|
||||||
|
{track.explicit && (
|
||||||
|
<div>
|
||||||
|
<span>
|
||||||
|
<i className="icon-cancel-circled"></i> Przekleństwa
|
||||||
</span>
|
</span>
|
||||||
</div>
|
</div>
|
||||||
)}
|
)}
|
||||||
@@ -166,27 +208,28 @@ function Info() {
|
|||||||
)}
|
)}
|
||||||
</div>
|
</div>
|
||||||
<span className="info-data">{id}</span>
|
<span className="info-data">{id}</span>
|
||||||
{showModal ? (
|
{modalReport && (
|
||||||
<Modal>
|
<Modal>
|
||||||
<div className="modal-text">
|
<div className="modal-title">Czy na pewno chcesz zgłosić utwór?</div>
|
||||||
<div>
|
<div className="modal-body">
|
||||||
Czy na pewno chcesz zgłosić utwór{' '}
|
Zgłoszone utwory trafiają do sprawdzenia przez administrację. Jeżeli
|
||||||
<i>
|
<b> {track.title}</b> zawiera treści nieodpowiednie lub
|
||||||
<b>{track.title}</b>
|
<i> bardzo</i> nie chciałbyś go usłyszeć na korytarzu, zalecamy
|
||||||
</i>
|
zgłoszanie tego utworu.
|
||||||
?
|
|
||||||
</div>
|
|
||||||
</div>
|
</div>
|
||||||
<div className="modal-buttons-2">
|
<div className="modal-buttons">
|
||||||
<button onClick={toggleModal} className="modal-button">
|
<button
|
||||||
Nie
|
onClick={() => setModalReport(false)}
|
||||||
|
className="modal-button"
|
||||||
|
>
|
||||||
|
Anuluj
|
||||||
</button>
|
</button>
|
||||||
<button onClick={report} className="modal-button">
|
<button onClick={report} className="modal-button">
|
||||||
Tak
|
Zgłoś
|
||||||
</button>
|
</button>
|
||||||
</div>
|
</div>
|
||||||
</Modal>
|
</Modal>
|
||||||
) : null}
|
)}
|
||||||
</div>
|
</div>
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,17 +1,18 @@
|
|||||||
@import url('https://fonts.googleapis.com/css2?family=Quicksand&family=Poppins');
|
@import url('https://fonts.googleapis.com/css2?family=Quicksand&family=Poppins');
|
||||||
|
|
||||||
.main {
|
.main {
|
||||||
height: 100vh;
|
height: 100%;
|
||||||
justify-content: flex-end;
|
justify-content: flex-end;
|
||||||
background-color: var(--light);
|
|
||||||
font-family: 'Quicksand';
|
font-family: 'Quicksand';
|
||||||
overflow: hidden;
|
overflow: hidden auto;
|
||||||
}
|
}
|
||||||
|
|
||||||
.wrapper {
|
.wrapper {
|
||||||
max-width: 600px;
|
max-width: 600px;
|
||||||
|
/* max-height: 100%; */
|
||||||
margin: auto;
|
margin: auto;
|
||||||
box-sizing: border-box;
|
box-sizing: border-box;
|
||||||
padding-bottom: 8em;
|
padding-top: 3em;
|
||||||
overflow-y: auto;
|
padding-bottom: 7em;
|
||||||
|
/* overflow-y: auto; */
|
||||||
}
|
}
|
||||||
+94
-72
@@ -6,6 +6,7 @@ import {
|
|||||||
} from 'react-router-dom'
|
} from 'react-router-dom'
|
||||||
import { useEffect, useState } from 'react'
|
import { useEffect, useState } from 'react'
|
||||||
import ga from 'react-ga'
|
import ga from 'react-ga'
|
||||||
|
import localStorage from 'local-storage'
|
||||||
|
|
||||||
import Nav from '../Nav/Nav'
|
import Nav from '../Nav/Nav'
|
||||||
import History from '../History/History'
|
import History from '../History/History'
|
||||||
@@ -13,12 +14,16 @@ import Status from '../Status/Status'
|
|||||||
import Info from '../Info/Info'
|
import Info from '../Info/Info'
|
||||||
import Top from '../Top/Top'
|
import Top from '../Top/Top'
|
||||||
import Search from '../Search/Search'
|
import Search from '../Search/Search'
|
||||||
|
import Settings, { defaults } from '../Settings/Settings'
|
||||||
|
import Modal from '../Modal/Modal'
|
||||||
|
|
||||||
import { get, getMultiple } from '../../Cache'
|
|
||||||
import { addEvent } from '../../socket'
|
import { addEvent } from '../../socket'
|
||||||
|
import { promptLogin } from '../../Auth'
|
||||||
|
|
||||||
import PlayingContext from '../../contexts/Playing'
|
import PlayingContext from '../../contexts/Playing'
|
||||||
import GaContext from '../../contexts/Ga'
|
import GaContext from '../../contexts/Ga'
|
||||||
|
import ModalLoginContext from '../../contexts/ModalLogin'
|
||||||
|
import SettingsContext from '../../contexts/Settings'
|
||||||
|
|
||||||
import './Main.css'
|
import './Main.css'
|
||||||
|
|
||||||
@@ -37,93 +42,110 @@ document.setTitle = (prefix, suffix) => {
|
|||||||
|
|
||||||
function Main() {
|
function Main() {
|
||||||
const [playing, setPlaying] = useState({}),
|
const [playing, setPlaying] = useState({}),
|
||||||
[elapsed, setElapsed] = useState(0),
|
[elapsed, setElapsed] = useState([0, 0]),
|
||||||
[paused, setPaused] = useState(true),
|
[paused, setPaused] = useState(true),
|
||||||
[next, setNext] = useState(),
|
[next, setNext] = useState(),
|
||||||
[previous, setPrevious] = useState([]),
|
[previous, setPrevious] = useState([]),
|
||||||
[top, setTop] = useState([])
|
[top, setTop] = useState([]),
|
||||||
|
[topDate, setTopDate] = useState(),
|
||||||
|
[modalLogin, setModalLogin] = useState(false),
|
||||||
|
[settings, setSettings] = useState(localStorage('settings') ?? defaults)
|
||||||
|
|
||||||
|
// set up socket events
|
||||||
useEffect(() => {
|
useEffect(() => {
|
||||||
addEvent('status', ({ trackid, progress, paused }) => {
|
addEvent('status', ({ tid, progress, duration, paused, timestamp }) => {
|
||||||
get(trackid)
|
if (tid === null) return
|
||||||
.then((track) => {
|
setPlaying({ tid, timestamp })
|
||||||
setPlaying(track)
|
setElapsed([progress, duration])
|
||||||
setElapsed(progress)
|
setPaused(paused)
|
||||||
setPaused(paused)
|
|
||||||
})
|
|
||||||
.catch((err) => {
|
|
||||||
setPaused(true)
|
|
||||||
})
|
|
||||||
})
|
})
|
||||||
|
|
||||||
addEvent('next', ({ trackid }) => {
|
addEvent('next', ({ tid }) => setNext(tid))
|
||||||
get(trackid)
|
|
||||||
.then((track) => {
|
|
||||||
setNext(track)
|
|
||||||
})
|
|
||||||
.catch((err) => console.error(err))
|
|
||||||
})
|
|
||||||
|
|
||||||
addEvent('previous', ({ trackids, timestamps }) => {
|
addEvent('previous', ({ combo }) => setPrevious(combo))
|
||||||
getMultiple(trackids)
|
|
||||||
.then((tracks) => {
|
|
||||||
// insert timestamps to tracks
|
|
||||||
tracks.map((track, i) => (track.timestamp = timestamps[i]))
|
|
||||||
setPrevious(tracks)
|
|
||||||
})
|
|
||||||
.catch((err) => console.error(err))
|
|
||||||
})
|
|
||||||
|
|
||||||
addEvent('top', ({ trackids }) => {
|
addEvent('top', ({ tids, timestamp }) => {
|
||||||
getMultiple(trackids)
|
setTop(tids)
|
||||||
.then((tracks) => setTop(tracks))
|
setTopDate(new Date(timestamp))
|
||||||
.catch((err) => console.error(err))
|
|
||||||
})
|
})
|
||||||
}, [])
|
}, []) // eslint-disable-line
|
||||||
|
|
||||||
|
// save settings on change
|
||||||
|
useEffect(() => {
|
||||||
|
localStorage('settings', settings)
|
||||||
|
}, [settings])
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<GaContext.Provider value={ga}>
|
<SettingsContext.Provider
|
||||||
<PlayingContext.Provider value={playing}>
|
value={{
|
||||||
<div className="main">
|
settings,
|
||||||
<Router>
|
setSettings: (key, value) => {
|
||||||
<Switch>
|
setSettings((settings) => ({ ...settings, [key]: !value }))
|
||||||
<Route exact path="/">
|
},
|
||||||
<History next={next} tracks={previous} />
|
}}
|
||||||
</Route>
|
>
|
||||||
|
<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} paused={paused} />
|
||||||
|
</Route>
|
||||||
|
|
||||||
<Route path="/utwor/:id?">
|
<Route path="/utwor/:id?">
|
||||||
<Info />
|
<Info top={top[0]} />
|
||||||
</Route>
|
</Route>
|
||||||
|
|
||||||
<Route path="/top">
|
<Route path="/top">
|
||||||
<Top tracks={top} />
|
<Top tracks={top} timestamp={topDate} />
|
||||||
</Route>
|
</Route>
|
||||||
|
|
||||||
<Route path="/wyszukaj/:query?">
|
<Route path="/wyszukaj/:query?">
|
||||||
<Search />
|
<Search />
|
||||||
</Route>
|
</Route>
|
||||||
|
|
||||||
<Route render={() => <Redirect to="/" />} />
|
<Route path="/ustawienia">
|
||||||
</Switch>
|
<Settings />
|
||||||
<Nav
|
</Route>
|
||||||
buttons={[
|
|
||||||
{ label: 'Historia', to: '/', icon: 'align-left' },
|
<Route render={() => <Redirect to="/" />} />
|
||||||
{ label: 'Wyszukaj', to: '/wyszukaj', icon: 'search' },
|
</Switch>
|
||||||
{ label: 'Top', to: '/top', icon: 'list-numbered' },
|
<Nav
|
||||||
{
|
buttons={[
|
||||||
label: 'Utwór',
|
{ label: 'Historia', to: '/', icon: 'align-left' },
|
||||||
path: '/utwor',
|
{ label: 'Wyszukaj', to: '/wyszukaj', icon: 'search' },
|
||||||
to: `/utwor`,
|
{ label: 'Top', to: '/top', icon: 'list-numbered' },
|
||||||
icon: 'info',
|
{
|
||||||
},
|
label: 'Utwór',
|
||||||
{ label: 'Ustawienia', to: '/ustawienia', icon: 'cog-alt' },
|
path: '/utwor',
|
||||||
]}
|
to: `/utwor`,
|
||||||
/>
|
icon: 'info',
|
||||||
<Status progress={elapsed} paused={paused} />
|
},
|
||||||
</Router>
|
{ label: 'Ustawienia', to: '/ustawienia', icon: 'cog-alt' },
|
||||||
</div>
|
]}
|
||||||
</PlayingContext.Provider>
|
/>
|
||||||
</GaContext.Provider>
|
<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 {
|
.modal {
|
||||||
background-color: var(--light);
|
background-color: var(--white);
|
||||||
color: var(--dark);
|
color: var(--dark);
|
||||||
border-radius: 0.5em;
|
border-radius: 3px;
|
||||||
padding: 30px min(9vw, 30px);
|
padding: 1.25em 1.5em;
|
||||||
max-width: 550px;
|
max-width: 550px;
|
||||||
width: 100%;
|
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 {
|
.modal > div.modal-title {
|
||||||
display: grid;
|
font-size: 1.2em;
|
||||||
grid-template-columns: 1fr;
|
font-weight: bold;
|
||||||
grid-template-rows: 1fr;
|
border-bottom: 1px solid;
|
||||||
grid-template-areas:
|
padding-bottom: 0.3em;
|
||||||
'text'
|
|
||||||
'modal-buttons';
|
|
||||||
}
|
}
|
||||||
.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 {
|
.modal-button:first-child {
|
||||||
border-radius: 0.5em 0 0 0.5em;
|
margin-right: 0.5em;
|
||||||
}
|
background-color: var(--white);
|
||||||
.modal-button:last-child {
|
color: var(--dark);
|
||||||
border-radius: 0 0.5em 0.5em 0;
|
|
||||||
}
|
|
||||||
div[class^='modal-buttons-'] {
|
|
||||||
display: grid;
|
|
||||||
grid-template-rows: 1fr;
|
|
||||||
gap: 0px;
|
|
||||||
grid-area: modal-buttons;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
.modal-buttons-1 {
|
.modal-button:hover {
|
||||||
grid-template-columns: 1fr;
|
filter: brightness(0.9);
|
||||||
}
|
|
||||||
.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;
|
|
||||||
}
|
}
|
||||||
@@ -5,7 +5,7 @@ import './Modal.css'
|
|||||||
|
|
||||||
const modalRoot = document.getElementById('modal')
|
const modalRoot = document.getElementById('modal')
|
||||||
|
|
||||||
function Modal({ children }) {
|
function Modal({ children, title, content, buttons }) {
|
||||||
const elRef = useRef(null)
|
const elRef = useRef(null)
|
||||||
if (!elRef.current) {
|
if (!elRef.current) {
|
||||||
elRef.current = document.createElement('div')
|
elRef.current = document.createElement('div')
|
||||||
@@ -15,7 +15,24 @@ function Modal({ children }) {
|
|||||||
return () => modalRoot.removeChild(elRef.current)
|
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
|
export default Modal
|
||||||
@@ -2,14 +2,15 @@ nav {
|
|||||||
width: 100%;
|
width: 100%;
|
||||||
display: flex;
|
display: flex;
|
||||||
background-color: var(--white);
|
background-color: var(--white);
|
||||||
border-radius: 0.5em 0.5em 0 0;
|
/* border-radius: 0.5em 0.5em 0 0; */
|
||||||
padding: 0.5em;
|
padding: 0.3em 0.5em;
|
||||||
box-sizing: border-box;
|
box-sizing: border-box;
|
||||||
user-select: none;
|
user-select: none;
|
||||||
box-shadow: 0 0 12px 1px #0000002b, 0 -10px 20px 20px var(--light);
|
|
||||||
z-index: 5;
|
z-index: 5;
|
||||||
position: fixed;
|
position: fixed;
|
||||||
bottom: 0;
|
top: 0;
|
||||||
|
box-shadow: 0px 4px 6px 2px #00000026;
|
||||||
|
border-bottom: 1px solid var(--main);
|
||||||
}
|
}
|
||||||
|
|
||||||
.nav-button {
|
.nav-button {
|
||||||
@@ -30,12 +31,12 @@ nav {
|
|||||||
.nav-button.active {
|
.nav-button.active {
|
||||||
color: var(--main);
|
color: var(--main);
|
||||||
font-weight: bold;
|
font-weight: bold;
|
||||||
padding-top: 0;
|
/* padding-top: 0; */
|
||||||
position: relative;
|
position: relative;
|
||||||
}
|
}
|
||||||
|
|
||||||
.nav-button.active:before {
|
.nav-button.active:before {
|
||||||
content: '';
|
/* content: ''; */
|
||||||
width: 80%;
|
width: 80%;
|
||||||
left: 10%;
|
left: 10%;
|
||||||
bottom: 0;
|
bottom: 0;
|
||||||
|
|||||||
@@ -19,3 +19,10 @@
|
|||||||
margin: 1em;
|
margin: 1em;
|
||||||
color: #000a;
|
color: #000a;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
.search[data-results='0'] {
|
||||||
|
height: 100%;
|
||||||
|
display: flex;
|
||||||
|
flex-direction: column;
|
||||||
|
justify-content: center;
|
||||||
|
}
|
||||||
@@ -1,7 +1,7 @@
|
|||||||
import { createRef, useEffect, useState } from 'react'
|
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 { getMultiple, search } from '../../Cache'
|
||||||
|
|
||||||
import './Search.css'
|
import './Search.css'
|
||||||
@@ -12,7 +12,8 @@ function Search() {
|
|||||||
const { query } = useParams(),
|
const { query } = useParams(),
|
||||||
[results, setResults] = useState([]),
|
[results, setResults] = useState([]),
|
||||||
[meta, setMeta] = useState(''),
|
[meta, setMeta] = useState(''),
|
||||||
input = createRef()
|
input = createRef(),
|
||||||
|
history = useHistory()
|
||||||
|
|
||||||
function run(query) {
|
function run(query) {
|
||||||
query = query.trim()
|
query = query.trim()
|
||||||
@@ -20,16 +21,18 @@ function Search() {
|
|||||||
|
|
||||||
setMeta(`Wyszukiwanie...`)
|
setMeta(`Wyszukiwanie...`)
|
||||||
|
|
||||||
|
history.replace(`/wyszukaj/${query}`)
|
||||||
|
|
||||||
search(query)
|
search(query)
|
||||||
.then(({ tracks, total }) => {
|
.then(({ tids, total, elapsed }) => {
|
||||||
getMultiple(tracks)
|
getMultiple(tids)
|
||||||
.then((tracks) => {
|
setResults(tids)
|
||||||
setResults(tracks)
|
setMeta(
|
||||||
setMeta(`Znaleziono ${total} utworów`)
|
`Znaleziono ${total} utworów (${(
|
||||||
})
|
elapsed[0] +
|
||||||
.catch((err) => {
|
elapsed[1] / 1e9
|
||||||
setMeta(`Wystąpił błąd podczas pobierania utworów`)
|
).toPrecision(2)}s)`
|
||||||
})
|
)
|
||||||
})
|
})
|
||||||
.catch((err) => {
|
.catch((err) => {
|
||||||
setMeta(`Wystąpił błąd podczas wyszukiwania`)
|
setMeta(`Wystąpił błąd podczas wyszukiwania`)
|
||||||
@@ -49,7 +52,7 @@ function Search() {
|
|||||||
}, []) // eslint-disable-line react-hooks/exhaustive-deps
|
}, []) // eslint-disable-line react-hooks/exhaustive-deps
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<div className="wrapper search">
|
<div className="wrapper search" data-results={results.length}>
|
||||||
<h2>Wyszukaj utwór</h2>
|
<h2>Wyszukaj utwór</h2>
|
||||||
<input
|
<input
|
||||||
className="search-input"
|
className="search-input"
|
||||||
@@ -73,9 +76,11 @@ function Search() {
|
|||||||
{meta}
|
{meta}
|
||||||
</span>
|
</span>
|
||||||
)}
|
)}
|
||||||
{results.map((track) => {
|
<Tracklist>
|
||||||
return <Track key={track.id} track={track} />
|
{results.map((tid) => {
|
||||||
})}
|
return <Track key={tid} tid={tid} />
|
||||||
|
})}
|
||||||
|
</Tracklist>
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
)
|
)
|
||||||
|
|||||||
@@ -0,0 +1,73 @@
|
|||||||
|
.settings {
|
||||||
|
padding: 1em;
|
||||||
|
}
|
||||||
|
|
||||||
|
.settings-part {
|
||||||
|
border-radius: 0.5em;
|
||||||
|
background: white;
|
||||||
|
margin-bottom: 1em;
|
||||||
|
height: 100%;
|
||||||
|
padding: 0.4em 0.8em;
|
||||||
|
box-shadow: 0 -1px 12px 0px #6b6b6b40;
|
||||||
|
}
|
||||||
|
|
||||||
|
.head {
|
||||||
|
display: flex;
|
||||||
|
align-items: flex-end;
|
||||||
|
padding: 0.5em;
|
||||||
|
border-bottom: 1px solid #3333;
|
||||||
|
margin-bottom: 0.5em;
|
||||||
|
}
|
||||||
|
|
||||||
|
.head > img {
|
||||||
|
width: 3em;
|
||||||
|
height: 3em;
|
||||||
|
border-radius: 4px;
|
||||||
|
box-shadow: 0 1px 8px 2px #8888;
|
||||||
|
}
|
||||||
|
|
||||||
|
.head > span {
|
||||||
|
font-size: 1.2em;
|
||||||
|
padding-left: 0.5em;
|
||||||
|
width: 100%;
|
||||||
|
}
|
||||||
|
|
||||||
|
.head > div {
|
||||||
|
white-space: nowrap;
|
||||||
|
font-weight: bold;
|
||||||
|
font-size: 0.8em;
|
||||||
|
float: right;
|
||||||
|
text-transform: uppercase;
|
||||||
|
cursor: pointer;
|
||||||
|
}
|
||||||
|
|
||||||
|
.settings-sub {
|
||||||
|
display: flex;
|
||||||
|
justify-content: space-between;
|
||||||
|
align-items: center;
|
||||||
|
padding: 0.4em 0.2em;
|
||||||
|
text-decoration: none;
|
||||||
|
color: inherit;
|
||||||
|
}
|
||||||
|
|
||||||
|
.settings-sub:not(:last-child) {
|
||||||
|
border-bottom: 1px solid var(--light);
|
||||||
|
}
|
||||||
|
|
||||||
|
.settings-sub i {
|
||||||
|
color: var(--dark);
|
||||||
|
}
|
||||||
|
|
||||||
|
.settings-sub.toggle[data-value='true'] .toggle i {
|
||||||
|
color: var(--main);
|
||||||
|
}
|
||||||
|
|
||||||
|
.settings-sub.external:hover,
|
||||||
|
.settings-sub.toggle:hover {
|
||||||
|
color: var(--main);
|
||||||
|
cursor: pointer;
|
||||||
|
}
|
||||||
|
|
||||||
|
.toggle i {
|
||||||
|
font-size: 1.2em;
|
||||||
|
}
|
||||||
@@ -0,0 +1,227 @@
|
|||||||
|
import ky from 'ky'
|
||||||
|
import { useContext, useEffect, useState } from 'react'
|
||||||
|
import { useLocation } from 'react-router'
|
||||||
|
|
||||||
|
import { promptLogin, credentials, clearCredentials } from '../../Auth'
|
||||||
|
|
||||||
|
import SettingsContext from '../../contexts/Settings'
|
||||||
|
|
||||||
|
import Modal from '../Modal/Modal'
|
||||||
|
|
||||||
|
import './Settings.css'
|
||||||
|
|
||||||
|
function checkCode(code) {
|
||||||
|
return ky
|
||||||
|
.get(`/api/code/info/${code}`, {
|
||||||
|
headers: { authorization: credentials.token },
|
||||||
|
})
|
||||||
|
.json()
|
||||||
|
}
|
||||||
|
|
||||||
|
function claimCode(code) {
|
||||||
|
return new Promise((resolve, reject) => {
|
||||||
|
ky.post(`/api/code/claim/${code}`, {
|
||||||
|
headers: { authorization: credentials.token },
|
||||||
|
})
|
||||||
|
.json()
|
||||||
|
.then((ok) => {
|
||||||
|
resolve(ok)
|
||||||
|
})
|
||||||
|
})
|
||||||
|
}
|
||||||
|
|
||||||
|
function listCodes() {
|
||||||
|
return ky
|
||||||
|
.get(`/api/code/list`, {
|
||||||
|
headers: { authorization: credentials.token },
|
||||||
|
})
|
||||||
|
.json()
|
||||||
|
}
|
||||||
|
|
||||||
|
const defaults = {
|
||||||
|
hueFromArt: true,
|
||||||
|
}
|
||||||
|
|
||||||
|
function CodeListing({ code: { value, type, used } }) {
|
||||||
|
return (
|
||||||
|
<div className="settings-sub plain">
|
||||||
|
<span>
|
||||||
|
<b>{value}</b> - {type}
|
||||||
|
</span>
|
||||||
|
<i className={used ? 'icon-star-empty' : 'icon-star'}></i>
|
||||||
|
</div>
|
||||||
|
)
|
||||||
|
}
|
||||||
|
|
||||||
|
function Toggle({ value }) {
|
||||||
|
return (
|
||||||
|
<div className="toggle">
|
||||||
|
<i className={`icon-toggle-${value ? 'on' : 'off'}`}></i>
|
||||||
|
</div>
|
||||||
|
)
|
||||||
|
}
|
||||||
|
|
||||||
|
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-sub toggle"
|
||||||
|
data-value={value}
|
||||||
|
onClick={() => {
|
||||||
|
setValue((value) => !value)
|
||||||
|
setSettings(id, value)
|
||||||
|
}}
|
||||||
|
>
|
||||||
|
{children}
|
||||||
|
<Toggle value={value} />
|
||||||
|
</div>
|
||||||
|
)
|
||||||
|
}
|
||||||
|
|
||||||
|
function Settings() {
|
||||||
|
const [creds, setCreds] = useState({ ...credentials }),
|
||||||
|
[code, setCode] = useState(null),
|
||||||
|
[modalCode, setModalCode] = useState(false),
|
||||||
|
[codes, setCodes] = useState([])
|
||||||
|
|
||||||
|
useEffect(() => {
|
||||||
|
if (credentials.token) {
|
||||||
|
listCodes().then((list) => setCodes(list))
|
||||||
|
}
|
||||||
|
}, [])
|
||||||
|
|
||||||
|
const { search } = useLocation()
|
||||||
|
|
||||||
|
useEffect(() => {
|
||||||
|
let params = new URLSearchParams(search),
|
||||||
|
c = params.get('c')
|
||||||
|
|
||||||
|
if (c) {
|
||||||
|
checkCode(c)
|
||||||
|
.then((info) => {
|
||||||
|
setCode(info)
|
||||||
|
setModalCode(true)
|
||||||
|
})
|
||||||
|
.catch((err) => console.error(err))
|
||||||
|
}
|
||||||
|
}, [search])
|
||||||
|
|
||||||
|
return (
|
||||||
|
<div className="wrapper settings">
|
||||||
|
<div className="head">
|
||||||
|
<img
|
||||||
|
src={
|
||||||
|
creds.token
|
||||||
|
? `https://graph.facebook.com/${creds.udata.id}/picture?type=square`
|
||||||
|
: '/media/default_profile.png'
|
||||||
|
}
|
||||||
|
alt="user profile pic"
|
||||||
|
/>
|
||||||
|
|
||||||
|
<span>{creds.udata.name ?? '-- --'}</span>
|
||||||
|
<div
|
||||||
|
onClick={() => {
|
||||||
|
creds.token
|
||||||
|
? clearCredentials().then((newCreds) => setCreds(newCreds))
|
||||||
|
: promptLogin().then((newCreds) => setCreds(newCreds))
|
||||||
|
}}
|
||||||
|
>
|
||||||
|
{creds.token ? 'wyloguj' : 'zaloguj'}
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
|
||||||
|
{creds.token ? null : (
|
||||||
|
<div className="settings-part body">
|
||||||
|
<b>Zaloguj się</b> aby móc głosować na utwory
|
||||||
|
</div>
|
||||||
|
)}
|
||||||
|
|
||||||
|
{codes.length > 0 && (
|
||||||
|
<div className="settings-part body">
|
||||||
|
<span>Zebrane kody: </span>
|
||||||
|
{codes.map((code) => (
|
||||||
|
<CodeListing code={code} />
|
||||||
|
))}
|
||||||
|
</div>
|
||||||
|
)}
|
||||||
|
|
||||||
|
{modalCode && (
|
||||||
|
<Modal>
|
||||||
|
<div className="modal-title">Znalazłeś kod do aktywacji!</div>
|
||||||
|
<div className="modal-body">
|
||||||
|
<p>
|
||||||
|
Kod "{code.value}" jest
|
||||||
|
<b> {code.claimed ? 'Zajęty 😥' : 'Wolny 😁'}</b>.<br />
|
||||||
|
</p>
|
||||||
|
{!credentials.token && <p>Zaloguj się aby móc go zająć.</p>}
|
||||||
|
Kod typu
|
||||||
|
<i> {code.type}</i>: {code.desc}
|
||||||
|
</div>
|
||||||
|
<div className="modal-buttons">
|
||||||
|
<button
|
||||||
|
onClick={() => setModalCode(false)}
|
||||||
|
className="modal-button"
|
||||||
|
>
|
||||||
|
Zamknij
|
||||||
|
</button>
|
||||||
|
{!code.claimed && credentials.token && (
|
||||||
|
<button
|
||||||
|
onClick={() => {
|
||||||
|
setModalCode(false)
|
||||||
|
claimCode(code.value).then((ok) => {
|
||||||
|
listCodes().then((list) => setCodes(list))
|
||||||
|
})
|
||||||
|
}}
|
||||||
|
className="modal-button"
|
||||||
|
>
|
||||||
|
Zajmij
|
||||||
|
</button>
|
||||||
|
)}
|
||||||
|
</div>
|
||||||
|
</Modal>
|
||||||
|
)}
|
||||||
|
|
||||||
|
<div className="settings-part">
|
||||||
|
<SettingToggle id="hueFromArt">
|
||||||
|
Ustawiaj kolorystyke strony na podstawie okładki albumu
|
||||||
|
</SettingToggle>
|
||||||
|
</div>
|
||||||
|
|
||||||
|
{/* Terms of Service and other usefull links */}
|
||||||
|
<div className="settings-part">
|
||||||
|
<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,16 +1,20 @@
|
|||||||
.status {
|
.status {
|
||||||
position: fixed;
|
position: fixed;
|
||||||
bottom: 3.5rem;
|
bottom: 2.5rem;
|
||||||
left: 2.5%;
|
left: 0;
|
||||||
width: 95%;
|
right: 0;
|
||||||
|
width: 80%;
|
||||||
background: var(--dark);
|
background: var(--dark);
|
||||||
color: var(--white);
|
color: var(--white);
|
||||||
padding: 0.5em;
|
padding: 0.5em;
|
||||||
border-radius: 0.5em;
|
border-radius: 0.5em;
|
||||||
box-sizing: border-box;
|
box-sizing: border-box;
|
||||||
box-shadow: 0 2px 8px 1px #00000063;
|
box-shadow: 0 2px 8px 1px #0006;
|
||||||
z-index: 10;
|
z-index: 10;
|
||||||
text-decoration: none;
|
text-decoration: none;
|
||||||
|
max-width: 700px;
|
||||||
|
margin: auto;
|
||||||
|
transition: 0.4s cubic-bezier(1, 0, 0, 1);
|
||||||
}
|
}
|
||||||
|
|
||||||
.status-image {
|
.status-image {
|
||||||
@@ -25,6 +29,9 @@
|
|||||||
font-size: 1.1em;
|
font-size: 1.1em;
|
||||||
display: block;
|
display: block;
|
||||||
font-weight: bold;
|
font-weight: bold;
|
||||||
|
overflow: hidden;
|
||||||
|
white-space: nowrap;
|
||||||
|
text-overflow: ellipsis;
|
||||||
}
|
}
|
||||||
|
|
||||||
.status-artist {
|
.status-artist {
|
||||||
@@ -47,7 +54,7 @@
|
|||||||
bottom: 0;
|
bottom: 0;
|
||||||
border-bottom: 2px solid white;
|
border-bottom: 2px solid white;
|
||||||
border-radius: 2px;
|
border-radius: 2px;
|
||||||
transition: 0.5s linear width, 0.3s ease-out opacity;
|
transition: 1s linear width, 0.3s ease-out opacity;
|
||||||
}
|
}
|
||||||
|
|
||||||
.status-progress:after {
|
.status-progress:after {
|
||||||
@@ -61,6 +68,11 @@
|
|||||||
border-radius: 100%;
|
border-radius: 100%;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
.status.paused {
|
||||||
|
transform: scaleX(0);
|
||||||
|
opacity: 0;
|
||||||
|
}
|
||||||
|
|
||||||
.status.paused > .status-progress {
|
.status.paused > .status-progress {
|
||||||
opacity: 0;
|
opacity: 0;
|
||||||
}
|
}
|
||||||
@@ -1,34 +1,43 @@
|
|||||||
import { useContext, useEffect, useState } from 'react'
|
import { useContext, useEffect, useState } from 'react'
|
||||||
import { Link } from 'react-router-dom'
|
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 PlayingContext from '../../contexts/Playing'
|
||||||
|
import SettingsContext from '../../contexts/Settings'
|
||||||
|
|
||||||
import './Status.css'
|
import './Status.css'
|
||||||
import def from '../../media/default.png'
|
import def from '../../media/default.png'
|
||||||
|
import { get } from '../../Cache'
|
||||||
|
|
||||||
function Status({ progress, paused }) {
|
function Status({ progress: [progress, duration], paused }) {
|
||||||
const {
|
const { tid } = useContext(PlayingContext),
|
||||||
id,
|
{ settings } = useContext(SettingsContext)
|
||||||
title = '-',
|
|
||||||
artists = ['-'],
|
|
||||||
album = {},
|
|
||||||
duration,
|
|
||||||
} = useContext(PlayingContext),
|
|
||||||
[elapsed, setElapsed] = useState()
|
|
||||||
|
|
||||||
const step = 500,
|
const [elapsed, setElapsed] = useState(),
|
||||||
tread = step / duration
|
[track, setTrack] = useState({})
|
||||||
|
|
||||||
|
if (tid)
|
||||||
|
get(tid).then((tdata) => {
|
||||||
|
setTrack(tdata)
|
||||||
|
})
|
||||||
|
|
||||||
|
const step = 1e3,
|
||||||
|
tread = step / track?.duration
|
||||||
|
|
||||||
|
// update theme color based on track
|
||||||
useEffect(() => {
|
useEffect(() => {
|
||||||
if (album.art) setColor(album.art, 1)
|
if (!settings.hueFromArt) setDefault()
|
||||||
}, [album.art])
|
else if (track?.album?.art) setColor(track?.album?.art[1]?.url, 1)
|
||||||
|
}, [track?.album?.art, settings.hueFromArt])
|
||||||
|
|
||||||
|
// update progress on track change
|
||||||
useEffect(() => {
|
useEffect(() => {
|
||||||
setElapsed(progress ? progress / duration : 0)
|
setElapsed(progress ? progress / duration : 0)
|
||||||
}, [progress, duration])
|
}, [progress, duration, tid])
|
||||||
|
|
||||||
|
// animate progress bar
|
||||||
useEffect(
|
useEffect(
|
||||||
(anim) => {
|
(anim) => {
|
||||||
if (!paused) {
|
if (!paused) {
|
||||||
@@ -50,13 +59,25 @@ function Status({ progress, paused }) {
|
|||||||
|
|
||||||
return (
|
return (
|
||||||
<Link
|
<Link
|
||||||
className={['status', paused ? 'paused' : ''].join(' ')}
|
className={['status', paused || !tid ? 'paused' : ''].join(' ')}
|
||||||
to={`/utwor/${id}`}
|
to={`/utwor/${tid}`}
|
||||||
>
|
>
|
||||||
<img className="status-image" alt="album cover" src={album.art ?? def} />
|
<img
|
||||||
<span className="status-track">{title}</span>
|
className="status-image"
|
||||||
<span className="status-artist">{artists.join(', ')}</span>
|
alt="album cover"
|
||||||
<i className="icon-info"></i>
|
src={track?.album?.art ? track?.album?.art[1]?.url : def}
|
||||||
|
/>
|
||||||
|
<span className="status-track">{track?.title}</span>
|
||||||
|
<span className="status-artist">{track?.artists?.join(', ')}</span>
|
||||||
|
<i
|
||||||
|
className={`icon-${
|
||||||
|
track.id
|
||||||
|
? socket.readyState === socket.OPEN
|
||||||
|
? 'info'
|
||||||
|
: 'unlink'
|
||||||
|
: 'spin4 animate-spin'
|
||||||
|
}`}
|
||||||
|
></i>
|
||||||
<div
|
<div
|
||||||
className="status-progress"
|
className="status-progress"
|
||||||
style={{ width: `calc(var(--max) * ${elapsed})` }}
|
style={{ width: `calc(var(--max) * ${elapsed})` }}
|
||||||
|
|||||||
@@ -0,0 +1,24 @@
|
|||||||
|
.top-header {
|
||||||
|
border-bottom: 1px solid #eeec;
|
||||||
|
display: block;
|
||||||
|
margin: 1em 0.5em 0;
|
||||||
|
color: var(--dark);
|
||||||
|
text-align: center;
|
||||||
|
font-weight: bold;
|
||||||
|
}
|
||||||
|
|
||||||
|
.top-more {
|
||||||
|
text-align: center;
|
||||||
|
padding: 0.5em 1em;
|
||||||
|
background-color: var(--light);
|
||||||
|
border-radius: 5px;
|
||||||
|
margin: 1em auto;
|
||||||
|
cursor: pointer;
|
||||||
|
transition: 0.1s;
|
||||||
|
color: #333;
|
||||||
|
width: 60%;
|
||||||
|
}
|
||||||
|
|
||||||
|
.top-more:hover {
|
||||||
|
width: 75%;
|
||||||
|
}
|
||||||
@@ -1,13 +1,45 @@
|
|||||||
import Track from '../Track/Track'
|
import { useState } from 'react'
|
||||||
|
import { getMultiple } from '../../Cache'
|
||||||
|
import Track, { Tracklist } from '../Track/Track'
|
||||||
|
|
||||||
import './Top.css'
|
import './Top.css'
|
||||||
|
|
||||||
function Top(props) {
|
function Top({ tracks, timestamp }) {
|
||||||
|
const locale = 'pl-PL',
|
||||||
|
date = timestamp ?? new Date(),
|
||||||
|
weekName = date.toLocaleDateString(locale, { weekday: 'long' }),
|
||||||
|
day = date.toLocaleTimeString(locale, {
|
||||||
|
hour: '2-digit',
|
||||||
|
minute: '2-digit',
|
||||||
|
}),
|
||||||
|
limit = 25
|
||||||
|
|
||||||
|
const [more, setMore] = useState(0)
|
||||||
|
|
||||||
|
getMultiple(tracks.slice(0, limit + more))
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<div className="wrapper top">
|
<div className="wrapper top">
|
||||||
{props.tracks.map((track, rank) => {
|
<span className="top-header">
|
||||||
return <Track key={track.id} rank={rank + 1} track={track} />
|
TOP: {weekName} {timestamp ? day : '-'}
|
||||||
})}
|
</span>
|
||||||
|
|
||||||
|
<Tracklist>
|
||||||
|
{tracks.slice(0, limit + more).map((tid, i) => {
|
||||||
|
return <Track key={tid} tid={tid} rank={i + 1} />
|
||||||
|
})}
|
||||||
|
</Tracklist>
|
||||||
|
|
||||||
|
{tracks.length - limit - more > 0 && (
|
||||||
|
<div
|
||||||
|
className="top-more"
|
||||||
|
onClick={(e) => {
|
||||||
|
setMore((m) => m + 10)
|
||||||
|
}}
|
||||||
|
>
|
||||||
|
Pokaż więcej ({tracks.length - limit - more})
|
||||||
|
</div>
|
||||||
|
)}
|
||||||
</div>
|
</div>
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -50,6 +50,14 @@
|
|||||||
cursor: pointer;
|
cursor: pointer;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
.track:nth-child(-n + 21) .track-rank {
|
||||||
|
color: var(--dark);
|
||||||
|
border-radius: 100%;
|
||||||
|
margin: 0 0.5em;
|
||||||
|
background-color: var(--light);
|
||||||
|
filter: drop-shadow(0 0 2px #6665);
|
||||||
|
}
|
||||||
|
|
||||||
.track-rank:before {
|
.track-rank:before {
|
||||||
content: '#';
|
content: '#';
|
||||||
}
|
}
|
||||||
@@ -61,14 +69,14 @@
|
|||||||
}
|
}
|
||||||
|
|
||||||
.track-title {
|
.track-title {
|
||||||
padding: 0px 10px;
|
margin: 0px 10px;
|
||||||
font-weight: bold;
|
font-weight: bold;
|
||||||
text-decoration: none;
|
text-decoration: none;
|
||||||
color: inherit;
|
color: inherit;
|
||||||
}
|
}
|
||||||
|
|
||||||
.track-artist {
|
.track-artist {
|
||||||
padding: 0px 10px;
|
margin: 0px 10px;
|
||||||
color: #333;
|
color: #333;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -89,15 +97,15 @@
|
|||||||
left: 100%;
|
left: 100%;
|
||||||
top: 0;
|
top: 0;
|
||||||
border-radius: inherit;
|
border-radius: inherit;
|
||||||
background: hsl(12deg, 4%, 20%);
|
|
||||||
transition: 0.3s cubic-bezier(0.7, 0, 0.3, 1);
|
transition: 0.3s cubic-bezier(0.7, 0, 0.3, 1);
|
||||||
|
|
||||||
display: flex;
|
display: flex;
|
||||||
flex-direction: row;
|
flex-direction: row;
|
||||||
color: #fff;
|
color: #fff;
|
||||||
padding: 0.5em;
|
padding: 0.5em;
|
||||||
box-sizing: border-box;
|
box-sizing: border-box;
|
||||||
justify-content: space-around;
|
justify-content: space-around;
|
||||||
|
backdrop-filter: blur(1px);
|
||||||
|
background-color: hsla(var(--deg), 35%, 22%, 71%);
|
||||||
}
|
}
|
||||||
|
|
||||||
.track.open > .track-more {
|
.track.open > .track-more {
|
||||||
@@ -116,15 +124,17 @@
|
|||||||
|
|
||||||
.track-more-button > i {
|
.track-more-button > i {
|
||||||
width: 100%;
|
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);
|
background-color: var(--dark);
|
||||||
color: var(--main);
|
color: var(--main);
|
||||||
cursor: default;
|
cursor: default;
|
||||||
}
|
}
|
||||||
|
|
||||||
.track-more-button:hover {
|
.track-more-button:not([data-set='true']):hover > i {
|
||||||
background-color: #fff2;
|
background-color: #fff2;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -1,84 +1,135 @@
|
|||||||
import { useState } from 'react'
|
import { useState, createContext, useContext } from 'react'
|
||||||
import { Link, useHistory } from 'react-router-dom'
|
import { Link, useHistory } from 'react-router-dom'
|
||||||
|
|
||||||
|
import { credentials } from '../../Auth'
|
||||||
|
import { get } from '../../Cache'
|
||||||
|
|
||||||
|
import ModalLoginContext from '../../contexts/ModalLogin'
|
||||||
|
|
||||||
import './Track.css'
|
import './Track.css'
|
||||||
|
import './loading.css'
|
||||||
|
|
||||||
import def from '../../media/default.png'
|
import def from '../../media/default.png'
|
||||||
|
|
||||||
function Track({ track, timestamp, rank }) {
|
const TracklistContext = createContext({})
|
||||||
const [open, setOpen] = useState(false),
|
|
||||||
{
|
function Tracklist({ children }) {
|
||||||
id,
|
const [active, setActive] = useState(''),
|
||||||
title = '-',
|
value = { active, setActive }
|
||||||
artists = ['-'],
|
|
||||||
album = {},
|
return (
|
||||||
votes = {},
|
<TracklistContext.Provider value={value}>
|
||||||
cast = '',
|
{children}
|
||||||
} = track ?? {},
|
</TracklistContext.Provider>
|
||||||
history = useHistory()
|
)
|
||||||
|
}
|
||||||
|
|
||||||
|
function Track({ tid, timestamp, rank }) {
|
||||||
|
const history = useHistory()
|
||||||
|
|
||||||
|
const tracklist = useContext(TracklistContext),
|
||||||
|
{ setModalLogin } = useContext(ModalLoginContext)
|
||||||
|
|
||||||
|
const [track, setTrack] = useState({})
|
||||||
|
|
||||||
|
get(tid)
|
||||||
|
.then((tdata) => {
|
||||||
|
setTrack(tdata)
|
||||||
|
if (!tdata.stats) tdata.getStats().then((ntdata) => setTrack(ntdata))
|
||||||
|
})
|
||||||
|
.catch((err) => {
|
||||||
|
setTrack(err)
|
||||||
|
})
|
||||||
|
|
||||||
function vote(value) {
|
function vote(value) {
|
||||||
|
if (!credentials.token) return setModalLogin(true)
|
||||||
|
|
||||||
track
|
track
|
||||||
.setVote(value)
|
.setVote(value)
|
||||||
.then((ok) => ok && setOpen(false))
|
.then((ok) => ok && tracklist.setActive(false))
|
||||||
.catch((err) => console.error(err))
|
.catch((err) => console.error(err)) // TODO: alert on error
|
||||||
}
|
}
|
||||||
|
|
||||||
function info() {
|
function info() {
|
||||||
history.push(`/utwor/${id}`)
|
history.push(`/utwor/${tid}`)
|
||||||
}
|
}
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<div className={['track', open ? 'open' : ''].join(' ')} id={id}>
|
<div
|
||||||
|
className={[
|
||||||
|
'track',
|
||||||
|
tracklist.active === tid ? 'open' : '',
|
||||||
|
track.id ? 'loaded' : 'loading',
|
||||||
|
track instanceof Error ? 'failed' : '',
|
||||||
|
].join(' ')}
|
||||||
|
id={tid}
|
||||||
|
>
|
||||||
<div
|
<div
|
||||||
className={'track-section-a ' + (timestamp || rank ? '' : 'empty')}
|
className={'track-section-a ' + (timestamp || rank ? '' : 'empty')}
|
||||||
onClick={() => info()}
|
onClick={() => info()}
|
||||||
>
|
>
|
||||||
{timestamp && <span className="track-timestamp">{timestamp}</span>}
|
{timestamp && <span className="track-timestamp">{timestamp}</span>}
|
||||||
{rank && <span className="track-rank">{rank}</span>}
|
{rank && (
|
||||||
<img className="track-image" src={album.art ?? def} alt="album cover" />
|
<span className="track-rank" data-votes={track?.stats?.total}>
|
||||||
|
{rank}
|
||||||
|
</span>
|
||||||
|
)}
|
||||||
|
<img
|
||||||
|
className="track-image"
|
||||||
|
src={track.album?.art ? track.album?.art[2].url : def}
|
||||||
|
alt="album cover"
|
||||||
|
/>
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
<div className="track-section-b" onClick={() => info()}>
|
<div className="track-section-b" onClick={() => info()}>
|
||||||
<span className="track-title">{title}</span>
|
{track instanceof Error ? (
|
||||||
<span className="track-artist">{artists.join(', ')}</span>
|
<>
|
||||||
|
<span className="track-title">{tid}</span>
|
||||||
|
<span className="track-artist">Wystąpił błąd {track.message}</span>
|
||||||
|
</>
|
||||||
|
) : (
|
||||||
|
<>
|
||||||
|
<span className="track-title">{track.title}</span>
|
||||||
|
<span className="track-artist">{track.artists?.join(', ')}</span>
|
||||||
|
</>
|
||||||
|
)}
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
<div className="track-icons">
|
<div className="track-icons">
|
||||||
<i
|
<i
|
||||||
className="icon-ellipsis-vert"
|
className="icon-ellipsis-vert"
|
||||||
onClick={() => {
|
onClick={() => tracklist.setActive(tid)}
|
||||||
setOpen(true)
|
|
||||||
}}
|
|
||||||
></i>
|
></i>
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
<div className="track-more">
|
<div className="track-more">
|
||||||
<div className="track-more-button">
|
<div
|
||||||
<i
|
className="track-more-button"
|
||||||
className="icon-thumbs-up"
|
data-set={track.stats?.cast === 'up'}
|
||||||
data-set={cast === 'up'}
|
onClick={(e) => vote('up')}
|
||||||
onClick={(e) => vote('up')}
|
>
|
||||||
></i>
|
<i className="icon-thumbs-up"></i>
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
<div className="track-more-button">
|
<div
|
||||||
<i
|
className="track-more-button"
|
||||||
className="icon-thumbs-down"
|
data-set={track.stats?.cast === 'down'}
|
||||||
data-set={cast === 'down'}
|
onClick={(e) => vote('down')}
|
||||||
onClick={(e) => vote('down')}
|
>
|
||||||
></i>
|
<i className="icon-thumbs-down"></i>
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
<Link to={`/utwor/${id}`} className="track-more-button">
|
<Link to={`/utwor/${tid}`} className="track-more-button">
|
||||||
<i className="icon-info"></i>
|
<i className="icon-info"></i>
|
||||||
</Link>
|
</Link>
|
||||||
|
|
||||||
<div className="track-more-button">
|
<div
|
||||||
<i
|
className="track-more-button"
|
||||||
className="icon-cancel-circled"
|
onClick={() => {
|
||||||
onClick={() => {
|
tracklist.setActive(false)
|
||||||
setOpen(false)
|
}}
|
||||||
}}
|
>
|
||||||
></i>
|
<i className="icon-cancel-circled"></i>
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
@@ -86,3 +137,4 @@ function Track({ track, timestamp, rank }) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
export default Track
|
export default Track
|
||||||
|
export { Track, Tracklist }
|
||||||
@@ -0,0 +1,43 @@
|
|||||||
|
@keyframes shine {
|
||||||
|
0% {
|
||||||
|
transform: translateX(-100%);
|
||||||
|
}
|
||||||
|
100% {
|
||||||
|
transform: translateX(100%);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
.track.loading:not(.failed):after {
|
||||||
|
content: '';
|
||||||
|
top: 0;
|
||||||
|
transform: translateX(100%);
|
||||||
|
width: 100%;
|
||||||
|
height: 100%;
|
||||||
|
position: absolute;
|
||||||
|
z-index: 1;
|
||||||
|
animation: shine 1.5s infinite;
|
||||||
|
|
||||||
|
pointer-events: none;
|
||||||
|
|
||||||
|
background: linear-gradient(
|
||||||
|
to right,
|
||||||
|
rgba(255, 255, 255, 0) 0%,
|
||||||
|
rgba(255, 255, 255, 0.4) 50%,
|
||||||
|
rgba(128, 186, 232, 0) 99%,
|
||||||
|
rgba(125, 185, 232, 0) 100%
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
.track.loading {
|
||||||
|
background-color: #eee5;
|
||||||
|
}
|
||||||
|
|
||||||
|
.track.loading:not(.failed) > .track-section-b > * {
|
||||||
|
width: 5em;
|
||||||
|
background-color: #6666;
|
||||||
|
height: 1em;
|
||||||
|
}
|
||||||
|
|
||||||
|
.track.failed {
|
||||||
|
background-color: #eaa5;
|
||||||
|
}
|
||||||
@@ -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
|
||||||
@@ -5,6 +5,17 @@ body {
|
|||||||
sans-serif;
|
sans-serif;
|
||||||
-webkit-font-smoothing: antialiased;
|
-webkit-font-smoothing: antialiased;
|
||||||
-moz-osx-font-smoothing: grayscale;
|
-moz-osx-font-smoothing: grayscale;
|
||||||
|
|
||||||
|
background-image: url('./media/skyline.jpg');
|
||||||
|
background-size: cover;
|
||||||
|
background-color: var(--light);
|
||||||
|
background-blend-mode: multiply;
|
||||||
|
transition: background-color 0.5s;
|
||||||
|
}
|
||||||
|
|
||||||
|
#root {
|
||||||
|
backdrop-filter: blur(6px);
|
||||||
|
height: 100vh;
|
||||||
}
|
}
|
||||||
|
|
||||||
:root {
|
:root {
|
||||||
@@ -14,3 +25,18 @@ body {
|
|||||||
--main: hsl(var(--deg), 57%, 52%);
|
--main: hsl(var(--deg), 57%, 52%);
|
||||||
--dark: hsl(var(--deg) 55% 22%);
|
--dark: hsl(var(--deg) 55% 22%);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@media (pointer: fine) {
|
||||||
|
::-webkit-scrollbar-track {
|
||||||
|
border-radius: 10px;
|
||||||
|
}
|
||||||
|
|
||||||
|
::-webkit-scrollbar {
|
||||||
|
width: 0.5em;
|
||||||
|
}
|
||||||
|
|
||||||
|
::-webkit-scrollbar-thumb {
|
||||||
|
border-radius: 3px;
|
||||||
|
background-color: var(--main);
|
||||||
|
}
|
||||||
|
}
|
||||||
+1
-1
@@ -15,6 +15,6 @@ ReactDOM.render(
|
|||||||
)
|
)
|
||||||
|
|
||||||
// If you want to start measuring performance in your app, pass a function
|
// If you want to start measuring performance in your app, pass a function
|
||||||
// to log results (for example: reportWebVitals(console.log))
|
// to log results (for example: reportWebVitals(console.info))
|
||||||
// or send to an analytics endpoint. Learn more: https://bit.ly/CRA-vitals
|
// or send to an analytics endpoint. Learn more: https://bit.ly/CRA-vitals
|
||||||
reportWebVitals()
|
reportWebVitals()
|
||||||
Binary file not shown.
|
After Width: | Height: | Size: 13 KiB |
+7
-3
@@ -1,10 +1,14 @@
|
|||||||
|
// import dotenv from 'dotenv'
|
||||||
|
|
||||||
|
// dotenv.config()
|
||||||
|
|
||||||
const events = {}
|
const events = {}
|
||||||
|
|
||||||
let socket,
|
let socket,
|
||||||
retries = 0
|
retries = 0
|
||||||
|
|
||||||
function open() {
|
function open() {
|
||||||
socket = new WebSocket(`wss://${window.location.host}/ws/`)
|
socket = new WebSocket(process.env.REACT_APP_WS_SERVER)
|
||||||
|
|
||||||
socket.onopen = () => {
|
socket.onopen = () => {
|
||||||
console.info(`Socket: connected`)
|
console.info(`Socket: connected`)
|
||||||
@@ -19,10 +23,10 @@ function open() {
|
|||||||
socket.onmessage = (e) => {
|
socket.onmessage = (e) => {
|
||||||
let data = JSON.parse(e.data)
|
let data = JSON.parse(e.data)
|
||||||
|
|
||||||
console.debug(data)
|
|
||||||
|
|
||||||
if (!Array.isArray(data)) data = [data]
|
if (!Array.isArray(data)) data = [data]
|
||||||
|
|
||||||
|
console.debug(data.map(({ cat }) => cat).join(' '), data)
|
||||||
|
|
||||||
for (let chunk of data) {
|
for (let chunk of data) {
|
||||||
let category = events[chunk.cat]
|
let category = events[chunk.cat]
|
||||||
if (category)
|
if (category)
|
||||||
|
|||||||
Reference in new issue
Block a user