mirror of
https://github.com/navidrome/navidrome.git
synced 2025-04-18 12:57:41 +03:00
Revert "Show indicator on current playing song. Fixes #128"
This implementation causes performance issues
This commit is contained in:
parent
86bc8d97a0
commit
72b2e756f7
@ -2,6 +2,7 @@ import React from 'react'
|
||||
import {
|
||||
BulkActionsToolbar,
|
||||
DatagridLoading,
|
||||
FunctionField,
|
||||
ListToolbar,
|
||||
TextField,
|
||||
useListController,
|
||||
@ -14,10 +15,9 @@ import StarBorderIcon from '@material-ui/icons/StarBorder'
|
||||
import { playTracks } from '../audioplayer'
|
||||
import {
|
||||
DurationField,
|
||||
SongContextMenu,
|
||||
SongDatagrid,
|
||||
SongDetails,
|
||||
SongTitleField,
|
||||
SongDatagrid,
|
||||
SongContextMenu,
|
||||
} from '../common'
|
||||
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 classes = useStyles(props)
|
||||
const classesToolbar = useStylesListToolbar(props)
|
||||
@ -124,11 +132,14 @@ const AlbumSongs = (props) => {
|
||||
sortable={false}
|
||||
/>
|
||||
)}
|
||||
<SongTitleField
|
||||
source="title"
|
||||
sortable={false}
|
||||
showTrackNumbers={!isDesktop}
|
||||
/>
|
||||
{isDesktop && <TextField source="title" sortable={false} />}
|
||||
{!isDesktop && (
|
||||
<FunctionField
|
||||
source="title"
|
||||
render={trackName}
|
||||
sortable={false}
|
||||
/>
|
||||
)}
|
||||
{isDesktop && <TextField source="artist" sortable={false} />}
|
||||
<DurationField source="duration" sortable={false} />
|
||||
<SongContextMenu
|
||||
|
@ -5,7 +5,7 @@ import { useAuthState, useDataProvider, useTranslate } from 'react-admin'
|
||||
import ReactJkMusicPlayer from 'react-jinke-music-player'
|
||||
import 'react-jinke-music-player/assets/index.css'
|
||||
import subsonic from '../subsonic'
|
||||
import { scrobble, syncQueue, progress } from './queue'
|
||||
import { scrobble, syncQueue } from './queue'
|
||||
import themes from '../themes'
|
||||
import { makeStyles } from '@material-ui/core/styles'
|
||||
|
||||
@ -100,12 +100,8 @@ const Player = () => {
|
||||
}
|
||||
|
||||
const OnAudioProgress = (info) => {
|
||||
if (info.ended) {
|
||||
document.title = 'Navidrome'
|
||||
}
|
||||
dispatch(progress(info))
|
||||
const pos = (info.currentTime / info.duration) * 100
|
||||
if (isNaN(info.duration) || pos < 90) {
|
||||
const progress = (info.currentTime / info.duration) * 100
|
||||
if (isNaN(info.duration) || progress < 90) {
|
||||
return
|
||||
}
|
||||
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) {
|
||||
return (
|
||||
<ReactJkMusicPlayer
|
||||
@ -131,6 +131,7 @@ const Player = () => {
|
||||
onAudioListsChange={OnAudioListsChange}
|
||||
onAudioProgress={OnAudioProgress}
|
||||
onAudioPlay={OnAudioPlay}
|
||||
onAudioEnded={onAudioEnded}
|
||||
/>
|
||||
)
|
||||
}
|
||||
|
@ -6,7 +6,6 @@ const PLAYER_SET_TRACK = 'PLAYER_SET_TRACK'
|
||||
const PLAYER_SYNC_QUEUE = 'PLAYER_SYNC_QUEUE'
|
||||
const PLAYER_SCROBBLE = 'PLAYER_SCROBBLE'
|
||||
const PLAYER_PLAY_TRACKS = 'PLAYER_PLAY_TRACKS'
|
||||
const PLAYER_PROGRESS = 'PLAYER_PROGRESS'
|
||||
|
||||
const mapToAudioLists = (item) => {
|
||||
// If item comes from a playlist, id is mediaFileId
|
||||
@ -89,30 +88,13 @@ const scrobble = (id, submit) => ({
|
||||
submit,
|
||||
})
|
||||
|
||||
const progress = (audioInfo) => ({
|
||||
type: PLAYER_PROGRESS,
|
||||
data: audioInfo,
|
||||
})
|
||||
|
||||
const playQueueReducer = (
|
||||
previousState = { queue: [], clear: true, playing: false, current: {} },
|
||||
previousState = { queue: [], clear: true, playing: false },
|
||||
payload
|
||||
) => {
|
||||
let queue, current
|
||||
let queue
|
||||
const { type, data } = payload
|
||||
switch (type) {
|
||||
case PLAYER_PROGRESS:
|
||||
queue = previousState.queue
|
||||
current = data.ended
|
||||
? {}
|
||||
: {
|
||||
trackId: data.trackId,
|
||||
paused: data.paused,
|
||||
}
|
||||
return {
|
||||
...previousState,
|
||||
current,
|
||||
}
|
||||
case PLAYER_ADD_TRACKS:
|
||||
queue = previousState.queue
|
||||
Object.keys(data).forEach((id) => {
|
||||
@ -127,12 +109,10 @@ const playQueueReducer = (
|
||||
playing: true,
|
||||
}
|
||||
case PLAYER_SYNC_QUEUE:
|
||||
current = data.length > 0 ? previousState.current : {}
|
||||
return {
|
||||
...previousState,
|
||||
queue: data,
|
||||
clear: false,
|
||||
current,
|
||||
}
|
||||
case PLAYER_SCROBBLE:
|
||||
const newQueue = previousState.queue.map((item) => {
|
||||
@ -176,7 +156,6 @@ export {
|
||||
playTracks,
|
||||
syncQueue,
|
||||
scrobble,
|
||||
progress,
|
||||
shuffleTracks,
|
||||
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 { SongDatagrid, SongDatagridRow } from './SongDatagrid'
|
||||
import SongContextMenu from './SongContextMenu'
|
||||
import SongTitleField from './SongTitleField'
|
||||
import QuickFilter from './QuickFilter'
|
||||
import useAlbumsPerPage from './useAlbumsPerPage'
|
||||
|
||||
@ -29,7 +28,6 @@ export {
|
||||
SongDetails,
|
||||
SongDatagrid,
|
||||
SongDatagridRow,
|
||||
SongTitleField,
|
||||
DocLink,
|
||||
formatRange,
|
||||
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,
|
||||
SongContextMenu,
|
||||
SongDatagrid,
|
||||
SongTitleField,
|
||||
} from '../common'
|
||||
import AddToPlaylistDialog from '../dialogs/AddToPlaylistDialog'
|
||||
import { AlbumLinkField } from '../song/AlbumLinkField'
|
||||
@ -161,7 +160,7 @@ const PlaylistSongs = (props) => {
|
||||
contextAlwaysVisible={!isDesktop}
|
||||
>
|
||||
{isDesktop && <TextField source="id" label={'#'} />}
|
||||
<SongTitleField source="title" showTrackNumbers={false} />
|
||||
<TextField source="title" />
|
||||
{isDesktop && <AlbumLinkField source="album" />}
|
||||
{isDesktop && <TextField source="artist" />}
|
||||
<DurationField
|
||||
|
@ -18,7 +18,6 @@ import {
|
||||
SongDatagrid,
|
||||
SongDetails,
|
||||
QuickFilter,
|
||||
SongTitleField,
|
||||
} from '../common'
|
||||
import { useDispatch } from 'react-redux'
|
||||
import { setTrack } from '../audioplayer'
|
||||
@ -84,7 +83,7 @@ const SongList = (props) => {
|
||||
rowClick={handleRowClick}
|
||||
contextAlwaysVisible={!isDesktop}
|
||||
>
|
||||
<SongTitleField source="title" showTrackNumbers={false} />
|
||||
<TextField source="title" />
|
||||
{isDesktop && <AlbumLinkField source="album" />}
|
||||
<TextField source="artist" />
|
||||
{isDesktop && <NumberField source="trackNumber" />}
|
||||
|
Loading…
x
Reference in New Issue
Block a user