Browse Source

update star functionality

- star term -> favorites
- star/unstar to playerbar
- star/unstar api
master
jeffvli 3 years ago
parent
commit
a94f50b096
  1. 24
      src/api/api.ts
  2. 8
      src/components/layout/Sidebar.tsx
  3. 69
      src/components/player/PlayerBar.tsx
  4. 2
      src/components/starred/StarredView.tsx
  5. 16
      src/redux/playQueueSlice.ts

24
src/api/api.ts

@ -249,3 +249,27 @@ export const getScanStatus = async () => {
return scanStatus; return scanStatus;
}; };
export const star = async (id: string, type: string) => {
const { data } = await api.get(`/star`, {
params: {
id: type === 'song' ? id : undefined,
albumId: type === 'album' ? id : undefined,
artistId: type === 'artist' ? id : undefined,
},
});
return data;
};
export const unstar = async (id: string, type: string) => {
const { data } = await api.get(`/unstar`, {
params: {
id: type === 'song' ? id : undefined,
albumId: type === 'album' ? id : undefined,
artistId: type === 'artist' ? id : undefined,
},
});
return data;
};

8
src/components/layout/Sidebar.tsx

@ -39,15 +39,15 @@ const Sidebar = ({
</Nav.Item> </Nav.Item>
<Nav.Item <Nav.Item
eventKey="starred" eventKey="starred"
icon={<Icon icon="star" />} icon={<Icon icon="heart" />}
onSelect={handleSidebarSelect} onSelect={handleSidebarSelect}
disabled={disableSidebar} disabled={disableSidebar}
> >
Starred Favorites
</Nav.Item> </Nav.Item>
<Nav.Item <Nav.Item
eventKey="playlists" eventKey="playlists"
icon={<Icon icon="bookmark" />} icon={<Icon icon="list-ul" />}
onSelect={handleSidebarSelect} onSelect={handleSidebarSelect}
disabled={disableSidebar} disabled={disableSidebar}
> >
@ -55,7 +55,7 @@ const Sidebar = ({
</Nav.Item> </Nav.Item>
<Nav.Item <Nav.Item
eventKey="library" eventKey="library"
icon={<Icon icon="book2" />} icon={<Icon icon="folder-open" />}
onSelect={handleSidebarSelect} onSelect={handleSidebarSelect}
disabled={disableSidebar} disabled={disableSidebar}
> >

69
src/components/player/PlayerBar.tsx

@ -1,4 +1,5 @@
import React, { useEffect, useState, useRef } from 'react'; import React, { useEffect, useState, useRef } from 'react';
import { useQueryClient } from 'react-query';
import settings from 'electron-settings'; import settings from 'electron-settings';
import { FlexboxGrid, Icon, Grid, Row, Col } from 'rsuite'; import { FlexboxGrid, Icon, Grid, Row, Col } from 'rsuite';
import { useHistory } from 'react-router-dom'; import { useHistory } from 'react-router-dom';
@ -19,11 +20,13 @@ import {
setStatus, setStatus,
fixPlayer2Index, fixPlayer2Index,
toggleRepeat, toggleRepeat,
toggleShuffle, toggleDisplayQueue,
setStar,
} from '../../redux/playQueueSlice'; } from '../../redux/playQueueSlice';
import { useAppDispatch, useAppSelector } from '../../redux/hooks'; import { useAppDispatch, useAppSelector } from '../../redux/hooks';
import Player from './Player'; import Player from './Player';
import CustomTooltip from '../shared/CustomTooltip'; import CustomTooltip from '../shared/CustomTooltip';
import { star, unstar } from '../../api/api';
const keyCodes = { const keyCodes = {
SPACEBAR: 32, SPACEBAR: 32,
@ -32,6 +35,7 @@ const keyCodes = {
}; };
const PlayerBar = () => { const PlayerBar = () => {
const queryClient = useQueryClient();
const playQueue = useAppSelector((state) => state.playQueue); const playQueue = useAppSelector((state) => state.playQueue);
const dispatch = useAppDispatch(); const dispatch = useAppDispatch();
const [seek, setSeek] = useState(0); const [seek, setSeek] = useState(0);
@ -202,10 +206,27 @@ const PlayerBar = () => {
dispatch(toggleRepeat()); dispatch(toggleRepeat());
}; };
const handleShuffle = () => { const handleDisplayQueue = () => {
dispatch(toggleShuffle()); dispatch(toggleDisplayQueue());
}; };
const handleFavorite = async () => {
if (!playQueue.entry[playQueue.currentIndex].starred) {
star(playQueue.entry[playQueue.currentIndex].id, 'song');
dispatch(setStar('star'));
await queryClient.refetchQueries(['starred'], {
active: true,
exact: true,
});
} else {
unstar(playQueue.entry[playQueue.currentIndex].id, 'song');
dispatch(setStar('unstar'));
await queryClient.refetchQueries(['starred'], {
active: true,
exact: true,
});
}
};
return ( return (
<Player ref={playersRef}> <Player ref={playersRef}>
<PlayerContainer> <PlayerContainer>
@ -436,14 +457,14 @@ const PlayerBar = () => {
> >
{playQueue.entry.length >= 1 && ( {playQueue.entry.length >= 1 && (
<> <>
{/* Star Button */} {/* Favorite Button */}
<CustomTooltip text="Star" delay={1000}> <CustomTooltip text="Favorite">
<PlayerControlIcon <PlayerControlIcon
tabIndex={0} tabIndex={0}
icon={ icon={
playQueue.entry[playQueue.currentIndex].starred playQueue.entry[playQueue.currentIndex].starred
? 'star' ? 'heart'
: 'star-o' : 'heart-o'
} }
size="lg" size="lg"
fixedWidth fixedWidth
@ -453,46 +474,48 @@ const PlayerBar = () => {
? '#1179ac' ? '#1179ac'
: undefined, : undefined,
}} }}
onClick={handleFavorite}
/> />
</CustomTooltip> </CustomTooltip>
{/* Shuffle Button */} {/* Repeat Button */}
<CustomTooltip text="Shuffle" delay={1000}> <CustomTooltip text="Repeat">
<PlayerControlIcon <PlayerControlIcon
tabIndex={0} tabIndex={0}
icon="random" icon="repeat"
size="lg" size="lg"
fixedWidth fixedWidth
onClick={handleShuffle} onClick={handleRepeat}
onKeyDown={(e: any) => { onKeyDown={(e: any) => {
if (e.keyCode === keyCodes.SPACEBAR) { if (e.keyCode === keyCodes.SPACEBAR) {
handleShuffle(); handleRepeat();
} }
}} }}
style={{ style={{
color: playQueue.shuffle ? '#1179ac' : undefined, color:
playQueue.repeat === 'all'
? '#1179ac'
: undefined,
}} }}
/> />
</CustomTooltip> </CustomTooltip>
{/* Display Queue Button */}
{/* Repeat Button */} <CustomTooltip text="Queue">
<CustomTooltip text="Repeat" delay={1000}>
<PlayerControlIcon <PlayerControlIcon
tabIndex={0} tabIndex={0}
icon="repeat" icon="tasks"
size="lg" size="lg"
fixedWidth fixedWidth
onClick={handleRepeat} onClick={handleDisplayQueue}
onKeyDown={(e: any) => { onKeyDown={(e: any) => {
if (e.keyCode === keyCodes.SPACEBAR) { if (e.keyCode === keyCodes.SPACEBAR) {
handleRepeat(); handleDisplayQueue();
} }
}} }}
style={{ style={{
color: color: playQueue.displayQueue
playQueue.repeat === 'all' ? '#1179ac'
? '#1179ac' : undefined,
: undefined,
}} }}
/> />
</CustomTooltip> </CustomTooltip>

2
src/components/starred/StarredView.tsx

@ -133,7 +133,7 @@ const StarredView = () => {
<GenericPage <GenericPage
header={ header={
<GenericPageHeader <GenericPageHeader
title="Starred" title="Favorites"
subtitle={ subtitle={
<Nav activeKey={currentPage} onSelect={(e) => setCurrentPage(e)}> <Nav activeKey={currentPage} onSelect={(e) => setCurrentPage(e)}>
<Nav.Item eventKey="Tracks">Tracks</Nav.Item> <Nav.Item eventKey="Tracks">Tracks</Nav.Item>

16
src/redux/playQueueSlice.ts

@ -50,6 +50,7 @@ export interface PlayQueue {
isLoading: boolean; isLoading: boolean;
repeat: string; repeat: string;
shuffle: boolean; shuffle: boolean;
displayQueue: boolean;
entry: Entry[]; entry: Entry[];
} }
@ -74,6 +75,7 @@ const initialState: PlayQueue = {
isLoading: false, isLoading: false,
repeat: 'none', repeat: 'none',
shuffle: false, shuffle: false,
displayQueue: false,
entry: [], entry: [],
}; };
@ -114,6 +116,14 @@ const playQueueSlice = createSlice({
state.autoIncremented = action.payload; state.autoIncremented = action.payload;
}, },
setStar: (state, action: PayloadAction<string>) => {
if (action.payload === 'unstar') {
state.entry[state.currentIndex].starred = undefined;
} else {
state.entry[state.currentIndex].starred = String(Date.now());
}
},
toggleRepeat: (state) => { toggleRepeat: (state) => {
if (state.repeat === 'none') { if (state.repeat === 'none') {
state.repeat = 'all'; state.repeat = 'all';
@ -130,6 +140,10 @@ const playQueueSlice = createSlice({
state.shuffle = !state.shuffle; state.shuffle = !state.shuffle;
}, },
toggleDisplayQueue: (state) => {
state.displayQueue = !state.displayQueue;
},
setVolume: (state, action: PayloadAction<number>) => { setVolume: (state, action: PayloadAction<number>) => {
state.volume = action.payload; state.volume = action.payload;
}, },
@ -413,6 +427,8 @@ export const {
setAutoIncremented, setAutoIncremented,
toggleRepeat, toggleRepeat,
toggleShuffle, toggleShuffle,
toggleDisplayQueue,
resetPlayer, resetPlayer,
setStar,
} = playQueueSlice.actions; } = playQueueSlice.actions;
export default playQueueSlice.reducer; export default playQueueSlice.reducer;

Loading…
Cancel
Save