Browse Source

Clean up queue selector logic

master
jeffvli 3 years ago
parent
commit
6ca73fadb2
  1. 8
      src/components/layout/Titlebar.tsx
  2. 19
      src/components/player/NowPlayingMiniView.tsx
  3. 21
      src/components/player/NowPlayingView.tsx
  4. 11
      src/components/player/PlayerBar.tsx

8
src/components/layout/Titlebar.tsx

@ -1,6 +1,7 @@
import React, { useEffect, useState } from 'react'; import React, { useEffect, useState } from 'react';
import { TitleHeader, DragRegion, WindowControl, WindowControlButton } from './styled'; import { TitleHeader, DragRegion, WindowControl, WindowControlButton } from './styled';
import { useAppSelector } from '../../redux/hooks'; import { useAppSelector } from '../../redux/hooks';
import { getCurrentEntryList } from '../../shared/utils';
const Titlebar = ({ font }: any) => { const Titlebar = ({ font }: any) => {
const playQueue = useAppSelector((state) => state.playQueue); const playQueue = useAppSelector((state) => state.playQueue);
@ -13,12 +14,7 @@ const Titlebar = ({ font }: any) => {
// Not sure if this is a bug or not, but this is the only workaround unless // Not sure if this is a bug or not, but this is the only workaround unless
// someone knows of a better solution. // someone knows of a better solution.
const currentEntryList = const currentEntryList = getCurrentEntryList(playQueue);
playQueue.sortedEntry.length > 0
? 'sortedEntry'
: playQueue.shuffle
? 'shuffledEntry'
: 'entry';
const playStatus = const playStatus =
player.status !== 'PLAYING' && playQueue[currentEntryList].length > 0 ? '(Paused)' : ''; player.status !== 'PLAYING' && playQueue[currentEntryList].length > 0 ? '(Paused)' : '';

19
src/components/player/NowPlayingMiniView.tsx

@ -32,6 +32,7 @@ import {
MoveManualButton, MoveManualButton,
MoveUpButton, MoveUpButton,
} from '../selectionbar/SelectionButtons'; } from '../selectionbar/SelectionButtons';
import { getCurrentEntryList } from '../../shared/utils';
const NowPlayingMiniView = () => { const NowPlayingMiniView = () => {
const tableRef = useRef<any>(); const tableRef = useRef<any>();
@ -62,15 +63,7 @@ const NowPlayingMiniView = () => {
dispatch(toggleSelected(rowData)); dispatch(toggleSelected(rowData));
} else if (e.shiftKey) { } else if (e.shiftKey) {
dispatch(setRangeSelected(rowData)); dispatch(setRangeSelected(rowData));
dispatch( dispatch(toggleRangeSelected(playQueue[getCurrentEntryList(playQueue)]));
toggleRangeSelected(
playQueue.sortedEntry.length > 0
? playQueue.sortedEntry
: playQueue.shuffle
? playQueue.shuffledEntry
: playQueue.entry
)
);
} }
}, 100); }, 100);
} }
@ -199,13 +192,7 @@ const NowPlayingMiniView = () => {
> >
<ListViewType <ListViewType
ref={tableRef} ref={tableRef}
data={ data={playQueue[getCurrentEntryList(playQueue)]}
playQueue.sortedEntry.length > 0
? playQueue.sortedEntry
: playQueue.shuffle
? playQueue.shuffledEntry
: playQueue.entry
}
currentIndex={playQueue.currentIndex} currentIndex={playQueue.currentIndex}
tableColumns={settings.getSync('miniListColumns')} tableColumns={settings.getSync('miniListColumns')}
handleRowClick={handleRowClick} handleRowClick={handleRowClick}

21
src/components/player/NowPlayingView.tsx

@ -29,6 +29,7 @@ import PageLoader from '../loader/PageLoader';
import { resetPlayer, setStatus } from '../../redux/playerSlice'; import { resetPlayer, setStatus } from '../../redux/playerSlice';
import { ClearQueueButton, ShuffleButton } from '../shared/ToolbarButtons'; import { ClearQueueButton, ShuffleButton } from '../shared/ToolbarButtons';
import { StyledCheckbox } from '../shared/styled'; import { StyledCheckbox } from '../shared/styled';
import { getCurrentEntryList } from '../../shared/utils';
const NowPlayingView = () => { const NowPlayingView = () => {
const tableRef = useRef<any>(); const tableRef = useRef<any>();
@ -65,15 +66,7 @@ const NowPlayingView = () => {
if (searchQuery !== '') { if (searchQuery !== '') {
dispatch(toggleRangeSelected(filteredData)); dispatch(toggleRangeSelected(filteredData));
} else { } else {
dispatch( dispatch(toggleRangeSelected(playQueue[getCurrentEntryList(playQueue)]));
toggleRangeSelected(
playQueue.sortedEntry.length > 0
? playQueue.sortedEntry
: playQueue.shuffle
? playQueue.shuffledEntry
: playQueue.entry
)
);
} }
} }
}, 100); }, 100);
@ -197,15 +190,7 @@ const NowPlayingView = () => {
> >
<ListViewType <ListViewType
ref={tableRef} ref={tableRef}
data={ data={searchQuery !== '' ? filteredData : playQueue[getCurrentEntryList(playQueue)]}
searchQuery !== ''
? filteredData
: playQueue.sortedEntry.length > 0
? playQueue.sortedEntry
: playQueue.shuffle
? playQueue.shuffledEntry
: playQueue.entry
}
currentIndex={playQueue.currentIndex} currentIndex={playQueue.currentIndex}
tableColumns={settings.getSync('musicListColumns')} tableColumns={settings.getSync('musicListColumns')}
handleRowClick={handleRowClick} handleRowClick={handleRowClick}

11
src/components/player/PlayerBar.tsx

@ -33,6 +33,7 @@ import { star, unstar } from '../../api/api';
import placeholderImg from '../../img/placeholder.jpg'; import placeholderImg from '../../img/placeholder.jpg';
import DebugWindow from '../debug/DebugWindow'; import DebugWindow from '../debug/DebugWindow';
import { CoverArtWrapper } from '../layout/styled'; import { CoverArtWrapper } from '../layout/styled';
import { getCurrentEntryList } from '../../shared/utils';
const keyCodes = { const keyCodes = {
SPACEBAR: 32, SPACEBAR: 32,
@ -55,14 +56,8 @@ const PlayerBar = () => {
const history = useHistory(); const history = useHistory();
useEffect(() => { useEffect(() => {
if (playQueue.sortedEntry.length > 0) { setCurrentEntryList(getCurrentEntryList(playQueue));
setCurrentEntryList('sortedEntry'); }, [playQueue]);
} else if (playQueue.shuffle) {
setCurrentEntryList('shuffledEntry');
} else {
setCurrentEntryList('entry');
}
}, [playQueue.shuffle, playQueue.sortedEntry.length]);
useEffect(() => { useEffect(() => {
// Handle volume slider dragging // Handle volume slider dragging

Loading…
Cancel
Save