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 { TitleHeader, DragRegion, WindowControl, WindowControlButton } from './styled';
import { useAppSelector } from '../../redux/hooks';
import { getCurrentEntryList } from '../../shared/utils';
const Titlebar = ({ font }: any) => {
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
// someone knows of a better solution.
const currentEntryList =
playQueue.sortedEntry.length > 0
? 'sortedEntry'
: playQueue.shuffle
? 'shuffledEntry'
: 'entry';
const currentEntryList = getCurrentEntryList(playQueue);
const playStatus =
player.status !== 'PLAYING' && playQueue[currentEntryList].length > 0 ? '(Paused)' : '';

19
src/components/player/NowPlayingMiniView.tsx

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

21
src/components/player/NowPlayingView.tsx

@ -29,6 +29,7 @@ import PageLoader from '../loader/PageLoader';
import { resetPlayer, setStatus } from '../../redux/playerSlice';
import { ClearQueueButton, ShuffleButton } from '../shared/ToolbarButtons';
import { StyledCheckbox } from '../shared/styled';
import { getCurrentEntryList } from '../../shared/utils';
const NowPlayingView = () => {
const tableRef = useRef<any>();
@ -65,15 +66,7 @@ const NowPlayingView = () => {
if (searchQuery !== '') {
dispatch(toggleRangeSelected(filteredData));
} else {
dispatch(
toggleRangeSelected(
playQueue.sortedEntry.length > 0
? playQueue.sortedEntry
: playQueue.shuffle
? playQueue.shuffledEntry
: playQueue.entry
)
);
dispatch(toggleRangeSelected(playQueue[getCurrentEntryList(playQueue)]));
}
}
}, 100);
@ -197,15 +190,7 @@ const NowPlayingView = () => {
>
<ListViewType
ref={tableRef}
data={
searchQuery !== ''
? filteredData
: playQueue.sortedEntry.length > 0
? playQueue.sortedEntry
: playQueue.shuffle
? playQueue.shuffledEntry
: playQueue.entry
}
data={searchQuery !== '' ? filteredData : playQueue[getCurrentEntryList(playQueue)]}
currentIndex={playQueue.currentIndex}
tableColumns={settings.getSync('musicListColumns')}
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 DebugWindow from '../debug/DebugWindow';
import { CoverArtWrapper } from '../layout/styled';
import { getCurrentEntryList } from '../../shared/utils';
const keyCodes = {
SPACEBAR: 32,
@ -55,14 +56,8 @@ const PlayerBar = () => {
const history = useHistory();
useEffect(() => {
if (playQueue.sortedEntry.length > 0) {
setCurrentEntryList('sortedEntry');
} else if (playQueue.shuffle) {
setCurrentEntryList('shuffledEntry');
} else {
setCurrentEntryList('entry');
}
}, [playQueue.shuffle, playQueue.sortedEntry.length]);
setCurrentEntryList(getCurrentEntryList(playQueue));
}, [playQueue]);
useEffect(() => {
// Handle volume slider dragging

Loading…
Cancel
Save