feat: auth
This commit is contained in:
1 parent
38407959a6
commit
94d10d52cf
18 files changed
+483
-47
No files matched your search
Generated
+96
@@ -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",
|
||||
@@ -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",
|
||||
|
||||
+3
-1
@@ -8,7 +8,9 @@
|
||||
"@testing-library/react": "^11.2.7",
|
||||
"@testing-library/user-event": "^12.8.3",
|
||||
"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 +43,4 @@
|
||||
"last 1 safari version"
|
||||
]
|
||||
}
|
||||
}
|
||||
}
|
||||
+1
-1
@@ -14,7 +14,7 @@
|
||||
<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 -->
|
||||
|
||||
Binary file not shown.
|
After Width: | Height: | Size: 6.0 KiB |
Binary file not shown.
|
After Width: | Height: | Size: 13 KiB |
@@ -0,0 +1 @@
|
||||
polityka prywatności
|
||||
@@ -0,0 +1 @@
|
||||
terms of service
|
||||
+50
@@ -0,0 +1,50 @@
|
||||
import Jwt from 'jsonwebtoken'
|
||||
import localStorage from 'local-storage'
|
||||
|
||||
const appId = '299948451430584',
|
||||
redirectUri = `https://radio.rolniknysa.pl/api/login/token`,
|
||||
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`
|
||||
)
|
||||
window.exit = ({ jwt }) => {
|
||||
popup.close()
|
||||
|
||||
credentials = {
|
||||
token: jwt,
|
||||
udata: Jwt.decode(jwt),
|
||||
}
|
||||
|
||||
localStorage('token', credentials.token)
|
||||
localStorage('udata', credentials.udata)
|
||||
|
||||
resolve(credentials)
|
||||
}
|
||||
})
|
||||
}
|
||||
|
||||
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
-21
@@ -1,37 +1,67 @@
|
||||
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 {String} tdata.album.art album art url
|
||||
* @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,
|
||||
rank: -1,
|
||||
cast: '',
|
||||
}
|
||||
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,12 +70,22 @@ 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) => {
|
||||
@@ -54,6 +94,10 @@ class Track {
|
||||
})
|
||||
}
|
||||
|
||||
/**
|
||||
* Update Track's stats
|
||||
* @returns {Promise} stats object
|
||||
*/
|
||||
getStats() {
|
||||
return new Promise((resolve, reject) => {
|
||||
getStats(this.id)
|
||||
@@ -68,9 +112,16 @@ class Track {
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 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 +130,90 @@ 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') {
|
||||
if (typeof Tracks[id] === 'undefined') {
|
||||
download(id)
|
||||
.then((track) => resolve(track))
|
||||
.catch((err) => reject(err))
|
||||
} else resolve(tracks[id])
|
||||
} else resolve(Tracks[id])
|
||||
})
|
||||
}
|
||||
|
||||
function getMultiple(ids) {
|
||||
/**
|
||||
* Get multiple Tracks
|
||||
* @param {Array} ids Array of track ids
|
||||
* @returns {Array} Array of Tracks
|
||||
*/
|
||||
function getMultiple(ids = []) {
|
||||
return new Promise((resolve, reject) => {
|
||||
Promise.all(ids.map((id) => get(id)))
|
||||
.then((tracks) => resolve(tracks))
|
||||
.catch((err) => {
|
||||
console.error(err)
|
||||
let missing = ids.filter((id) => !Tracks[id]) // filter tracks missing from cache
|
||||
|
||||
// if none are missing, resolve from cache
|
||||
if (missing.length < 1) return resolve(ids.map((id) => Tracks[id]))
|
||||
else {
|
||||
// fetch missing tracks
|
||||
downloadMultiple(ids).then((tracks) => {
|
||||
tracks.map((track) => (Tracks[track.id] = track)) // add to cache
|
||||
return resolve(ids.map((id) => Tracks[id])) // resolve from cache
|
||||
})
|
||||
}
|
||||
})
|
||||
}
|
||||
|
||||
function getMultipleStats(tids) {
|
||||
return new Promise((resolve, reject) => {
|
||||
ky.post('/api/vote/batch', {
|
||||
json: { tids },
|
||||
headers: { authorization: credentials.token },
|
||||
})
|
||||
.json()
|
||||
.then((stats) => {
|
||||
resolve(stats)
|
||||
})
|
||||
})
|
||||
}
|
||||
|
||||
/**
|
||||
* 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])
|
||||
Tracks[track.id] = new Track(track)
|
||||
resolve(Tracks[track.id])
|
||||
})
|
||||
.catch((err) => reject(err))
|
||||
})
|
||||
}
|
||||
|
||||
function downloadMultiple(tids) {
|
||||
return new Promise((resolve, reject) => {
|
||||
ky.post('/api/track/batch', {
|
||||
json: { tids },
|
||||
})
|
||||
.json()
|
||||
.then((tracks) => {
|
||||
resolve(tracks.map((tdata) => new Track(tdata)))
|
||||
})
|
||||
.catch((err) => {})
|
||||
})
|
||||
}
|
||||
|
||||
/**
|
||||
* 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 +223,11 @@ function search(query) {
|
||||
})
|
||||
}
|
||||
|
||||
export { tracks, get, getMultiple, search, getStats }
|
||||
export {
|
||||
Tracks as tracks,
|
||||
get,
|
||||
getMultiple,
|
||||
getMultipleStats,
|
||||
search,
|
||||
getStats,
|
||||
}
|
||||
@@ -31,13 +31,8 @@ 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) => console.error(err))
|
||||
})
|
||||
@@ -100,12 +95,12 @@ function Info() {
|
||||
<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>
|
||||
|
||||
@@ -1,7 +1,7 @@
|
||||
@import url('https://fonts.googleapis.com/css2?family=Quicksand&family=Poppins');
|
||||
|
||||
.main {
|
||||
height: 100vh;
|
||||
height: 100%;
|
||||
justify-content: flex-end;
|
||||
font-family: 'Quicksand';
|
||||
overflow: hidden auto;
|
||||
|
||||
@@ -13,8 +13,9 @@ import Status from '../Status/Status'
|
||||
import Info from '../Info/Info'
|
||||
import Top from '../Top/Top'
|
||||
import Search from '../Search/Search'
|
||||
import Settings from '../Settings/Settings'
|
||||
|
||||
import { get, getMultiple } from '../../Cache'
|
||||
import { get, getMultiple, getMultipleStats } from '../../Cache'
|
||||
import { addEvent } from '../../socket'
|
||||
|
||||
import PlayingContext from '../../contexts/Playing'
|
||||
@@ -41,7 +42,8 @@ function Main() {
|
||||
[paused, setPaused] = useState(true),
|
||||
[next, setNext] = useState(),
|
||||
[previous, setPrevious] = useState([]),
|
||||
[top, setTop] = useState([])
|
||||
[top, setTop] = useState([]),
|
||||
[topDate, setTopDate] = useState()
|
||||
|
||||
useEffect(() => {
|
||||
addEvent('status', ({ trackid, progress, paused }) => {
|
||||
@@ -74,10 +76,26 @@ function Main() {
|
||||
.catch((err) => console.error(err))
|
||||
})
|
||||
|
||||
addEvent('top', ({ trackids }) => {
|
||||
getMultiple(trackids)
|
||||
.then((tracks) => setTop(tracks))
|
||||
.catch((err) => console.error(err))
|
||||
addEvent('top', ({ trackids, timestamp }) => {
|
||||
Promise.all([getMultiple(trackids), getMultipleStats(trackids)]).then(
|
||||
([tracks, stats]) => {
|
||||
tracks.map((track, i) => (track.stats = stats[i]))
|
||||
setTop(tracks)
|
||||
setTopDate(new Date(timestamp))
|
||||
}
|
||||
)
|
||||
// getMultiple(trackids)
|
||||
// .then((tracks) => {
|
||||
// Promise.all(tracks.map((track) => track.getStats()))
|
||||
// .then(() => {
|
||||
// setTop(tracks)
|
||||
// setTopDate(new Date(timestamp))
|
||||
// })
|
||||
// .catch((err) => {
|
||||
// console.error(err)
|
||||
// })
|
||||
// })
|
||||
// .catch((err) => console.error(err))
|
||||
})
|
||||
}, [])
|
||||
|
||||
@@ -96,13 +114,17 @@ function Main() {
|
||||
</Route>
|
||||
|
||||
<Route path="/top">
|
||||
<Top tracks={top} />
|
||||
<Top tracks={top} timestamp={topDate} />
|
||||
</Route>
|
||||
|
||||
<Route path="/wyszukaj/:query?">
|
||||
<Search />
|
||||
</Route>
|
||||
|
||||
<Route path="/ustawienia">
|
||||
<Settings />
|
||||
</Route>
|
||||
|
||||
<Route render={() => <Redirect to="/" />} />
|
||||
</Switch>
|
||||
<Nav
|
||||
|
||||
@@ -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-toggle {
|
||||
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;
|
||||
cursor: pointer;
|
||||
}
|
||||
|
||||
.settings-toggle i {
|
||||
color: var(--dark);
|
||||
}
|
||||
|
||||
.settings-toggle[data-value='true'] i {
|
||||
color: var(--main);
|
||||
}
|
||||
|
||||
.settings-toggle:hover {
|
||||
color: var(--main);
|
||||
}
|
||||
|
||||
.toggle {
|
||||
font-size: 1.2em;
|
||||
cursor: pointer;
|
||||
}
|
||||
@@ -0,0 +1,82 @@
|
||||
import { useState } from 'react/cjs/react.development'
|
||||
import { promptLogin, credentials, clearCredentials } from '../../Auth'
|
||||
|
||||
import './Settings.css'
|
||||
|
||||
function Toggle({ value }) {
|
||||
return (
|
||||
<div className="toggle">
|
||||
<i className={`icon-toggle-${value ? 'on' : 'off'}`}></i>
|
||||
</div>
|
||||
)
|
||||
}
|
||||
|
||||
function SettingToggle({ children, defaultValue }) {
|
||||
const [value, setValue] = useState(defaultValue ?? false)
|
||||
return (
|
||||
<div
|
||||
className="settings-toggle"
|
||||
data-value={value}
|
||||
onClick={() => setValue((value) => !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">
|
||||
<strong>Zaloguj się</strong> aby móc głosować więcej niż na jeden
|
||||
utwór
|
||||
</div>
|
||||
)}
|
||||
|
||||
<div className="settings-part">
|
||||
<SettingToggle defaultValue={false}>
|
||||
Ustawiaj kolorystyke strony na podstawie okładki albumu
|
||||
</SettingToggle>
|
||||
<SettingToggle>Lorem ipsum dolor sit amet</SettingToggle>
|
||||
</div>
|
||||
|
||||
{/* Terms of Service and other usefull links */}
|
||||
<div className="settings-part">
|
||||
<a href="/tos.html" target="_blank" className="settings-toggle">
|
||||
Regulamin korzystania ze strony <i className="icon-export"></i>
|
||||
</a>
|
||||
<a href="/privacy.html" target="_blank" className="settings-toggle">
|
||||
Zasady prywatności (RODO) <i className="icon-export"></i>
|
||||
</a>
|
||||
</div>
|
||||
</div>
|
||||
)
|
||||
}
|
||||
|
||||
export default Settings
|
||||
@@ -4,9 +4,15 @@ import './Top.css'
|
||||
|
||||
function Top({ tracks, timestamp }) {
|
||||
const date = timestamp ?? new Date(),
|
||||
weekName = ['Poniedziak', 'Wtorek', 'Środa', 'Czwartek', 'Piątek'][
|
||||
date.getDay()
|
||||
],
|
||||
weekName = [
|
||||
'Niedziela',
|
||||
'Poniedziałek',
|
||||
'Wtorek',
|
||||
'Środa',
|
||||
'Czwartek',
|
||||
'Piątek',
|
||||
'Sobota',
|
||||
][date.getDay()],
|
||||
day = date.toLocaleString('pl-PL')
|
||||
|
||||
return (
|
||||
|
||||
@@ -23,7 +23,6 @@ function Track({ track, timestamp, displayRank = false }) {
|
||||
title = '-',
|
||||
artists = ['-'],
|
||||
album = {},
|
||||
cast = '',
|
||||
stats = {},
|
||||
} = track ?? {},
|
||||
history = useHistory(),
|
||||
@@ -70,11 +69,11 @@ function Track({ track, timestamp, displayRank = false }) {
|
||||
></i>
|
||||
</div>
|
||||
<div className="track-more">
|
||||
<div className="track-more-button" data-set={cast === 'up'}>
|
||||
<div className="track-more-button" data-set={stats.cast === 'up'}>
|
||||
<i className="icon-thumbs-up" onClick={(e) => vote('up')}></i>
|
||||
</div>
|
||||
|
||||
<div className="track-more-button" data-set={cast === 'down'}>
|
||||
<div className="track-more-button" data-set={stats.cast === 'down'}>
|
||||
<i className="icon-thumbs-down" onClick={(e) => vote('down')}></i>
|
||||
</div>
|
||||
|
||||
|
||||
@@ -15,6 +15,7 @@ body {
|
||||
|
||||
#root {
|
||||
backdrop-filter: blur(6px);
|
||||
height: 100vh;
|
||||
}
|
||||
|
||||
:root {
|
||||
|
||||
+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()
|
||||
Reference in new issue
Block a user