fix: login issues,
feat: tools for moderation
This commit is contained in:
1 parent
ba8bbf45ac
commit
836cd10f77
6 files changed
+47
-35
No files matched your search
@@ -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
|
||||
+4
-3
@@ -1,4 +1,3 @@
|
||||
import Jwt from 'jsonwebtoken'
|
||||
import localStorage from 'local-storage'
|
||||
|
||||
const appId = '299948451430584',
|
||||
@@ -20,10 +19,12 @@ function promptLogin() {
|
||||
|
||||
let interval = setInterval(() => {
|
||||
if (popup.closed) {
|
||||
resolve({
|
||||
credentials = {
|
||||
token: localStorage('token'),
|
||||
udata: localStorage('udata'),
|
||||
})
|
||||
}
|
||||
|
||||
resolve(credentials)
|
||||
clearInterval(interval)
|
||||
}
|
||||
}, 500)
|
||||
|
||||
@@ -34,7 +34,13 @@ function History({ next, tracks, paused }) {
|
||||
? new Date(track.timestamp).toISOString().slice(11, 16)
|
||||
: '-:-'
|
||||
|
||||
return <Track key={track.id} track={track} timestamp={time} />
|
||||
return (
|
||||
<Track
|
||||
key={track.id + '_' + track.timestamp}
|
||||
track={track}
|
||||
timestamp={time}
|
||||
/>
|
||||
)
|
||||
})}
|
||||
|
||||
{tracks.length < 1 && (
|
||||
|
||||
@@ -11,6 +11,7 @@ import ModalLoginContext from '../../contexts/ModalLogin'
|
||||
|
||||
import './Info.css'
|
||||
import def from '../../media/default.png'
|
||||
import admin from '../../Admin'
|
||||
|
||||
var last
|
||||
|
||||
@@ -153,6 +154,17 @@ function Info() {
|
||||
></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>
|
||||
|
||||
@@ -4,7 +4,7 @@ import {
|
||||
Route,
|
||||
Redirect,
|
||||
} from 'react-router-dom'
|
||||
import { useEffect, useRef, useState } from 'react'
|
||||
import { useEffect, useState } from 'react'
|
||||
import ga from 'react-ga'
|
||||
import localStorage from 'local-storage'
|
||||
|
||||
@@ -41,14 +41,6 @@ document.setTitle = (prefix, suffix) => {
|
||||
ga.pageview(document.location.pathname)
|
||||
}
|
||||
|
||||
function usePrevious(value) {
|
||||
const ref = useRef()
|
||||
useEffect(() => {
|
||||
ref.current = value
|
||||
})
|
||||
return ref.current
|
||||
}
|
||||
|
||||
function Main() {
|
||||
const [playing, setPlaying] = useState({}),
|
||||
[elapsed, setElapsed] = useState([0, 0]),
|
||||
@@ -58,31 +50,16 @@ function Main() {
|
||||
[top, setTop] = useState([]),
|
||||
[topDate, setTopDate] = useState(),
|
||||
[modalLogin, setModalLogin] = useState(false),
|
||||
[settings, setSettings] = useState(localStorage('settings') ?? defaults),
|
||||
prevPlaying = usePrevious(playing)
|
||||
|
||||
useEffect(() => {
|
||||
console.log('effect', prevPlaying?.id, playing?.id)
|
||||
if (prevPlaying?.id !== playing?.id) {
|
||||
if (prevPlaying?.id) {
|
||||
setPrevious((prev) => [prevPlaying, ...prev])
|
||||
}
|
||||
}
|
||||
// setPlaying((playing) => {
|
||||
// console.log(playing, track, playing.id != track.id)
|
||||
// if (playing.id != track.id) {
|
||||
// if (playing.id)
|
||||
// }
|
||||
// return track
|
||||
// })
|
||||
}, [prevPlaying, playing])
|
||||
[settings, setSettings] = useState(localStorage('settings') ?? defaults)
|
||||
|
||||
// set up socket events
|
||||
useEffect(() => {
|
||||
addEvent('status', ({ tid, progress, duration, paused, timestamp }) => {
|
||||
if (tid === null) return
|
||||
get(tid)
|
||||
.then((track) => {
|
||||
track.timestamp = timestamp // insert timestamp
|
||||
console.log('new status')
|
||||
console.info('status: update', tid)
|
||||
setPlaying(track)
|
||||
setElapsed([progress, duration])
|
||||
setPaused(paused)
|
||||
@@ -132,9 +109,9 @@ function Main() {
|
||||
})
|
||||
}, []) // eslint-disable-line
|
||||
|
||||
// save settings on change
|
||||
useEffect(() => {
|
||||
console.log('settings changed')
|
||||
console.log(settings)
|
||||
console.info('settings changed', settings)
|
||||
localStorage('settings', settings)
|
||||
}, [settings])
|
||||
|
||||
|
||||
@@ -13,7 +13,7 @@ function Top({ tracks, timestamp }) {
|
||||
'Piątek',
|
||||
'Sobota',
|
||||
][date.getDay()],
|
||||
day = date.toLocaleString('pl-PL')
|
||||
day = date.toLocaleTimeString('pl-PL')
|
||||
|
||||
return (
|
||||
<div className="wrapper top">
|
||||
|
||||
Reference in new issue
Block a user