mirror of
https://github.com/navidrome/navidrome.git
synced 2025-06-18 16:03:19 +03:00
Clear play queue on login and logout
This commit is contained in:
parent
9d23b191b5
commit
804d969427
@ -4,7 +4,7 @@ import { createHashHistory } from 'history'
|
|||||||
import { Admin, Resource } from 'react-admin'
|
import { Admin, Resource } from 'react-admin'
|
||||||
import dataProvider from './dataProvider'
|
import dataProvider from './dataProvider'
|
||||||
import authProvider from './authProvider'
|
import authProvider from './authProvider'
|
||||||
import { Layout, Login } from './layout'
|
import { Layout, Login, Logout } from './layout'
|
||||||
import transcoding from './transcoding'
|
import transcoding from './transcoding'
|
||||||
import player from './player'
|
import player from './player'
|
||||||
import user from './user'
|
import user from './user'
|
||||||
@ -44,6 +44,7 @@ const App = () => (
|
|||||||
history={history}
|
history={history}
|
||||||
layout={Layout}
|
layout={Layout}
|
||||||
loginPage={Login}
|
loginPage={Login}
|
||||||
|
logoutButton={Logout}
|
||||||
>
|
>
|
||||||
{(permissions) => [
|
{(permissions) => [
|
||||||
<Resource name="album" {...album} options={{ subMenu: 'library' }} />,
|
<Resource name="album" {...album} options={{ subMenu: 'library' }} />,
|
||||||
|
@ -5,6 +5,7 @@ import {
|
|||||||
playQueueReducer,
|
playQueueReducer,
|
||||||
playTracks,
|
playTracks,
|
||||||
shuffleTracks,
|
shuffleTracks,
|
||||||
|
clearQueue,
|
||||||
} from './queue'
|
} from './queue'
|
||||||
|
|
||||||
export {
|
export {
|
||||||
@ -14,4 +15,5 @@ export {
|
|||||||
playTracks,
|
playTracks,
|
||||||
playQueueReducer,
|
playQueueReducer,
|
||||||
shuffleTracks,
|
shuffleTracks,
|
||||||
|
clearQueue,
|
||||||
}
|
}
|
||||||
|
@ -4,6 +4,7 @@ import subsonic from '../subsonic'
|
|||||||
const PLAYER_ADD_TRACKS = 'PLAYER_ADD_TRACKS'
|
const PLAYER_ADD_TRACKS = 'PLAYER_ADD_TRACKS'
|
||||||
const PLAYER_SET_TRACK = 'PLAYER_SET_TRACK'
|
const PLAYER_SET_TRACK = 'PLAYER_SET_TRACK'
|
||||||
const PLAYER_SYNC_QUEUE = 'PLAYER_SYNC_QUEUE'
|
const PLAYER_SYNC_QUEUE = 'PLAYER_SYNC_QUEUE'
|
||||||
|
const PLAYER_CLEAR_QUEUE = 'PLAYER_CLEAR_QUEUE'
|
||||||
const PLAYER_SCROBBLE = 'PLAYER_SCROBBLE'
|
const PLAYER_SCROBBLE = 'PLAYER_SCROBBLE'
|
||||||
const PLAYER_PLAY_TRACKS = 'PLAYER_PLAY_TRACKS'
|
const PLAYER_PLAY_TRACKS = 'PLAYER_PLAY_TRACKS'
|
||||||
const PLAYER_CURRENT = 'PLAYER_CURRENT'
|
const PLAYER_CURRENT = 'PLAYER_CURRENT'
|
||||||
@ -83,6 +84,10 @@ const syncQueue = (id, data) => ({
|
|||||||
data,
|
data,
|
||||||
})
|
})
|
||||||
|
|
||||||
|
const clearQueue = () => ({
|
||||||
|
type: PLAYER_CLEAR_QUEUE,
|
||||||
|
})
|
||||||
|
|
||||||
const scrobble = (id, submit) => ({
|
const scrobble = (id, submit) => ({
|
||||||
type: PLAYER_SCROBBLE,
|
type: PLAYER_SCROBBLE,
|
||||||
id,
|
id,
|
||||||
@ -94,13 +99,14 @@ const currentPlaying = (audioInfo) => ({
|
|||||||
data: audioInfo,
|
data: audioInfo,
|
||||||
})
|
})
|
||||||
|
|
||||||
const playQueueReducer = (
|
const initialState = { queue: [], clear: true, playing: false, current: {} }
|
||||||
previousState = { queue: [], clear: true, playing: false, current: {} },
|
|
||||||
payload
|
const playQueueReducer = (previousState = initialState, payload) => {
|
||||||
) => {
|
|
||||||
let queue, current
|
let queue, current
|
||||||
const { type, data } = payload
|
const { type, data } = payload
|
||||||
switch (type) {
|
switch (type) {
|
||||||
|
case PLAYER_CLEAR_QUEUE:
|
||||||
|
return initialState
|
||||||
case PLAYER_CURRENT:
|
case PLAYER_CURRENT:
|
||||||
queue = previousState.queue
|
queue = previousState.queue
|
||||||
current = data.ended
|
current = data.ended
|
||||||
@ -175,6 +181,7 @@ export {
|
|||||||
setTrack,
|
setTrack,
|
||||||
playTracks,
|
playTracks,
|
||||||
syncQueue,
|
syncQueue,
|
||||||
|
clearQueue,
|
||||||
scrobble,
|
scrobble,
|
||||||
currentPlaying,
|
currentPlaying,
|
||||||
shuffleTracks,
|
shuffleTracks,
|
||||||
|
@ -1,7 +1,9 @@
|
|||||||
import React, { useState } from 'react'
|
import React, { useState, useCallback } from 'react'
|
||||||
import PropTypes from 'prop-types'
|
import PropTypes from 'prop-types'
|
||||||
import { Field, Form } from 'react-final-form'
|
import { Field, Form } from 'react-final-form'
|
||||||
|
|
||||||
|
import { useDispatch } from 'react-redux'
|
||||||
|
|
||||||
import Avatar from '@material-ui/core/Avatar'
|
import Avatar from '@material-ui/core/Avatar'
|
||||||
import Button from '@material-ui/core/Button'
|
import Button from '@material-ui/core/Button'
|
||||||
import Card from '@material-ui/core/Card'
|
import Card from '@material-ui/core/Card'
|
||||||
@ -16,6 +18,7 @@ import { Notification, useLogin, useNotify, useTranslate } from 'react-admin'
|
|||||||
|
|
||||||
import LightTheme from '../themes/light'
|
import LightTheme from '../themes/light'
|
||||||
import config from '../config'
|
import config from '../config'
|
||||||
|
import { clearQueue } from '../audioplayer'
|
||||||
|
|
||||||
const useStyles = makeStyles((theme) => ({
|
const useStyles = makeStyles((theme) => ({
|
||||||
main: {
|
main: {
|
||||||
@ -210,9 +213,12 @@ const Login = ({ location }) => {
|
|||||||
const translate = useTranslate()
|
const translate = useTranslate()
|
||||||
const notify = useNotify()
|
const notify = useNotify()
|
||||||
const login = useLogin()
|
const login = useLogin()
|
||||||
|
const dispatch = useDispatch()
|
||||||
|
|
||||||
const handleSubmit = (auth) => {
|
const handleSubmit = useCallback(
|
||||||
|
(auth) => {
|
||||||
setLoading(true)
|
setLoading(true)
|
||||||
|
dispatch(clearQueue())
|
||||||
login(auth, location.state ? location.state.nextPathname : '/').catch(
|
login(auth, location.state ? location.state.nextPathname : '/').catch(
|
||||||
(error) => {
|
(error) => {
|
||||||
setLoading(false)
|
setLoading(false)
|
||||||
@ -226,9 +232,12 @@ const Login = ({ location }) => {
|
|||||||
)
|
)
|
||||||
}
|
}
|
||||||
)
|
)
|
||||||
}
|
},
|
||||||
|
[dispatch, login, notify, setLoading, location]
|
||||||
|
)
|
||||||
|
|
||||||
const validateLogin = (values) => {
|
const validateLogin = useCallback(
|
||||||
|
(values) => {
|
||||||
const errors = {}
|
const errors = {}
|
||||||
if (!values.username) {
|
if (!values.username) {
|
||||||
errors.username = translate('ra.validation.required')
|
errors.username = translate('ra.validation.required')
|
||||||
@ -237,9 +246,12 @@ const Login = ({ location }) => {
|
|||||||
errors.password = translate('ra.validation.required')
|
errors.password = translate('ra.validation.required')
|
||||||
}
|
}
|
||||||
return errors
|
return errors
|
||||||
}
|
},
|
||||||
|
[translate]
|
||||||
|
)
|
||||||
|
|
||||||
const validateSignup = (values) => {
|
const validateSignup = useCallback(
|
||||||
|
(values) => {
|
||||||
const errors = validateLogin(values)
|
const errors = validateLogin(values)
|
||||||
const regex = /^\w+$/g
|
const regex = /^\w+$/g
|
||||||
if (values.username && !values.username.match(regex)) {
|
if (values.username && !values.username.match(regex)) {
|
||||||
@ -252,7 +264,9 @@ const Login = ({ location }) => {
|
|||||||
errors.confirmPassword = translate('ra.validation.passwordDoesNotMatch')
|
errors.confirmPassword = translate('ra.validation.passwordDoesNotMatch')
|
||||||
}
|
}
|
||||||
return errors
|
return errors
|
||||||
}
|
},
|
||||||
|
[translate, validateLogin]
|
||||||
|
)
|
||||||
|
|
||||||
if (config.firstTime) {
|
if (config.firstTime) {
|
||||||
return (
|
return (
|
||||||
|
15
ui/src/layout/Logout.js
Normal file
15
ui/src/layout/Logout.js
Normal file
@ -0,0 +1,15 @@
|
|||||||
|
import React, { useCallback } from 'react'
|
||||||
|
import { useDispatch } from 'react-redux'
|
||||||
|
import { Logout } from 'react-admin'
|
||||||
|
import { clearQueue } from '../audioplayer'
|
||||||
|
|
||||||
|
export default (props) => {
|
||||||
|
const dispatch = useDispatch()
|
||||||
|
const handleClick = useCallback(() => dispatch(clearQueue()), [dispatch])
|
||||||
|
|
||||||
|
return (
|
||||||
|
<span onClick={handleClick}>
|
||||||
|
<Logout {...props} />
|
||||||
|
</span>
|
||||||
|
)
|
||||||
|
}
|
@ -1,4 +1,5 @@
|
|||||||
import Login from './Login'
|
import Login from './Login'
|
||||||
|
import Logout from './Logout'
|
||||||
import Layout from './Layout'
|
import Layout from './Layout'
|
||||||
|
|
||||||
export { Layout, Login }
|
export { Layout, Login, Logout }
|
||||||
|
Loading…
x
Reference in New Issue
Block a user