Compare commits
19
Commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
20a53744f7 | ||
|
|
5b72299c82 | ||
|
|
e15943050f | ||
|
|
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
|
||||
@@ -0,0 +1,17 @@
|
||||
# radio-rolnik Website
|
||||
|
||||
## Resources
|
||||
|
||||
API - https://github.com/Maathias/radio-rolnik-api/
|
||||
|
||||
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
|
||||
```
|
||||
Generated
+106
-3
@@ -3992,6 +3992,11 @@
|
||||
"isarray": "^1.0.0"
|
||||
}
|
||||
},
|
||||
"buffer-equal-constant-time": {
|
||||
"version": "1.0.1",
|
||||
"resolved": "https://registry.npmjs.org/buffer-equal-constant-time/-/buffer-equal-constant-time-1.0.1.tgz",
|
||||
"integrity": "sha1-+OcRMvf/5uAaXJaXpMbz5I1cyBk="
|
||||
},
|
||||
"buffer-from": {
|
||||
"version": "1.1.2",
|
||||
"resolved": "https://registry.npmjs.org/buffer-from/-/buffer-from-1.1.2.tgz",
|
||||
@@ -5344,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",
|
||||
@@ -5369,6 +5374,14 @@
|
||||
"stream-shift": "^1.0.0"
|
||||
}
|
||||
},
|
||||
"ecdsa-sig-formatter": {
|
||||
"version": "1.0.11",
|
||||
"resolved": "https://registry.npmjs.org/ecdsa-sig-formatter/-/ecdsa-sig-formatter-1.0.11.tgz",
|
||||
"integrity": "sha512-nagl3RYrbNv6kQkeJIpt6NJZy8twLB/2vtz6yN9Z4vRKHN4/QZJIEbqohALSgwKdnksuY3k5Addp5lg8sVoVcQ==",
|
||||
"requires": {
|
||||
"safe-buffer": "^5.0.1"
|
||||
}
|
||||
},
|
||||
"ee-first": {
|
||||
"version": "1.1.1",
|
||||
"resolved": "https://registry.npmjs.org/ee-first/-/ee-first-1.1.1.tgz",
|
||||
@@ -9731,6 +9744,30 @@
|
||||
"universalify": "^2.0.0"
|
||||
}
|
||||
},
|
||||
"jsonwebtoken": {
|
||||
"version": "8.5.1",
|
||||
"resolved": "https://registry.npmjs.org/jsonwebtoken/-/jsonwebtoken-8.5.1.tgz",
|
||||
"integrity": "sha512-XjwVfRS6jTMsqYs0EsuJ4LGxXV14zQybNd4L2r0UvbVnSF9Af8x7p5MzbJ90Ioz/9TI41/hTCvznF/loiSzn8w==",
|
||||
"requires": {
|
||||
"jws": "^3.2.2",
|
||||
"lodash.includes": "^4.3.0",
|
||||
"lodash.isboolean": "^3.0.3",
|
||||
"lodash.isinteger": "^4.0.4",
|
||||
"lodash.isnumber": "^3.0.3",
|
||||
"lodash.isplainobject": "^4.0.6",
|
||||
"lodash.isstring": "^4.0.1",
|
||||
"lodash.once": "^4.0.0",
|
||||
"ms": "^2.1.1",
|
||||
"semver": "^5.6.0"
|
||||
},
|
||||
"dependencies": {
|
||||
"semver": {
|
||||
"version": "5.7.1",
|
||||
"resolved": "https://registry.npmjs.org/semver/-/semver-5.7.1.tgz",
|
||||
"integrity": "sha512-sauaDf/PZdVgrLTNYHRtpXa1iRiKcaebiKQ1BJdpQlWH2lCvexQdX55snPFyK7QzpudqbCI0qXFfOasHdyNDGQ=="
|
||||
}
|
||||
}
|
||||
},
|
||||
"jsx-ast-utils": {
|
||||
"version": "3.2.0",
|
||||
"resolved": "https://registry.npmjs.org/jsx-ast-utils/-/jsx-ast-utils-3.2.0.tgz",
|
||||
@@ -9740,6 +9777,25 @@
|
||||
"object.assign": "^4.1.2"
|
||||
}
|
||||
},
|
||||
"jwa": {
|
||||
"version": "1.4.1",
|
||||
"resolved": "https://registry.npmjs.org/jwa/-/jwa-1.4.1.tgz",
|
||||
"integrity": "sha512-qiLX/xhEEFKUAJ6FiBMbes3w9ATzyk5W7Hvzpa/SLYdxNtng+gcurvrI7TbACjIXlsJyr05/S1oUhZrc63evQA==",
|
||||
"requires": {
|
||||
"buffer-equal-constant-time": "1.0.1",
|
||||
"ecdsa-sig-formatter": "1.0.11",
|
||||
"safe-buffer": "^5.0.1"
|
||||
}
|
||||
},
|
||||
"jws": {
|
||||
"version": "3.2.2",
|
||||
"resolved": "https://registry.npmjs.org/jws/-/jws-3.2.2.tgz",
|
||||
"integrity": "sha512-YHlZCB6lMTllWDtSPHz/ZXTsi8S00usEV6v1tjq8tOUZzw7DpSDWVXjXDre6ed1w/pd495ODpHZYSdkRTsa0HA==",
|
||||
"requires": {
|
||||
"jwa": "^1.4.1",
|
||||
"safe-buffer": "^5.0.1"
|
||||
}
|
||||
},
|
||||
"killable": {
|
||||
"version": "1.0.1",
|
||||
"resolved": "https://registry.npmjs.org/killable/-/killable-1.0.1.tgz",
|
||||
@@ -9848,6 +9904,11 @@
|
||||
"json5": "^2.1.2"
|
||||
}
|
||||
},
|
||||
"local-storage": {
|
||||
"version": "2.0.0",
|
||||
"resolved": "https://registry.npmjs.org/local-storage/-/local-storage-2.0.0.tgz",
|
||||
"integrity": "sha512-/0sRoeijw7yr/igbVVygDuq6dlYCmtsuTmmpnweVlVtl/s10pf5BCq8LWBxW/AMyFJ3MhMUuggMZiYlx6qr9tw=="
|
||||
},
|
||||
"locate-path": {
|
||||
"version": "5.0.0",
|
||||
"resolved": "https://registry.npmjs.org/locate-path/-/locate-path-5.0.0.tgz",
|
||||
@@ -9876,6 +9937,36 @@
|
||||
"resolved": "https://registry.npmjs.org/lodash.debounce/-/lodash.debounce-4.0.8.tgz",
|
||||
"integrity": "sha1-gteb/zCmfEAF/9XiUVMArZyk168="
|
||||
},
|
||||
"lodash.includes": {
|
||||
"version": "4.3.0",
|
||||
"resolved": "https://registry.npmjs.org/lodash.includes/-/lodash.includes-4.3.0.tgz",
|
||||
"integrity": "sha1-YLuYqHy5I8aMoeUTJUgzFISfVT8="
|
||||
},
|
||||
"lodash.isboolean": {
|
||||
"version": "3.0.3",
|
||||
"resolved": "https://registry.npmjs.org/lodash.isboolean/-/lodash.isboolean-3.0.3.tgz",
|
||||
"integrity": "sha1-bC4XHbKiV82WgC/UOwGyDV9YcPY="
|
||||
},
|
||||
"lodash.isinteger": {
|
||||
"version": "4.0.4",
|
||||
"resolved": "https://registry.npmjs.org/lodash.isinteger/-/lodash.isinteger-4.0.4.tgz",
|
||||
"integrity": "sha1-YZwK89A/iwTDH1iChAt3sRzWg0M="
|
||||
},
|
||||
"lodash.isnumber": {
|
||||
"version": "3.0.3",
|
||||
"resolved": "https://registry.npmjs.org/lodash.isnumber/-/lodash.isnumber-3.0.3.tgz",
|
||||
"integrity": "sha1-POdoEMWSjQM1IwGsKHMX8RwLH/w="
|
||||
},
|
||||
"lodash.isplainobject": {
|
||||
"version": "4.0.6",
|
||||
"resolved": "https://registry.npmjs.org/lodash.isplainobject/-/lodash.isplainobject-4.0.6.tgz",
|
||||
"integrity": "sha1-fFJqUtibRcRcxpC4gWO+BJf1UMs="
|
||||
},
|
||||
"lodash.isstring": {
|
||||
"version": "4.0.1",
|
||||
"resolved": "https://registry.npmjs.org/lodash.isstring/-/lodash.isstring-4.0.1.tgz",
|
||||
"integrity": "sha1-1SfftUVuynzJu5XV2ur4i6VKVFE="
|
||||
},
|
||||
"lodash.memoize": {
|
||||
"version": "4.1.2",
|
||||
"resolved": "https://registry.npmjs.org/lodash.memoize/-/lodash.memoize-4.1.2.tgz",
|
||||
@@ -9886,6 +9977,11 @@
|
||||
"resolved": "https://registry.npmjs.org/lodash.merge/-/lodash.merge-4.6.2.tgz",
|
||||
"integrity": "sha512-0KpjqXRVvrYyCsX1swR/XTK0va6VQkQM6MNo7PqW77ByjAhoARA8EfrP1N4+KlKj8YS0ZUCtRT/YUuhyYDujIQ=="
|
||||
},
|
||||
"lodash.once": {
|
||||
"version": "4.1.1",
|
||||
"resolved": "https://registry.npmjs.org/lodash.once/-/lodash.once-4.1.1.tgz",
|
||||
"integrity": "sha1-DdOXEhPHxW34gJd9UEyI+0cal6w="
|
||||
},
|
||||
"lodash.template": {
|
||||
"version": "4.5.0",
|
||||
"resolved": "https://registry.npmjs.org/lodash.template/-/lodash.template-4.5.0.tgz",
|
||||
@@ -12670,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": {
|
||||
|
||||
+4
-1
@@ -7,8 +7,11 @@
|
||||
"@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",
|
||||
"local-storage": "^2.0.0",
|
||||
"react": "^17.0.2",
|
||||
"react-dom": "^17.0.2",
|
||||
"react-ga": "^3.3.0",
|
||||
@@ -41,4 +44,4 @@
|
||||
"last 1 safari version"
|
||||
]
|
||||
}
|
||||
}
|
||||
}
|
||||
+9
-10
@@ -14,23 +14,22 @@
|
||||
<meta name="keywords" content="radio, rolnik">
|
||||
<meta name="author" content="Mathias">
|
||||
<title>radio-rolnik</title>
|
||||
|
||||
<meta name="google-site-verification" content="X202JcXlBt0U8ej5LjzpYFGRrwSHZrIN8QwfNEcqaig" />
|
||||
<link rel="stylesheet" href="/fontello.css">
|
||||
|
||||
<!-- Social embed properties -->
|
||||
<!-- <meta property="og:type" content="website" />
|
||||
<meta property="og:url" content="https://radio-rolnik.mtps.pl/" />
|
||||
<meta property="og:type" content="website" />
|
||||
<meta property="og:url" content="https://%REACT_APP_DOMAIN%/" />
|
||||
|
||||
<meta property="og:title" content="radio-rolnik" />
|
||||
<meta property="twitter:title" content="radio-rolnik" />
|
||||
<meta property="og:title" content="%REACT_APP_NAME%" />
|
||||
<meta property="twitter:title" content="%REACT_APP_NAME%" />
|
||||
|
||||
<meta property="og:description" content="radio-rolnik" />
|
||||
<meta property="twitter:description" content="radio-rolnik" />
|
||||
<meta property="og:description" content="%REACT_APP_NAME%" />
|
||||
<meta property="twitter:description" content="%REACT_APP_NAME%" />
|
||||
|
||||
<meta property="og:image" content="https://radio-rolnik.mtps.pl/media/thumbnail.png" />
|
||||
<meta property="twitter: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://%REACT_APP_DOMAIN%/media/banner.png" />
|
||||
|
||||
<!-- <script src="https://www.google.com/recaptcha/api.js?render=6LfdNtIaAAAAAMY6rU7Q9tMlJtlz8k49ke5rUOaU"></script> -->
|
||||
</head>
|
||||
|
||||
<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 { credentials } from './Auth'
|
||||
|
||||
var tracks = {}
|
||||
var Tracks = {}
|
||||
|
||||
/** Object representation for track metadata */
|
||||
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) {
|
||||
Object.assign(this, tdata)
|
||||
|
||||
this.stats = {
|
||||
up: -1,
|
||||
down: -1,
|
||||
}
|
||||
this.rank = -1
|
||||
this.cast = ''
|
||||
|
||||
this.getVote()
|
||||
// this.getVote()
|
||||
}
|
||||
|
||||
/**
|
||||
* Link to track's playback
|
||||
*/
|
||||
get listen() {
|
||||
return `https://open.spotify.com/track/${this.id}`
|
||||
}
|
||||
|
||||
/**
|
||||
* Self link to open Track's Info page
|
||||
*/
|
||||
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) {
|
||||
return new Promise((resolve, reject) => {
|
||||
if (value === this.cast) return
|
||||
ky.patch(`/api/vote/${this.id}`, { json: { uid: 'mathias', value } })
|
||||
if (value === this.stats.cast) return
|
||||
ky.patch(`/api/vote/${this.id}`, {
|
||||
json: { value },
|
||||
headers: { authorization: credentials.token },
|
||||
})
|
||||
.json()
|
||||
.then((ok) => {
|
||||
if (ok) {
|
||||
this.cast = value
|
||||
if (value === 'report') return
|
||||
this.stats.cast = value
|
||||
this.getStats()
|
||||
}
|
||||
resolve(ok)
|
||||
@@ -40,37 +63,56 @@ class Track {
|
||||
})
|
||||
}
|
||||
|
||||
/**
|
||||
* Get user's vote for track
|
||||
* @returns {Promise} vote value
|
||||
*/
|
||||
getVote() {
|
||||
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()
|
||||
.then((cast) => {
|
||||
this.cast = cast
|
||||
this.stats.cast = cast
|
||||
resolve(cast)
|
||||
})
|
||||
.catch((err) => {
|
||||
console.error(err)
|
||||
})
|
||||
.catch((err) => reject(err))
|
||||
})
|
||||
}
|
||||
|
||||
/**
|
||||
* Update Track's stats
|
||||
* @returns {Promise} stats object
|
||||
*/
|
||||
getStats() {
|
||||
return new Promise((resolve, reject) => {
|
||||
getStats(this.id)
|
||||
.then((stats) => {
|
||||
this.stats = stats
|
||||
resolve(stats)
|
||||
})
|
||||
.catch((err) => {
|
||||
console.error(err)
|
||||
})
|
||||
})
|
||||
if (this._stats) return this._stats
|
||||
else
|
||||
return (this._stats = new Promise((resolve, reject) => {
|
||||
getStats(this.id)
|
||||
.then((stats) => {
|
||||
this.stats = stats
|
||||
resolve(this)
|
||||
})
|
||||
.catch((err) => reject(err))
|
||||
}))
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Requests Track stats (votes upd and down)
|
||||
* @param {String} id track id
|
||||
* @returns {Promise} stats object
|
||||
*/
|
||||
function getStats(id) {
|
||||
return new Promise((resolve, reject) => {
|
||||
ky.get(`/api/vote/${id}`)
|
||||
ky.get(`/api/vote/${id}`, {
|
||||
headers: { authorization: credentials.token },
|
||||
})
|
||||
.json()
|
||||
.then((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) {
|
||||
return new Promise((resolve, reject) => {
|
||||
if (typeof tracks[id] === 'undefined') {
|
||||
download(id)
|
||||
.then((track) => resolve(track))
|
||||
.catch((err) => reject(err))
|
||||
} else resolve(tracks[id])
|
||||
})
|
||||
if (typeof Tracks[id] === 'undefined') {
|
||||
Tracks[id] = download(id)
|
||||
}
|
||||
|
||||
return Tracks[id]
|
||||
}
|
||||
|
||||
function getMultiple(ids) {
|
||||
return new Promise((resolve, reject) => {
|
||||
Promise.all(ids.map((id) => get(id)))
|
||||
.then((tracks) => resolve(tracks))
|
||||
.catch((err) => {
|
||||
console.error(err)
|
||||
})
|
||||
})
|
||||
/**
|
||||
* Get multiple Tracks
|
||||
* @param {Array} ids Array of track ids
|
||||
* @returns {Array} Array of Tracks
|
||||
*/
|
||||
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) {
|
||||
return new Promise((resolve, reject) => {
|
||||
ky.get('/api/track/' + id)
|
||||
.json()
|
||||
.then((track) => {
|
||||
tracks[track.id] = new Track(track)
|
||||
resolve(tracks[track.id])
|
||||
resolve(new Track(track))
|
||||
})
|
||||
.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) {
|
||||
return new Promise((resolve, reject) => {
|
||||
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'
|
||||
|
||||
var fac = new FastAverageColor(),
|
||||
def = document.documentElement.style.getPropertyValue('--deg')
|
||||
def = 0
|
||||
|
||||
function setColor(target, lvl) {
|
||||
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,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 {
|
||||
|
||||
@@ -1,38 +1,62 @@
|
||||
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 './History.css'
|
||||
import './playing.css'
|
||||
|
||||
function History({ next, tracks }) {
|
||||
const playing = useContext(PlayingContext)
|
||||
function History({ next, tracks, paused }) {
|
||||
const { tid } = useContext(PlayingContext)
|
||||
|
||||
getMultiple(tracks.map(([tid]) => tid))
|
||||
|
||||
return (
|
||||
<div className="wrapper history">
|
||||
{next && (
|
||||
<div className="history-section next">
|
||||
<span>Następny:</span>
|
||||
<Track track={next} timestamp=">" />
|
||||
<Tracklist>
|
||||
{next && (
|
||||
<div className="history-section next">
|
||||
<span 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 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>
|
||||
</Tracklist>
|
||||
</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;
|
||||
flex-direction: column;
|
||||
align-items: stretch;
|
||||
height: 100%;
|
||||
}
|
||||
|
||||
.info-image {
|
||||
@@ -19,10 +18,10 @@
|
||||
|
||||
.info-wrapper {
|
||||
border-radius: 0.5em;
|
||||
background: linear-gradient(180deg, white, transparent);
|
||||
height: 100%;
|
||||
padding: 1em;
|
||||
box-shadow: 0 -1px 11px 2px #6b6b6b52;
|
||||
background-color: hsl(var(--deg) 4% 98% / 70%);
|
||||
}
|
||||
|
||||
.info-wrapper > .title {
|
||||
@@ -32,12 +31,17 @@
|
||||
|
||||
.info-balance {
|
||||
width: 100%;
|
||||
font-size: 0.75em;
|
||||
font-family: monospace;
|
||||
background-color: var(--light);
|
||||
margin: 1em 0;
|
||||
display: flex;
|
||||
}
|
||||
|
||||
.info-balance[disabled] {
|
||||
filter: grayscale();
|
||||
opacity: 0.4;
|
||||
}
|
||||
|
||||
.info-balance > div {
|
||||
display: inline-block;
|
||||
min-width: 2em;
|
||||
@@ -48,18 +52,26 @@
|
||||
color: white;
|
||||
}
|
||||
|
||||
.info-list {
|
||||
display: flex;
|
||||
flex-wrap: wrap;
|
||||
}
|
||||
|
||||
.info-list > div {
|
||||
padding: 0.7em;
|
||||
display: flex;
|
||||
justify-content: space-around;
|
||||
justify-content: center;
|
||||
width: 100%;
|
||||
box-sizing: border-box;
|
||||
}
|
||||
|
||||
.info-list > div:not(:last-child) {
|
||||
border-bottom: 1px solid #cccc;
|
||||
}
|
||||
|
||||
.info-list > div:nth-child(-n + 2) {
|
||||
.info-list > .buttons {
|
||||
padding: 0;
|
||||
padding-bottom: 0.25em;
|
||||
}
|
||||
|
||||
.info-list > .buttons > i {
|
||||
@@ -73,9 +85,10 @@
|
||||
background-color: var(--light);
|
||||
color: var(--main);
|
||||
cursor: default;
|
||||
border-radius: 1em;
|
||||
}
|
||||
|
||||
.info-list > div > i:hover {
|
||||
.info-list > .buttons > i:hover {
|
||||
/* background-color: #cccc; */
|
||||
color: var(--main);
|
||||
}
|
||||
|
||||
+98
-53
@@ -4,15 +4,18 @@ import { useParams, Redirect } from 'react-router-dom'
|
||||
import Modal from '../Modal/Modal'
|
||||
|
||||
import { get } from '../../Cache'
|
||||
import { credentials } from '../../Auth'
|
||||
|
||||
import PlayingContext from '../../contexts/Playing'
|
||||
import ModalLoginContext from '../../contexts/ModalLogin'
|
||||
|
||||
import './Info.css'
|
||||
import def from '../../media/default.png'
|
||||
import admin from '../../Admin'
|
||||
|
||||
var last
|
||||
|
||||
function Info() {
|
||||
function Info({ top }) {
|
||||
const { id } = useParams(),
|
||||
[track, setTrack] = useState({
|
||||
title: '-',
|
||||
@@ -21,11 +24,12 @@ function Info() {
|
||||
artists: ['-'],
|
||||
}),
|
||||
[meta, setMeta] = useState('...'),
|
||||
[showModal, setShowModal] = useState(true),
|
||||
[modalReport, setModalReport] = useState(false),
|
||||
{ setModalLogin } = useContext(ModalLoginContext),
|
||||
playing = useContext(PlayingContext)
|
||||
|
||||
if (!id) last = playing.id ?? ''
|
||||
else last = id
|
||||
if (id) last = id
|
||||
if (!last) last = id ?? playing.id ?? top ?? ''
|
||||
|
||||
useEffect(() => {
|
||||
setMeta(`Pobieranie... ${last}`)
|
||||
@@ -34,84 +38,96 @@ function Info() {
|
||||
track
|
||||
.getStats()
|
||||
.then((stats) => {
|
||||
track
|
||||
.getVote()
|
||||
.then(() => {
|
||||
setTrack(track)
|
||||
setMeta(false)
|
||||
})
|
||||
.catch((err) => console.error(err))
|
||||
setTrack(track)
|
||||
setMeta(false)
|
||||
})
|
||||
.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`)
|
||||
})
|
||||
)
|
||||
}, [last]) // eslint-disable-line
|
||||
|
||||
if (!id && last) return <Redirect to={`/utwor/${last}`} />
|
||||
|
||||
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
|
||||
.setVote(value)
|
||||
.then((ok) => {
|
||||
track
|
||||
.getStats()
|
||||
.then(() => {
|
||||
// http ok, vote accepted?
|
||||
ok
|
||||
? 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,
|
||||
percent =
|
||||
total > 0
|
||||
? (track.stats.up / (track.stats.up + track.stats.down)) * 100
|
||||
: 50
|
||||
function report() {
|
||||
track.setVote('report')
|
||||
setModalReport(false)
|
||||
}
|
||||
|
||||
console.log(track.stats)
|
||||
|
||||
const total = track.stats.total,
|
||||
percent = total > 0 ? (track.stats.up / total) * 100 : 50
|
||||
|
||||
document.setTitle(track.title)
|
||||
|
||||
const toggleModal = () => setShowModal(!showModal)
|
||||
const report = () => {
|
||||
track.setVote('report')
|
||||
}
|
||||
|
||||
return (
|
||||
<div className="wrapper info">
|
||||
<img
|
||||
src={track.album.art ?? def}
|
||||
src={track.album.art ? track.album.art[0].url : def}
|
||||
className="info-image"
|
||||
alt="album cover"
|
||||
/>
|
||||
<div className="info-wrapper">
|
||||
<span className="title">{track.title}</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}%` }}>
|
||||
{track.stats.up}
|
||||
{track.stats.up}
|
||||
</div>
|
||||
<div className="down" style={{ width: `${100 - percent}%` }}>
|
||||
{track.stats.down}
|
||||
</div>
|
||||
</div>
|
||||
|
||||
{meta && <span className="info-meta">{meta}</span>}
|
||||
<span className="info-meta"> {meta}</span>
|
||||
|
||||
{track.id && (
|
||||
<div className="info-list">
|
||||
<div className="buttons">
|
||||
<i
|
||||
className="icon-thumbs-up"
|
||||
data-set={track.cast === 'up'}
|
||||
data-set={track.stats.cast === 'up'}
|
||||
onClick={(e) => vote('up')}
|
||||
></i>
|
||||
<i
|
||||
className="icon-thumbs-down"
|
||||
data-set={track.cast === 'down'}
|
||||
data-set={track.stats.cast === 'down'}
|
||||
onClick={(e) => vote('down')}
|
||||
></i>
|
||||
</div>
|
||||
@@ -136,29 +152,57 @@ function Info() {
|
||||
></i>
|
||||
<i
|
||||
className="icon-flag"
|
||||
onClick={(e) => {
|
||||
toggleModal()
|
||||
}}
|
||||
onClick={(e) => setModalReport(true)}
|
||||
></i>
|
||||
</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>
|
||||
<span>{track.artists.join(', ')}</span>
|
||||
</div>
|
||||
|
||||
<div>
|
||||
<span>
|
||||
{track.album.name ?? '-'} ({track.album.year ?? '-'})
|
||||
</span>
|
||||
</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 && (
|
||||
<div>
|
||||
<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>
|
||||
</div>
|
||||
)}
|
||||
@@ -166,27 +210,28 @@ function Info() {
|
||||
)}
|
||||
</div>
|
||||
<span className="info-data">{id}</span>
|
||||
{showModal ? (
|
||||
{modalReport && (
|
||||
<Modal>
|
||||
<div className="modal-text">
|
||||
<div>
|
||||
Czy na pewno chcesz zgłosić utwór{' '}
|
||||
<i>
|
||||
<b>{track.title}</b>
|
||||
</i>
|
||||
?
|
||||
</div>
|
||||
<div class="modal-title">Czy na pewno chcesz zgłosić utwór?</div>
|
||||
<div class="modal-body">
|
||||
Zgłoszone utwory trafiają do sprawdzenia przez administrację. Jeżeli
|
||||
<b> {track.title}</b> zawiera treści nieodpowiednie lub
|
||||
<i> bardzo</i> nie chciałbyś go usłyszeć na korytarzu, zalecamy
|
||||
zgłoszanie tego utworu.
|
||||
</div>
|
||||
<div className="modal-buttons-2">
|
||||
<button onClick={toggleModal} className="modal-button">
|
||||
Nie
|
||||
<div className="modal-buttons">
|
||||
<button
|
||||
onClick={() => setModalReport(false)}
|
||||
className="modal-button"
|
||||
>
|
||||
Anuluj
|
||||
</button>
|
||||
<button onClick={report} className="modal-button">
|
||||
Tak
|
||||
Zgłoś
|
||||
</button>
|
||||
</div>
|
||||
</Modal>
|
||||
) : null}
|
||||
)}
|
||||
</div>
|
||||
)
|
||||
}
|
||||
|
||||
@@ -1,17 +1,17 @@
|
||||
@import url('https://fonts.googleapis.com/css2?family=Quicksand&family=Poppins');
|
||||
|
||||
.main {
|
||||
height: 100vh;
|
||||
height: 100%;
|
||||
justify-content: flex-end;
|
||||
background-color: var(--light);
|
||||
font-family: 'Quicksand';
|
||||
overflow: hidden;
|
||||
overflow: hidden auto;
|
||||
}
|
||||
|
||||
.wrapper {
|
||||
max-width: 600px;
|
||||
/* max-height: 100%; */
|
||||
margin: auto;
|
||||
box-sizing: border-box;
|
||||
padding-bottom: 8em;
|
||||
overflow-y: auto;
|
||||
/* overflow-y: auto; */
|
||||
}
|
||||
+94
-72
@@ -6,6 +6,7 @@ import {
|
||||
} from 'react-router-dom'
|
||||
import { useEffect, useState } from 'react'
|
||||
import ga from 'react-ga'
|
||||
import localStorage from 'local-storage'
|
||||
|
||||
import Nav from '../Nav/Nav'
|
||||
import History from '../History/History'
|
||||
@@ -13,12 +14,16 @@ import Status from '../Status/Status'
|
||||
import Info from '../Info/Info'
|
||||
import Top from '../Top/Top'
|
||||
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 { promptLogin } from '../../Auth'
|
||||
|
||||
import PlayingContext from '../../contexts/Playing'
|
||||
import GaContext from '../../contexts/Ga'
|
||||
import ModalLoginContext from '../../contexts/ModalLogin'
|
||||
import SettingsContext from '../../contexts/Settings'
|
||||
|
||||
import './Main.css'
|
||||
|
||||
@@ -37,93 +42,110 @@ document.setTitle = (prefix, suffix) => {
|
||||
|
||||
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([])
|
||||
[top, setTop] = useState([]),
|
||||
[topDate, setTopDate] = useState(),
|
||||
[modalLogin, setModalLogin] = useState(false),
|
||||
[settings, setSettings] = useState(localStorage('settings') ?? defaults)
|
||||
|
||||
// set up socket events
|
||||
useEffect(() => {
|
||||
addEvent('status', ({ trackid, progress, paused }) => {
|
||||
get(trackid)
|
||||
.then((track) => {
|
||||
setPlaying(track)
|
||||
setElapsed(progress)
|
||||
setPaused(paused)
|
||||
})
|
||||
.catch((err) => {
|
||||
setPaused(true)
|
||||
})
|
||||
addEvent('status', ({ tid, progress, duration, paused, timestamp }) => {
|
||||
if (tid === null) return
|
||||
setPlaying({ tid, timestamp })
|
||||
setElapsed([progress, duration])
|
||||
setPaused(paused)
|
||||
})
|
||||
|
||||
addEvent('next', ({ trackid }) => {
|
||||
get(trackid)
|
||||
.then((track) => {
|
||||
setNext(track)
|
||||
})
|
||||
.catch((err) => console.error(err))
|
||||
})
|
||||
addEvent('next', ({ tid }) => setNext(tid))
|
||||
|
||||
addEvent('previous', ({ trackids, timestamps }) => {
|
||||
getMultiple(trackids)
|
||||
.then((tracks) => {
|
||||
// insert timestamps to tracks
|
||||
tracks.map((track, i) => (track.timestamp = timestamps[i]))
|
||||
setPrevious(tracks)
|
||||
})
|
||||
.catch((err) => console.error(err))
|
||||
})
|
||||
addEvent('previous', ({ combo }) => setPrevious(combo))
|
||||
|
||||
addEvent('top', ({ trackids }) => {
|
||||
getMultiple(trackids)
|
||||
.then((tracks) => setTop(tracks))
|
||||
.catch((err) => console.error(err))
|
||||
addEvent('top', ({ tids, timestamp }) => {
|
||||
setTop(tids)
|
||||
setTopDate(new Date(timestamp))
|
||||
})
|
||||
}, [])
|
||||
}, []) // eslint-disable-line
|
||||
|
||||
// save settings on change
|
||||
useEffect(() => {
|
||||
localStorage('settings', settings)
|
||||
}, [settings])
|
||||
|
||||
return (
|
||||
<GaContext.Provider value={ga}>
|
||||
<PlayingContext.Provider value={playing}>
|
||||
<div className="main">
|
||||
<Router>
|
||||
<Switch>
|
||||
<Route exact path="/">
|
||||
<History next={next} tracks={previous} />
|
||||
</Route>
|
||||
<SettingsContext.Provider
|
||||
value={{
|
||||
settings,
|
||||
setSettings: (key, value) => {
|
||||
setSettings((settings) => ({ ...settings, [key]: !value }))
|
||||
},
|
||||
}}
|
||||
>
|
||||
<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?">
|
||||
<Info />
|
||||
</Route>
|
||||
<Route path="/utwor/:id?">
|
||||
<Info top={top[0]} />
|
||||
</Route>
|
||||
|
||||
<Route path="/top">
|
||||
<Top tracks={top} />
|
||||
</Route>
|
||||
<Route path="/top">
|
||||
<Top tracks={top} timestamp={topDate} />
|
||||
</Route>
|
||||
|
||||
<Route path="/wyszukaj/:query?">
|
||||
<Search />
|
||||
</Route>
|
||||
<Route path="/wyszukaj/:query?">
|
||||
<Search />
|
||||
</Route>
|
||||
|
||||
<Route render={() => <Redirect to="/" />} />
|
||||
</Switch>
|
||||
<Nav
|
||||
buttons={[
|
||||
{ label: 'Historia', to: '/', icon: 'align-left' },
|
||||
{ label: 'Wyszukaj', to: '/wyszukaj', icon: 'search' },
|
||||
{ label: 'Top', to: '/top', icon: 'list-numbered' },
|
||||
{
|
||||
label: 'Utwór',
|
||||
path: '/utwor',
|
||||
to: `/utwor`,
|
||||
icon: 'info',
|
||||
},
|
||||
{ label: 'Ustawienia', to: '/ustawienia', icon: 'cog-alt' },
|
||||
]}
|
||||
/>
|
||||
<Status progress={elapsed} paused={paused} />
|
||||
</Router>
|
||||
</div>
|
||||
</PlayingContext.Provider>
|
||||
</GaContext.Provider>
|
||||
<Route path="/ustawienia">
|
||||
<Settings />
|
||||
</Route>
|
||||
|
||||
<Route render={() => <Redirect to="/" />} />
|
||||
</Switch>
|
||||
<Nav
|
||||
buttons={[
|
||||
{ label: 'Historia', to: '/', icon: 'align-left' },
|
||||
{ label: 'Wyszukaj', to: '/wyszukaj', icon: 'search' },
|
||||
{ label: 'Top', to: '/top', icon: 'list-numbered' },
|
||||
{
|
||||
label: 'Utwór',
|
||||
path: '/utwor',
|
||||
to: `/utwor`,
|
||||
icon: 'info',
|
||||
},
|
||||
{ label: 'Ustawienia', to: '/ustawienia', icon: 'cog-alt' },
|
||||
]}
|
||||
/>
|
||||
<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 {
|
||||
background-color: var(--light);
|
||||
background-color: var(--white);
|
||||
color: var(--dark);
|
||||
border-radius: 0.5em;
|
||||
padding: 30px min(9vw, 30px);
|
||||
border-radius: 3px;
|
||||
padding: 1.25em 1.5em;
|
||||
max-width: 550px;
|
||||
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 {
|
||||
display: grid;
|
||||
grid-template-columns: 1fr;
|
||||
grid-template-rows: 1fr;
|
||||
grid-template-areas:
|
||||
'text'
|
||||
'modal-buttons';
|
||||
.modal > div.modal-title {
|
||||
font-size: 1.2em;
|
||||
font-weight: bold;
|
||||
border-bottom: 1px solid;
|
||||
padding-bottom: 0.3em;
|
||||
}
|
||||
.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 {
|
||||
border-radius: 0.5em 0 0 0.5em;
|
||||
}
|
||||
.modal-button:last-child {
|
||||
border-radius: 0 0.5em 0.5em 0;
|
||||
}
|
||||
div[class^='modal-buttons-'] {
|
||||
display: grid;
|
||||
grid-template-rows: 1fr;
|
||||
gap: 0px;
|
||||
grid-area: modal-buttons;
|
||||
margin-right: 0.5em;
|
||||
background-color: var(--white);
|
||||
color: var(--dark);
|
||||
}
|
||||
|
||||
.modal-buttons-1 {
|
||||
grid-template-columns: 1fr;
|
||||
}
|
||||
.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;
|
||||
.modal-button:hover {
|
||||
filter: brightness(0.9);
|
||||
}
|
||||
@@ -5,7 +5,7 @@ import './Modal.css'
|
||||
|
||||
const modalRoot = document.getElementById('modal')
|
||||
|
||||
function Modal({ children }) {
|
||||
function Modal({ children, title, content, buttons }) {
|
||||
const elRef = useRef(null)
|
||||
if (!elRef.current) {
|
||||
elRef.current = document.createElement('div')
|
||||
@@ -15,7 +15,24 @@ function Modal({ children }) {
|
||||
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
|
||||
@@ -6,7 +6,6 @@ nav {
|
||||
padding: 0.5em;
|
||||
box-sizing: border-box;
|
||||
user-select: none;
|
||||
box-shadow: 0 0 12px 1px #0000002b, 0 -10px 20px 20px var(--light);
|
||||
z-index: 5;
|
||||
position: fixed;
|
||||
bottom: 0;
|
||||
|
||||
@@ -19,3 +19,10 @@
|
||||
margin: 1em;
|
||||
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 { useParams } from 'react-router-dom'
|
||||
import { useParams, useHistory } from 'react-router-dom'
|
||||
|
||||
import Track from '../Track/Track'
|
||||
import Track, { Tracklist } from '../Track/Track'
|
||||
import { getMultiple, search } from '../../Cache'
|
||||
|
||||
import './Search.css'
|
||||
@@ -12,7 +12,8 @@ function Search() {
|
||||
const { query } = useParams(),
|
||||
[results, setResults] = useState([]),
|
||||
[meta, setMeta] = useState(''),
|
||||
input = createRef()
|
||||
input = createRef(),
|
||||
history = useHistory()
|
||||
|
||||
function run(query) {
|
||||
query = query.trim()
|
||||
@@ -20,16 +21,18 @@ function Search() {
|
||||
|
||||
setMeta(`Wyszukiwanie...`)
|
||||
|
||||
history.replace(`/wyszukaj/${query}`)
|
||||
|
||||
search(query)
|
||||
.then(({ tracks, total }) => {
|
||||
getMultiple(tracks)
|
||||
.then((tracks) => {
|
||||
setResults(tracks)
|
||||
setMeta(`Znaleziono ${total} utworów`)
|
||||
})
|
||||
.catch((err) => {
|
||||
setMeta(`Wystąpił błąd podczas pobierania utworów`)
|
||||
})
|
||||
.then(({ tids, total, elapsed }) => {
|
||||
getMultiple(tids)
|
||||
setResults(tids)
|
||||
setMeta(
|
||||
`Znaleziono ${total} utworów (${(
|
||||
elapsed[0] +
|
||||
elapsed[1] / 1e9
|
||||
).toPrecision(2)}s)`
|
||||
)
|
||||
})
|
||||
.catch((err) => {
|
||||
setMeta(`Wystąpił błąd podczas wyszukiwania`)
|
||||
@@ -49,7 +52,7 @@ function Search() {
|
||||
}, []) // eslint-disable-line react-hooks/exhaustive-deps
|
||||
|
||||
return (
|
||||
<div className="wrapper search">
|
||||
<div className="wrapper search" data-results={results.length}>
|
||||
<h2>Wyszukaj utwór</h2>
|
||||
<input
|
||||
className="search-input"
|
||||
@@ -73,9 +76,11 @@ function Search() {
|
||||
{meta}
|
||||
</span>
|
||||
)}
|
||||
{results.map((track) => {
|
||||
return <Track key={track.id} track={track} />
|
||||
})}
|
||||
<Tracklist>
|
||||
{results.map((tid) => {
|
||||
return <Track key={tid} tid={tid} />
|
||||
})}
|
||||
</Tracklist>
|
||||
</div>
|
||||
</div>
|
||||
)
|
||||
|
||||
@@ -0,0 +1,71 @@
|
||||
.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;
|
||||
border-bottom: 1px solid var(--light);
|
||||
padding: 0.4em 0.2em;
|
||||
margin-bottom: 0.2em;
|
||||
text-decoration: none;
|
||||
color: inherit;
|
||||
}
|
||||
|
||||
.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,114 @@
|
||||
import { useContext, useState } from 'react'
|
||||
|
||||
import { promptLogin, credentials, clearCredentials } from '../../Auth'
|
||||
|
||||
import SettingsContext from '../../contexts/Settings'
|
||||
|
||||
import './Settings.css'
|
||||
|
||||
const defaults = {
|
||||
hueFromArt: true,
|
||||
}
|
||||
|
||||
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 })
|
||||
|
||||
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ć więcej niż na jeden utwór
|
||||
</div>
|
||||
)}
|
||||
|
||||
<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 {
|
||||
position: fixed;
|
||||
bottom: 3.5rem;
|
||||
left: 2.5%;
|
||||
left: 0;
|
||||
right: 0;
|
||||
width: 95%;
|
||||
background: var(--dark);
|
||||
color: var(--white);
|
||||
padding: 0.5em;
|
||||
border-radius: 0.5em;
|
||||
box-sizing: border-box;
|
||||
box-shadow: 0 2px 8px 1px #00000063;
|
||||
box-shadow: 0 2px 8px 1px #0006;
|
||||
z-index: 10;
|
||||
text-decoration: none;
|
||||
max-width: 700px;
|
||||
margin: auto;
|
||||
transition: 0.4s cubic-bezier(1, 0, 0, 1);
|
||||
}
|
||||
|
||||
.status-image {
|
||||
@@ -25,6 +29,9 @@
|
||||
font-size: 1.1em;
|
||||
display: block;
|
||||
font-weight: bold;
|
||||
overflow: hidden;
|
||||
white-space: nowrap;
|
||||
text-overflow: ellipsis;
|
||||
}
|
||||
|
||||
.status-artist {
|
||||
@@ -47,7 +54,7 @@
|
||||
bottom: 0;
|
||||
border-bottom: 2px solid white;
|
||||
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 {
|
||||
@@ -61,6 +68,11 @@
|
||||
border-radius: 100%;
|
||||
}
|
||||
|
||||
.status.paused {
|
||||
transform: scaleX(0);
|
||||
opacity: 0;
|
||||
}
|
||||
|
||||
.status.paused > .status-progress {
|
||||
opacity: 0;
|
||||
}
|
||||
@@ -1,34 +1,43 @@
|
||||
import { useContext, useEffect, useState } from 'react'
|
||||
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 SettingsContext from '../../contexts/Settings'
|
||||
|
||||
import './Status.css'
|
||||
import def from '../../media/default.png'
|
||||
import { get } from '../../Cache'
|
||||
|
||||
function Status({ progress, paused }) {
|
||||
const {
|
||||
id,
|
||||
title = '-',
|
||||
artists = ['-'],
|
||||
album = {},
|
||||
duration,
|
||||
} = useContext(PlayingContext),
|
||||
[elapsed, setElapsed] = useState()
|
||||
function Status({ progress: [progress, duration], paused }) {
|
||||
const { tid } = useContext(PlayingContext),
|
||||
{ settings } = useContext(SettingsContext)
|
||||
|
||||
const step = 500,
|
||||
tread = step / duration
|
||||
const [elapsed, setElapsed] = useState(),
|
||||
[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(() => {
|
||||
if (album.art) setColor(album.art, 1)
|
||||
}, [album.art])
|
||||
if (!settings.hueFromArt) setDefault()
|
||||
else if (track?.album?.art) setColor(track?.album?.art[1]?.url, 1)
|
||||
}, [track?.album?.art, settings.hueFromArt])
|
||||
|
||||
// update progress on track change
|
||||
useEffect(() => {
|
||||
setElapsed(progress ? progress / duration : 0)
|
||||
}, [progress, duration])
|
||||
}, [progress, duration, tid])
|
||||
|
||||
// animate progress bar
|
||||
useEffect(
|
||||
(anim) => {
|
||||
if (!paused) {
|
||||
@@ -50,13 +59,25 @@ function Status({ progress, paused }) {
|
||||
|
||||
return (
|
||||
<Link
|
||||
className={['status', paused ? 'paused' : ''].join(' ')}
|
||||
to={`/utwor/${id}`}
|
||||
className={['status', paused || !tid ? 'paused' : ''].join(' ')}
|
||||
to={`/utwor/${tid}`}
|
||||
>
|
||||
<img className="status-image" alt="album cover" src={album.art ?? def} />
|
||||
<span className="status-track">{title}</span>
|
||||
<span className="status-artist">{artists.join(', ')}</span>
|
||||
<i className="icon-info"></i>
|
||||
<img
|
||||
className="status-image"
|
||||
alt="album cover"
|
||||
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
|
||||
className="status-progress"
|
||||
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'
|
||||
|
||||
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 (
|
||||
<div className="wrapper top">
|
||||
{props.tracks.map((track, rank) => {
|
||||
return <Track key={track.id} rank={rank + 1} track={track} />
|
||||
})}
|
||||
<span className="top-header">
|
||||
TOP: {weekName} {timestamp ? day : '-'}
|
||||
</span>
|
||||
|
||||
<Tracklist>
|
||||
{tracks.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>
|
||||
)
|
||||
}
|
||||
|
||||
@@ -50,6 +50,14 @@
|
||||
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 {
|
||||
content: '#';
|
||||
}
|
||||
@@ -61,14 +69,14 @@
|
||||
}
|
||||
|
||||
.track-title {
|
||||
padding: 0px 10px;
|
||||
margin: 0px 10px;
|
||||
font-weight: bold;
|
||||
text-decoration: none;
|
||||
color: inherit;
|
||||
}
|
||||
|
||||
.track-artist {
|
||||
padding: 0px 10px;
|
||||
margin: 0px 10px;
|
||||
color: #333;
|
||||
}
|
||||
|
||||
@@ -89,15 +97,15 @@
|
||||
left: 100%;
|
||||
top: 0;
|
||||
border-radius: inherit;
|
||||
background: hsl(12deg, 4%, 20%);
|
||||
transition: 0.3s cubic-bezier(0.7, 0, 0.3, 1);
|
||||
|
||||
display: flex;
|
||||
flex-direction: row;
|
||||
color: #fff;
|
||||
padding: 0.5em;
|
||||
box-sizing: border-box;
|
||||
justify-content: space-around;
|
||||
backdrop-filter: blur(1px);
|
||||
background-color: hsla(var(--deg), 35%, 22%, 71%);
|
||||
}
|
||||
|
||||
.track.open > .track-more {
|
||||
@@ -116,15 +124,17 @@
|
||||
|
||||
.track-more-button > i {
|
||||
width: 100%;
|
||||
border-radius: 1em;
|
||||
margin: 0 0.5em;
|
||||
}
|
||||
|
||||
.track-more-button > i[data-set='true'] {
|
||||
.track-more-button[data-set='true'] > i {
|
||||
background-color: var(--dark);
|
||||
color: var(--main);
|
||||
cursor: default;
|
||||
}
|
||||
|
||||
.track-more-button:hover {
|
||||
.track-more-button:not([data-set='true']):hover > i {
|
||||
background-color: #fff2;
|
||||
}
|
||||
|
||||
|
||||
@@ -1,84 +1,135 @@
|
||||
import { useState } from 'react'
|
||||
import { useState, createContext, useContext } from 'react'
|
||||
import { Link, useHistory } from 'react-router-dom'
|
||||
|
||||
import { credentials } from '../../Auth'
|
||||
import { get } from '../../Cache'
|
||||
|
||||
import ModalLoginContext from '../../contexts/ModalLogin'
|
||||
|
||||
import './Track.css'
|
||||
import './loading.css'
|
||||
|
||||
import def from '../../media/default.png'
|
||||
|
||||
function Track({ track, timestamp, rank }) {
|
||||
const [open, setOpen] = useState(false),
|
||||
{
|
||||
id,
|
||||
title = '-',
|
||||
artists = ['-'],
|
||||
album = {},
|
||||
votes = {},
|
||||
cast = '',
|
||||
} = track ?? {},
|
||||
history = useHistory()
|
||||
const TracklistContext = createContext({})
|
||||
|
||||
function Tracklist({ children }) {
|
||||
const [active, setActive] = useState(''),
|
||||
value = { active, setActive }
|
||||
|
||||
return (
|
||||
<TracklistContext.Provider value={value}>
|
||||
{children}
|
||||
</TracklistContext.Provider>
|
||||
)
|
||||
}
|
||||
|
||||
function Track({ 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) {
|
||||
if (!credentials.token) return setModalLogin(true)
|
||||
|
||||
track
|
||||
.setVote(value)
|
||||
.then((ok) => ok && setOpen(false))
|
||||
.catch((err) => console.error(err))
|
||||
.then((ok) => ok && tracklist.setActive(false))
|
||||
.catch((err) => console.error(err)) // TODO: alert on error
|
||||
}
|
||||
|
||||
function info() {
|
||||
history.push(`/utwor/${id}`)
|
||||
history.push(`/utwor/${tid}`)
|
||||
}
|
||||
|
||||
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
|
||||
className={'track-section-a ' + (timestamp || rank ? '' : 'empty')}
|
||||
onClick={() => info()}
|
||||
>
|
||||
{timestamp && <span className="track-timestamp">{timestamp}</span>}
|
||||
{rank && <span className="track-rank">{rank}</span>}
|
||||
<img className="track-image" src={album.art ?? def} alt="album cover" />
|
||||
{rank && (
|
||||
<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 className="track-section-b" onClick={() => info()}>
|
||||
<span className="track-title">{title}</span>
|
||||
<span className="track-artist">{artists.join(', ')}</span>
|
||||
{track instanceof Error ? (
|
||||
<>
|
||||
<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 className="track-icons">
|
||||
<i
|
||||
className="icon-ellipsis-vert"
|
||||
onClick={() => {
|
||||
setOpen(true)
|
||||
}}
|
||||
onClick={() => tracklist.setActive(tid)}
|
||||
></i>
|
||||
</div>
|
||||
|
||||
<div className="track-more">
|
||||
<div className="track-more-button">
|
||||
<i
|
||||
className="icon-thumbs-up"
|
||||
data-set={cast === 'up'}
|
||||
onClick={(e) => vote('up')}
|
||||
></i>
|
||||
<div
|
||||
className="track-more-button"
|
||||
data-set={track.stats?.cast === 'up'}
|
||||
onClick={(e) => vote('up')}
|
||||
>
|
||||
<i className="icon-thumbs-up"></i>
|
||||
</div>
|
||||
|
||||
<div className="track-more-button">
|
||||
<i
|
||||
className="icon-thumbs-down"
|
||||
data-set={cast === 'down'}
|
||||
onClick={(e) => vote('down')}
|
||||
></i>
|
||||
<div
|
||||
className="track-more-button"
|
||||
data-set={track.stats?.cast === 'down'}
|
||||
onClick={(e) => vote('down')}
|
||||
>
|
||||
<i className="icon-thumbs-down"></i>
|
||||
</div>
|
||||
|
||||
<Link to={`/utwor/${id}`} className="track-more-button">
|
||||
<Link to={`/utwor/${tid}`} className="track-more-button">
|
||||
<i className="icon-info"></i>
|
||||
</Link>
|
||||
|
||||
<div className="track-more-button">
|
||||
<i
|
||||
className="icon-cancel-circled"
|
||||
onClick={() => {
|
||||
setOpen(false)
|
||||
}}
|
||||
></i>
|
||||
<div
|
||||
className="track-more-button"
|
||||
onClick={() => {
|
||||
tracklist.setActive(false)
|
||||
}}
|
||||
>
|
||||
<i className="icon-cancel-circled"></i>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
@@ -86,3 +137,4 @@ function Track({ track, timestamp, rank }) {
|
||||
}
|
||||
|
||||
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;
|
||||
-webkit-font-smoothing: antialiased;
|
||||
-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 {
|
||||
@@ -14,3 +25,18 @@ body {
|
||||
--main: hsl(var(--deg), 57%, 52%);
|
||||
--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
|
||||
// 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
|
||||
reportWebVitals()
|
||||
Binary file not shown.
|
After Width: | Height: | Size: 13 KiB |
+5
-1
@@ -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`)
|
||||
|
||||
Reference in new issue
Block a user