Revert "Show indicator on current playing song. Fixes #128"
This implementation causes performance issues
This commit is contained in:
@@ -2,6 +2,7 @@ import React from 'react'
|
|||||||
import {
|
import {
|
||||||
BulkActionsToolbar,
|
BulkActionsToolbar,
|
||||||
DatagridLoading,
|
DatagridLoading,
|
||||||
|
FunctionField,
|
||||||
ListToolbar,
|
ListToolbar,
|
||||||
TextField,
|
TextField,
|
||||||
useListController,
|
useListController,
|
||||||
@@ -14,10 +15,9 @@ import StarBorderIcon from '@material-ui/icons/StarBorder'
|
|||||||
import { playTracks } from '../audioplayer'
|
import { playTracks } from '../audioplayer'
|
||||||
import {
|
import {
|
||||||
DurationField,
|
DurationField,
|
||||||
SongContextMenu,
|
|
||||||
SongDatagrid,
|
|
||||||
SongDetails,
|
SongDetails,
|
||||||
SongTitleField,
|
SongDatagrid,
|
||||||
|
SongContextMenu,
|
||||||
} from '../common'
|
} from '../common'
|
||||||
import AddToPlaylistDialog from '../dialogs/AddToPlaylistDialog'
|
import AddToPlaylistDialog from '../dialogs/AddToPlaylistDialog'
|
||||||
|
|
||||||
@@ -62,6 +62,14 @@ const useStylesListToolbar = makeStyles({
|
|||||||
},
|
},
|
||||||
})
|
})
|
||||||
|
|
||||||
|
const trackName = (r) => {
|
||||||
|
const name = r.title
|
||||||
|
if (r.trackNumber) {
|
||||||
|
return r.trackNumber.toString().padStart(2, '0') + ' ' + name
|
||||||
|
}
|
||||||
|
return name
|
||||||
|
}
|
||||||
|
|
||||||
const AlbumSongs = (props) => {
|
const AlbumSongs = (props) => {
|
||||||
const classes = useStyles(props)
|
const classes = useStyles(props)
|
||||||
const classesToolbar = useStylesListToolbar(props)
|
const classesToolbar = useStylesListToolbar(props)
|
||||||
@@ -124,11 +132,14 @@ const AlbumSongs = (props) => {
|
|||||||
sortable={false}
|
sortable={false}
|
||||||
/>
|
/>
|
||||||
)}
|
)}
|
||||||
<SongTitleField
|
{isDesktop && <TextField source="title" sortable={false} />}
|
||||||
|
{!isDesktop && (
|
||||||
|
<FunctionField
|
||||||
source="title"
|
source="title"
|
||||||
|
render={trackName}
|
||||||
sortable={false}
|
sortable={false}
|
||||||
showTrackNumbers={!isDesktop}
|
|
||||||
/>
|
/>
|
||||||
|
)}
|
||||||
{isDesktop && <TextField source="artist" sortable={false} />}
|
{isDesktop && <TextField source="artist" sortable={false} />}
|
||||||
<DurationField source="duration" sortable={false} />
|
<DurationField source="duration" sortable={false} />
|
||||||
<SongContextMenu
|
<SongContextMenu
|
||||||
|
|||||||
@@ -5,7 +5,7 @@ import { useAuthState, useDataProvider, useTranslate } from 'react-admin'
|
|||||||
import ReactJkMusicPlayer from 'react-jinke-music-player'
|
import ReactJkMusicPlayer from 'react-jinke-music-player'
|
||||||
import 'react-jinke-music-player/assets/index.css'
|
import 'react-jinke-music-player/assets/index.css'
|
||||||
import subsonic from '../subsonic'
|
import subsonic from '../subsonic'
|
||||||
import { scrobble, syncQueue, progress } from './queue'
|
import { scrobble, syncQueue } from './queue'
|
||||||
import themes from '../themes'
|
import themes from '../themes'
|
||||||
import { makeStyles } from '@material-ui/core/styles'
|
import { makeStyles } from '@material-ui/core/styles'
|
||||||
|
|
||||||
@@ -100,12 +100,8 @@ const Player = () => {
|
|||||||
}
|
}
|
||||||
|
|
||||||
const OnAudioProgress = (info) => {
|
const OnAudioProgress = (info) => {
|
||||||
if (info.ended) {
|
const progress = (info.currentTime / info.duration) * 100
|
||||||
document.title = 'Navidrome'
|
if (isNaN(info.duration) || progress < 90) {
|
||||||
}
|
|
||||||
dispatch(progress(info))
|
|
||||||
const pos = (info.currentTime / info.duration) * 100
|
|
||||||
if (isNaN(info.duration) || pos < 90) {
|
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
const item = queue.queue.find((item) => item.trackId === info.trackId)
|
const item = queue.queue.find((item) => item.trackId === info.trackId)
|
||||||
@@ -124,6 +120,10 @@ const Player = () => {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
const onAudioEnded = () => {
|
||||||
|
document.title = 'Navidrome'
|
||||||
|
}
|
||||||
|
|
||||||
if (authenticated && options.audioLists.length > 0) {
|
if (authenticated && options.audioLists.length > 0) {
|
||||||
return (
|
return (
|
||||||
<ReactJkMusicPlayer
|
<ReactJkMusicPlayer
|
||||||
@@ -131,6 +131,7 @@ const Player = () => {
|
|||||||
onAudioListsChange={OnAudioListsChange}
|
onAudioListsChange={OnAudioListsChange}
|
||||||
onAudioProgress={OnAudioProgress}
|
onAudioProgress={OnAudioProgress}
|
||||||
onAudioPlay={OnAudioPlay}
|
onAudioPlay={OnAudioPlay}
|
||||||
|
onAudioEnded={onAudioEnded}
|
||||||
/>
|
/>
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -6,7 +6,6 @@ const PLAYER_SET_TRACK = 'PLAYER_SET_TRACK'
|
|||||||
const PLAYER_SYNC_QUEUE = 'PLAYER_SYNC_QUEUE'
|
const PLAYER_SYNC_QUEUE = 'PLAYER_SYNC_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_PROGRESS = 'PLAYER_PROGRESS'
|
|
||||||
|
|
||||||
const mapToAudioLists = (item) => {
|
const mapToAudioLists = (item) => {
|
||||||
// If item comes from a playlist, id is mediaFileId
|
// If item comes from a playlist, id is mediaFileId
|
||||||
@@ -89,30 +88,13 @@ const scrobble = (id, submit) => ({
|
|||||||
submit,
|
submit,
|
||||||
})
|
})
|
||||||
|
|
||||||
const progress = (audioInfo) => ({
|
|
||||||
type: PLAYER_PROGRESS,
|
|
||||||
data: audioInfo,
|
|
||||||
})
|
|
||||||
|
|
||||||
const playQueueReducer = (
|
const playQueueReducer = (
|
||||||
previousState = { queue: [], clear: true, playing: false, current: {} },
|
previousState = { queue: [], clear: true, playing: false },
|
||||||
payload
|
payload
|
||||||
) => {
|
) => {
|
||||||
let queue, current
|
let queue
|
||||||
const { type, data } = payload
|
const { type, data } = payload
|
||||||
switch (type) {
|
switch (type) {
|
||||||
case PLAYER_PROGRESS:
|
|
||||||
queue = previousState.queue
|
|
||||||
current = data.ended
|
|
||||||
? {}
|
|
||||||
: {
|
|
||||||
trackId: data.trackId,
|
|
||||||
paused: data.paused,
|
|
||||||
}
|
|
||||||
return {
|
|
||||||
...previousState,
|
|
||||||
current,
|
|
||||||
}
|
|
||||||
case PLAYER_ADD_TRACKS:
|
case PLAYER_ADD_TRACKS:
|
||||||
queue = previousState.queue
|
queue = previousState.queue
|
||||||
Object.keys(data).forEach((id) => {
|
Object.keys(data).forEach((id) => {
|
||||||
@@ -127,12 +109,10 @@ const playQueueReducer = (
|
|||||||
playing: true,
|
playing: true,
|
||||||
}
|
}
|
||||||
case PLAYER_SYNC_QUEUE:
|
case PLAYER_SYNC_QUEUE:
|
||||||
current = data.length > 0 ? previousState.current : {}
|
|
||||||
return {
|
return {
|
||||||
...previousState,
|
...previousState,
|
||||||
queue: data,
|
queue: data,
|
||||||
clear: false,
|
clear: false,
|
||||||
current,
|
|
||||||
}
|
}
|
||||||
case PLAYER_SCROBBLE:
|
case PLAYER_SCROBBLE:
|
||||||
const newQueue = previousState.queue.map((item) => {
|
const newQueue = previousState.queue.map((item) => {
|
||||||
@@ -176,7 +156,6 @@ export {
|
|||||||
playTracks,
|
playTracks,
|
||||||
syncQueue,
|
syncQueue,
|
||||||
scrobble,
|
scrobble,
|
||||||
progress,
|
|
||||||
shuffleTracks,
|
shuffleTracks,
|
||||||
playQueueReducer,
|
playQueueReducer,
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,65 +0,0 @@
|
|||||||
import { makeStyles } from '@material-ui/core/styles'
|
|
||||||
import React from 'react'
|
|
||||||
import PropTypes from 'prop-types'
|
|
||||||
import { useSelector } from 'react-redux'
|
|
||||||
import { FunctionField } from 'react-admin'
|
|
||||||
import get from 'lodash.get'
|
|
||||||
import { useTheme } from '@material-ui/core/styles'
|
|
||||||
import PlayingLight from '../icons/playing-light.gif'
|
|
||||||
import PlayingDark from '../icons/playing-dark.gif'
|
|
||||||
|
|
||||||
const useStyles = makeStyles({
|
|
||||||
playingIcon: {
|
|
||||||
width: '20px',
|
|
||||||
height: '20px',
|
|
||||||
verticalAlign: 'text-top',
|
|
||||||
marginTop: '-2px',
|
|
||||||
paddingRight: '3px',
|
|
||||||
},
|
|
||||||
})
|
|
||||||
|
|
||||||
const SongTitleField = ({ showTrackNumbers, ...props }) => {
|
|
||||||
const theme = useTheme()
|
|
||||||
const classes = useStyles()
|
|
||||||
const { record } = props
|
|
||||||
const currentTrack = useSelector((state) => get(state, 'queue.current', {}))
|
|
||||||
const currentId = currentTrack.trackId
|
|
||||||
const paused = currentTrack.paused
|
|
||||||
const isCurrent =
|
|
||||||
currentId &&
|
|
||||||
!paused &&
|
|
||||||
(currentId === record.id || currentId === record.mediaFileId)
|
|
||||||
|
|
||||||
const trackName = (r) => {
|
|
||||||
const name = r.title
|
|
||||||
if (r.trackNumber && showTrackNumbers) {
|
|
||||||
return r.trackNumber.toString().padStart(2, '0') + ' ' + name
|
|
||||||
}
|
|
||||||
return name
|
|
||||||
}
|
|
||||||
|
|
||||||
return (
|
|
||||||
<>
|
|
||||||
{isCurrent && (
|
|
||||||
<img
|
|
||||||
src={theme.palette.type === 'light' ? PlayingLight : PlayingDark}
|
|
||||||
className={classes.playingIcon}
|
|
||||||
alt="playing"
|
|
||||||
/>
|
|
||||||
)}
|
|
||||||
<FunctionField
|
|
||||||
{...props}
|
|
||||||
source="title"
|
|
||||||
render={trackName}
|
|
||||||
sortable={false}
|
|
||||||
/>
|
|
||||||
</>
|
|
||||||
)
|
|
||||||
}
|
|
||||||
|
|
||||||
SongTitleField.propTypes = {
|
|
||||||
record: PropTypes.object,
|
|
||||||
showTrackNumbers: PropTypes.bool,
|
|
||||||
}
|
|
||||||
|
|
||||||
export default SongTitleField
|
|
||||||
@@ -12,7 +12,6 @@ import DocLink from './DocLink'
|
|||||||
import List from './List'
|
import List from './List'
|
||||||
import { SongDatagrid, SongDatagridRow } from './SongDatagrid'
|
import { SongDatagrid, SongDatagridRow } from './SongDatagrid'
|
||||||
import SongContextMenu from './SongContextMenu'
|
import SongContextMenu from './SongContextMenu'
|
||||||
import SongTitleField from './SongTitleField'
|
|
||||||
import QuickFilter from './QuickFilter'
|
import QuickFilter from './QuickFilter'
|
||||||
import useAlbumsPerPage from './useAlbumsPerPage'
|
import useAlbumsPerPage from './useAlbumsPerPage'
|
||||||
|
|
||||||
@@ -29,7 +28,6 @@ export {
|
|||||||
SongDetails,
|
SongDetails,
|
||||||
SongDatagrid,
|
SongDatagrid,
|
||||||
SongDatagridRow,
|
SongDatagridRow,
|
||||||
SongTitleField,
|
|
||||||
DocLink,
|
DocLink,
|
||||||
formatRange,
|
formatRange,
|
||||||
ArtistLinkField,
|
ArtistLinkField,
|
||||||
|
|||||||
Binary file not shown.
|
Before Width: | Height: | Size: 2.3 KiB |
Binary file not shown.
|
Before Width: | Height: | Size: 2.3 KiB |
@@ -19,7 +19,6 @@ import {
|
|||||||
SongDetails,
|
SongDetails,
|
||||||
SongContextMenu,
|
SongContextMenu,
|
||||||
SongDatagrid,
|
SongDatagrid,
|
||||||
SongTitleField,
|
|
||||||
} from '../common'
|
} from '../common'
|
||||||
import AddToPlaylistDialog from '../dialogs/AddToPlaylistDialog'
|
import AddToPlaylistDialog from '../dialogs/AddToPlaylistDialog'
|
||||||
import { AlbumLinkField } from '../song/AlbumLinkField'
|
import { AlbumLinkField } from '../song/AlbumLinkField'
|
||||||
@@ -161,7 +160,7 @@ const PlaylistSongs = (props) => {
|
|||||||
contextAlwaysVisible={!isDesktop}
|
contextAlwaysVisible={!isDesktop}
|
||||||
>
|
>
|
||||||
{isDesktop && <TextField source="id" label={'#'} />}
|
{isDesktop && <TextField source="id" label={'#'} />}
|
||||||
<SongTitleField source="title" showTrackNumbers={false} />
|
<TextField source="title" />
|
||||||
{isDesktop && <AlbumLinkField source="album" />}
|
{isDesktop && <AlbumLinkField source="album" />}
|
||||||
{isDesktop && <TextField source="artist" />}
|
{isDesktop && <TextField source="artist" />}
|
||||||
<DurationField
|
<DurationField
|
||||||
|
|||||||
@@ -18,7 +18,6 @@ import {
|
|||||||
SongDatagrid,
|
SongDatagrid,
|
||||||
SongDetails,
|
SongDetails,
|
||||||
QuickFilter,
|
QuickFilter,
|
||||||
SongTitleField,
|
|
||||||
} from '../common'
|
} from '../common'
|
||||||
import { useDispatch } from 'react-redux'
|
import { useDispatch } from 'react-redux'
|
||||||
import { setTrack } from '../audioplayer'
|
import { setTrack } from '../audioplayer'
|
||||||
@@ -84,7 +83,7 @@ const SongList = (props) => {
|
|||||||
rowClick={handleRowClick}
|
rowClick={handleRowClick}
|
||||||
contextAlwaysVisible={!isDesktop}
|
contextAlwaysVisible={!isDesktop}
|
||||||
>
|
>
|
||||||
<SongTitleField source="title" showTrackNumbers={false} />
|
<TextField source="title" />
|
||||||
{isDesktop && <AlbumLinkField source="album" />}
|
{isDesktop && <AlbumLinkField source="album" />}
|
||||||
<TextField source="artist" />
|
<TextField source="artist" />
|
||||||
{isDesktop && <NumberField source="trackNumber" />}
|
{isDesktop && <NumberField source="trackNumber" />}
|
||||||
|
|||||||
Reference in New Issue
Block a user