Browse Source

Update default prettier config

- Change printWidth from 80 -> 100
master
jeffvli 3 years ago
parent
commit
2243d40a66
  1. 4
      .prettierrc
  2. 15
      package.json
  3. 5
      src/App.tsx
  4. 4
      src/__tests__/App.test.tsx
  5. 49
      src/api/api.ts
  6. 28
      src/components/card/Card.tsx
  7. 27
      src/components/debug/DebugWindow.tsx
  8. 9
      src/components/layout/GenericPage.tsx
  9. 13
      src/components/layout/GenericPageHeader.tsx
  10. 5
      src/components/layout/Layout.tsx
  11. 5
      src/components/layout/NavToggle.tsx
  12. 25
      src/components/layout/Titlebar.tsx
  13. 22
      src/components/layout/styled.tsx
  14. 4
      src/components/library/AlbumList.tsx
  15. 33
      src/components/library/AlbumView.tsx
  16. 27
      src/components/library/ArtistView.tsx
  17. 21
      src/components/library/LibraryView.tsx
  18. 6
      src/components/loader/PageLoader.tsx
  19. 21
      src/components/modal/PageModal.tsx
  20. 13
      src/components/player/NowPlayingMiniView.tsx
  21. 6
      src/components/player/NowPlayingView.tsx
  22. 111
      src/components/player/Player.tsx
  23. 155
      src/components/player/PlayerBar.tsx
  24. 19
      src/components/player/styled.tsx
  25. 22
      src/components/playlist/PlaylistList.tsx
  26. 62
      src/components/playlist/PlaylistView.tsx
  27. 20
      src/components/scrollingmenu/ScrollingMenu.tsx
  28. 7
      src/components/selectionbar/SelectionBar.tsx
  29. 24
      src/components/selectionbar/SelectionButtons.tsx
  30. 4
      src/components/settings/Config.tsx
  31. 43
      src/components/settings/ConfigPanels/CacheConfig.tsx
  32. 5
      src/components/settings/ConfigPanels/DebugConfig.tsx
  33. 19
      src/components/settings/ConfigPanels/ListViewConfig.tsx
  34. 23
      src/components/settings/ConfigPanels/LookAndFeelConfig.tsx
  35. 48
      src/components/settings/ConfigPanels/PlaybackConfig.tsx
  36. 9
      src/components/settings/ConfigPanels/PlayerConfig.tsx
  37. 61
      src/components/shared/ContextMenu.tsx
  38. 17
      src/components/shared/ToolbarButtons.tsx
  39. 30
      src/components/shared/styled.ts
  40. 5
      src/components/shared/toast.ts
  41. 26
      src/components/starred/StarredView.tsx
  42. 21
      src/components/viewtypes/GridViewType.tsx
  43. 152
      src/components/viewtypes/ListViewTable.tsx
  44. 8
      src/components/viewtypes/ListViewType.tsx
  45. 6
      src/components/viewtypes/ViewTypeButtons.tsx
  46. 10
      src/components/viewtypes/styled.tsx
  47. 10
      src/hooks/useSearchQuery.ts
  48. 4
      src/index.html
  49. 55
      src/main.dev.js
  50. 39
      src/menu.ts
  51. 11
      src/redux/miscSlice.ts
  52. 16
      src/redux/multiSelectSlice.ts
  53. 146
      src/redux/playQueueSlice.ts
  54. 44
      src/shared/utils.ts
  55. 7
      yarn.lock

4
.prettierrc

@ -2,5 +2,7 @@
"trailingComma": "es5",
"tabWidth": 2,
"semi": true,
"singleQuote": false
"singleQuote": true,
"printWidth": 100,
"arrowParens": "always"
}

15
package.json

@ -297,21 +297,6 @@
"yarn": ">=1.21.3"
},
"browserslist": [],
"prettier": {
"overrides": [
{
"files": [
".prettierrc",
".babelrc",
".eslintrc"
],
"options": {
"parser": "json"
}
}
],
"singleQuote": true
},
"renovate": {
"extends": [
"bliss"

5
src/App.tsx

@ -55,10 +55,7 @@ const App = () => {
document.getElementById('local-search-input')?.focus();
}, []);
if (
!localStorage.getItem('server') ||
!localStorage.getItem('serverBase64')
) {
if (!localStorage.getItem('server') || !localStorage.getItem('serverBase64')) {
return (
<ThemeProvider theme={theme}>
<Layout disableSidebar footer={<MockFooter />} font={font}>

4
src/__tests__/App.test.tsx

@ -9,9 +9,7 @@ import { Player } from '../redux/playerSlice';
import { General } from '../redux/miscSlice';
import App from '../App';
const middlewares:
| Middleware<Record<string, unknown>, any, Dispatch<AnyAction>>[]
| undefined = [];
const middlewares: Middleware<Record<string, unknown>, any, Dispatch<AnyAction>>[] | undefined = [];
const mockStore = configureMockStore(middlewares);
const playQueueState: PlayQueue = {

49
src/api/api.ts

@ -141,18 +141,13 @@ export const getPlaylists = async (sortBy: string) => {
return a.changed > b.changed ? -1 : a.changed < b.changed ? 1 : 0;
})
: sortBy === 'name'
? _.orderBy(
data.playlists.playlist || [],
[(entry) => entry.name.toLowerCase()],
'asc'
)
? _.orderBy(data.playlists.playlist || [], [(entry) => entry.name.toLowerCase()], 'asc')
: data.playlists?.playlist;
return (newData || []).map((playlist: any) => ({
...playlist,
name: playlist.name,
image:
playlist.songCount > 0 ? getCoverArtUrl(playlist) : 'img/placeholder.jpg',
image: playlist.songCount > 0 ? getCoverArtUrl(playlist) : 'img/placeholder.jpg',
}));
};
@ -168,10 +163,7 @@ export const getPlaylist = async (id: string) => {
index,
uniqueId: nanoid(),
})),
image:
data.playlist.songCount > 0
? getCoverArtUrl(data.playlist)
: 'img/placeholder.jpg',
image: data.playlist.songCount > 0 ? getCoverArtUrl(data.playlist) : 'img/placeholder.jpg',
};
};
@ -250,17 +242,15 @@ export const getAlbumsDirect = async (options: any, coverArtSize = 150) => {
params: options,
});
const albums = (data.albumList2.album || []).map(
(entry: any, index: any) => ({
...entry,
albumId: entry.id,
image: getCoverArtUrl(entry, coverArtSize),
starred: entry.starred || undefined,
type: 'album',
index,
uniqueId: nanoid(),
})
);
const albums = (data.albumList2.album || []).map((entry: any, index: any) => ({
...entry,
albumId: entry.id,
image: getCoverArtUrl(entry, coverArtSize),
starred: entry.starred || undefined,
type: 'album',
index,
uniqueId: nanoid(),
}));
return albums;
};
@ -348,9 +338,7 @@ export const getArtists = async () => {
const { data } = await api.get(`/getArtists`);
const artistList: any[] = [];
const artists = (data.artists?.index || []).flatMap(
(index: any) => index.artist
);
const artists = (data.artists?.index || []).flatMap((index: any) => index.artist);
artists.map((artist: any) =>
artistList.push({
@ -523,11 +511,7 @@ export const setRating = async (id: string, rating: number) => {
return data;
};
export const getSimilarSongs = async (
id: string,
count: number,
coverArtSize = 150
) => {
export const getSimilarSongs = async (id: string, count: number, coverArtSize = 150) => {
const { data } = await api.get(`/getSimilarSongs2`, {
params: { id, count },
});
@ -559,10 +543,7 @@ export const updatePlaylistSongs = async (id: string, entry: any[]) => {
return data;
};
export const updatePlaylistSongsLg = async (
playlistId: string,
entry: any[]
) => {
export const updatePlaylistSongsLg = async (playlistId: string, entry: any[]) => {
const entryIds = _.map(entry, 'id');
// Set these in chunks so the api doesn't break

28
src/components/card/Card.tsx

@ -7,11 +7,7 @@ import { useQueryClient } from 'react-query';
import cacheImage from '../shared/cacheImage';
import { getAlbum, getPlaylist, star, unstar } from '../../api/api';
import { useAppDispatch, useAppSelector } from '../../redux/hooks';
import {
appendPlayQueue,
fixPlayer2Index,
setPlayQueue,
} from '../../redux/playQueueSlice';
import { appendPlayQueue, fixPlayer2Index, setPlayQueue } from '../../redux/playQueueSlice';
import { isCached, getImageCachePath } from '../../shared/utils';
import {
@ -126,9 +122,7 @@ const Card = ({
{lazyLoad ? (
<LazyCardImg
src={
isCached(
`${cachePath}${rest.details.cacheType}_${rest.details.id}.jpg`
)
isCached(`${cachePath}${rest.details.cacheType}_${rest.details.id}.jpg`)
? `${cachePath}${rest.details.cacheType}_${rest.details.id}.jpg`
: rest.coverArt
}
@ -147,12 +141,7 @@ const Card = ({
}}
/>
) : (
<CardImg
src={rest.coverArt}
alt="img"
onClick={handleClick}
cardsize={size}
/>
<CardImg src={rest.coverArt} alt="img" onClick={handleClick} cardsize={size} />
)}
{hasHoverButtons && (
@ -172,9 +161,7 @@ const Card = ({
<FavoriteOverlayButton
onClick={handleFavorite}
size="xs"
icon={
<Icon icon={rest.details.starred ? 'heart' : 'heart-o'} />
}
icon={<Icon icon={rest.details.starred ? 'heart' : 'heart-o'} />}
/>
)}
{!rest.isModal && (
@ -189,12 +176,7 @@ const Card = ({
</Overlay>
<InfoPanel cardsize={size}>
<InfoSpan>
<CardTitleButton
appearance="link"
size="sm"
onClick={handleClick}
cardsize={size}
>
<CardTitleButton appearance="link" size="sm" onClick={handleClick} cardsize={size}>
{rest.title}
</CardTitleButton>
</InfoSpan>

27
src/components/debug/DebugWindow.tsx

@ -145,9 +145,7 @@ const DebugWindow = ({ ...rest }) => {
<table style={{ tableLayout: 'fixed', textAlign: 'center' }}>
<tbody>
<tr>
<th style={{ textAlign: 'left' }}>
Player [{playQueue.currentPlayer}]
</th>
<th style={{ textAlign: 'left' }}>Player [{playQueue.currentPlayer}]</th>
<th
style={{
color: 'rgb(0, 150, 0)',
@ -170,12 +168,8 @@ const DebugWindow = ({ ...rest }) => {
</tr>
<tr>
<td style={{ width: '80px', textAlign: 'left' }}>volume</td>
<td style={{ width: '65px' }}>
{Number(playQueue.player1.volume).toFixed(2)}
</td>
<td style={{ width: '65px' }}>
{Number(playQueue.player2.volume).toFixed(2)}
</td>
<td style={{ width: '65px' }}>{Number(playQueue.player1.volume).toFixed(2)}</td>
<td style={{ width: '65px' }}>{Number(playQueue.player2.volume).toFixed(2)}</td>
</tr>
</tbody>
</table>
@ -186,10 +180,7 @@ const DebugWindow = ({ ...rest }) => {
<h6>Volume fade</h6>
</FlexboxGrid.Item>
<FlexboxGrid.Item>
<Button
size="xs"
onClick={() => dispatch(setFadeData({ clear: true }))}
>
<Button size="xs" onClick={() => dispatch(setFadeData({ clear: true }))}>
Reset
</Button>
</FlexboxGrid.Item>
@ -224,18 +215,16 @@ const DebugWindow = ({ ...rest }) => {
}}
>
<li>
lastSelected: [{multiSelect.lastSelected.rowIndex}]{' '}
{multiSelect.lastSelected.title} {multiSelect.lastSelected.id}
lastSelected: [{multiSelect.lastSelected.rowIndex}] {multiSelect.lastSelected.title}{' '}
{multiSelect.lastSelected.id}
</li>
<li>
range (start): [
{multiSelect.lastRangeSelected.lastSelected.rowIndex}]{' '}
range (start): [{multiSelect.lastRangeSelected.lastSelected.rowIndex}]{' '}
{multiSelect.lastRangeSelected.lastSelected.title}{' '}
{multiSelect.lastRangeSelected.lastSelected.id}
</li>
<li>
range (end): [
{multiSelect.lastRangeSelected.lastRangeSelected.rowIndex}]{' '}
range (end): [{multiSelect.lastRangeSelected.lastRangeSelected.rowIndex}]{' '}
{multiSelect.lastRangeSelected.lastRangeSelected.title}{' '}
{multiSelect.lastRangeSelected.lastRangeSelected.id}
</li>

9
src/components/layout/GenericPage.tsx

@ -14,10 +14,7 @@ const GenericPage = ({ header, children, hideDivider, ...rest }: any) => {
useEffect(() => {
if (misc.dynamicBackground) {
const cachedImagePath = `${cachePath}album_${playQueue.current?.albumId}.jpg`;
const serverImagePath = playQueue.current?.image.replace(
/size=\d+/,
'size=500'
);
const serverImagePath = playQueue.current?.image.replace(/size=\d+/, 'size=500');
const cssBackgroundImagePath = `${cachePath}album_${playQueue.current?.albumId}.jpg`.replaceAll(
'\\',
'/'
@ -28,9 +25,7 @@ const GenericPage = ({ header, children, hideDivider, ...rest }: any) => {
preloadImage.src = serverImagePath;
}
const imagePath = isCached(cachedImagePath)
? cssBackgroundImagePath
: serverImagePath;
const imagePath = isCached(cachedImagePath) ? cssBackgroundImagePath : serverImagePath;
setBackgroundImage(imagePath);
}

13
src/components/layout/GenericPageHeader.tsx

@ -60,9 +60,7 @@ const GenericPageHeader = ({
alignSelf: 'center',
}}
>
{sidetitle && (
<span style={{ display: 'inline-block' }}>{sidetitle}</span>
)}
{sidetitle && <span style={{ display: 'inline-block' }}>{sidetitle}</span>}
{showSearchBar && (
<span style={{ display: 'inline-block' }}>
<StyledInputGroup inside>
@ -74,10 +72,7 @@ const GenericPageHeader = ({
onChange={handleSearch}
/>
{searchQuery !== '' && (
<InputGroup.Button
appearance="subtle"
onClick={clearSearchQuery}
>
<InputGroup.Button appearance="subtle" onClick={clearSearchQuery}>
<Icon icon="close" />
</InputGroup.Button>
)}
@ -105,9 +100,7 @@ const GenericPageHeader = ({
{subtitle}
</span>
<span style={{ alignSelf: 'center' }}>
{subsidetitle && (
<span style={{ display: 'inline-block' }}>{subsidetitle}</span>
)}
{subsidetitle && <span style={{ display: 'inline-block' }}>{subsidetitle}</span>}
{showViewTypeButtons && (
<span style={{ display: 'inline-block' }}>
<ViewTypeButtons

5
src/components/layout/Layout.tsx

@ -74,10 +74,7 @@ const Layout = ({ footer, children, disableSidebar, font }: any) => {
})
);
}
if (
multiSelect.selected.length > 0 &&
!multiSelect.isSelectDragging
) {
if (multiSelect.selected.length > 0 && !multiSelect.isSelectDragging) {
dispatch(clearSelected());
}
}}

5
src/components/layout/NavToggle.tsx

@ -20,10 +20,7 @@ const NavToggle = ({ expand, onChange }: any) => {
</Nav>
<Nav pullRight>
<Nav.Item
onClick={onChange}
style={{ width: 56, textAlign: 'center' }}
>
<Nav.Item onClick={onChange} style={{ width: 56, textAlign: 'center' }}>
<Icon icon={expand ? 'angle-left' : 'angle-right'} />
</Nav.Item>
</Nav>

25
src/components/layout/Titlebar.tsx

@ -1,10 +1,5 @@
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';
const Titlebar = ({ font }: any) => {
@ -21,16 +16,12 @@ const Titlebar = ({ font }: any) => {
const currentEntryList = playQueue.shuffle ? 'shuffledEntry' : 'entry';
const playStatus =
player.status !== 'PLAYING' && playQueue[currentEntryList].length > 0
? '(Paused)'
: '';
player.status !== 'PLAYING' && playQueue[currentEntryList].length > 0 ? '(Paused)' : '';
const songTitle = playQueue[currentEntryList][playQueue.currentIndex]?.title
? `(${playQueue.currentIndex + 1} / ${
playQueue[currentEntryList].length
}) ~ ${playQueue[currentEntryList][playQueue.currentIndex]?.title} ~ ${
playQueue[currentEntryList][playQueue.currentIndex]?.artist
} `
? `(${playQueue.currentIndex + 1} / ${playQueue[currentEntryList].length}) ~ ${
playQueue[currentEntryList][playQueue.currentIndex]?.title
} ~ ${playQueue[currentEntryList][playQueue.currentIndex]?.artist} `
: 'sonixd';
setTitle(`${playStatus} ${songTitle}`);
@ -59,11 +50,7 @@ const Titlebar = ({ font }: any) => {
alt=""
/>
</WindowControlButton>
<WindowControlButton
restoreButton
className="button"
id="restore-button"
>
<WindowControlButton restoreButton className="button" id="restore-button">
<img
className="icon"
srcSet="img/icons/restore-w-10.png 1x, img/icons/restore-w-12.png 1.25x, img/icons/restore-w-15.png 1.5x, img/icons/restore-w-15.png 1.75x, img/icons/restore-w-20.png 2x, img/icons/restore-w-20.png 2.25x, img/icons/restore-w-24.png 2.5x, img/icons/restore-w-30.png 3x, img/icons/restore-w-30.png 3.5x"

22
src/components/layout/styled.tsx

@ -19,12 +19,9 @@ interface ContainerProps {
children: any;
}
const StyledContainer = ({
id,
expanded,
children,
...props
}: ContainerProps) => <Container {...props}>{children}</Container>;
const StyledContainer = ({ id, expanded, children, ...props }: ContainerProps) => (
<Container {...props}>{children}</Container>
);
export const MainContainer = styled(StyledContainer)`
padding-left: ${(props) => (props.expanded ? '193px' : '56px')};
@ -44,8 +41,7 @@ export const TitleHeader = styled.header<{ font: string }>`
display: block;
position: fixed;
height: 32px;
width: ${(props) =>
props.className?.includes('maximized') ? '100%' : 'calc(100%)'};
width: ${(props) => (props.className?.includes('maximized') ? '100%' : 'calc(100%)')};
background: ${(props) => props.theme.primary.titleBar};
padding: 4px;
color: ${(props) => props.theme.primary.titleText};
@ -86,8 +82,7 @@ export const WindowControlButton = styled.div<{
align-items: center;
width: 100%;
height: 100%;
grid-column: ${(props) =>
props.minButton ? 1 : props.maxButton || props.restoreButton ? 2 : 3};
grid-column: ${(props) => (props.minButton ? 1 : props.maxButton || props.restoreButton ? 2 : 3)};
&:hover {
background: rgba(255, 255, 255, 0.1);
@ -113,9 +108,7 @@ export const PageContainer = styled(Container)<{ $backgroundSrc?: string }>`
right: 0;
display: block;
background-image: ${
props.$backgroundSrc ? `url(${props.$backgroundSrc})` : undefined
};
background-image: ${props.$backgroundSrc ? `url(${props.$backgroundSrc})` : undefined};
transition: background-image 1s ease-in-out;
width: 100%;
@ -155,8 +148,7 @@ export const FixedSidebar = styled(Sidebar)<{ font: string }>`
export const CoverArtWrapper = styled.div`
display: inline-block;
filter: ${(props) =>
`drop-shadow(0px 5px 8px ${props.theme.primary.coverArtShadow})`};
filter: ${(props) => `drop-shadow(0px 5px 8px ${props.theme.primary.coverArtShadow})`};
`;
export const PageHeaderTitle = styled.h1`

4
src/components/library/AlbumList.tsx

@ -54,9 +54,7 @@ const AlbumList = () => {
dispatch(toggleSelected(rowData));
} else if (e.shiftKey) {
dispatch(setRangeSelected(rowData));
dispatch(
toggleRangeSelected(searchQuery !== '' ? filteredData : albums)
);
dispatch(toggleRangeSelected(searchQuery !== '' ? filteredData : albums));
}
}, 100);
}

33
src/components/library/AlbumView.tsx

@ -3,11 +3,7 @@ import settings from 'electron-settings';
import { ButtonToolbar, Tag } from 'rsuite';
import { useQuery, useQueryClient } from 'react-query';
import { useParams, useHistory } from 'react-router-dom';
import {
FavoriteButton,
PlayAppendButton,
PlayButton,
} from '../shared/ToolbarButtons';
import { FavoriteButton, PlayAppendButton, PlayButton } from '../shared/ToolbarButtons';
import { getAlbum, star, unstar } from '../../api/api';
import { useAppDispatch, useAppSelector } from '../../redux/hooks';
import {
@ -44,9 +40,8 @@ const AlbumView = ({ ...rest }: any) => {
const { id } = useParams<AlbumParams>();
const albumId = rest.id ? rest.id : id;
const { isLoading, isError, data, error }: any = useQuery(
['album', albumId],
() => getAlbum(albumId)
const { isLoading, isError, data, error }: any = useQuery(['album', albumId], () =>
getAlbum(albumId)
);
const [searchQuery, setSearchQuery] = useState('');
const filteredData = useSearchQuery(searchQuery, data?.song, [
@ -66,9 +61,7 @@ const AlbumView = ({ ...rest }: any) => {
dispatch(toggleSelected(rowData));
} else if (e.shiftKey) {
dispatch(setRangeSelected(rowData));
dispatch(
toggleRangeSelected(searchQuery !== '' ? filteredData : data.song)
);
dispatch(toggleRangeSelected(searchQuery !== '' ? filteredData : data.song));
}
}, 100);
}
@ -171,21 +164,9 @@ const AlbumView = ({ ...rest }: any) => {
</div>
<div style={{ marginTop: '10px' }}>
<ButtonToolbar>
<PlayButton
appearance="primary"
size="lg"
onClick={handlePlay}
/>
<PlayAppendButton
appearance="primary"
size="lg"
onClick={handlePlayAppend}
/>
<FavoriteButton
size="lg"
isFavorite={data.starred}
onClick={handleFavorite}
/>
<PlayButton appearance="primary" size="lg" onClick={handlePlay} />
<PlayAppendButton appearance="primary" size="lg" onClick={handlePlayAppend} />
<FavoriteButton size="lg" isFavorite={data.starred} onClick={handleFavorite} />
</ButtonToolbar>
</div>
</div>

27
src/components/library/ArtistView.tsx

@ -7,10 +7,7 @@ import { useParams, useHistory } from 'react-router-dom';
import { PlayAppendButton, PlayButton } from '../shared/ToolbarButtons';
import { getArtist, getArtistInfo } from '../../api/api';
import { useAppDispatch } from '../../redux/hooks';
import {
fixPlayer2Index,
setPlayQueueByRowClick,
} from '../../redux/playQueueSlice';
import { fixPlayer2Index, setPlayQueueByRowClick } from '../../redux/playQueueSlice';
import {
toggleSelected,
setRangeSelected,
@ -35,16 +32,13 @@ interface ArtistParams {
const ArtistView = ({ ...rest }: any) => {
const dispatch = useAppDispatch();
const history = useHistory();
const [viewType, setViewType] = useState(
settings.getSync('albumViewType') || 'list'
);
const [viewType, setViewType] = useState(settings.getSync('albumViewType') || 'list');
const { id } = useParams<ArtistParams>();
const artistId = rest.id ? rest.id : id;
const { isLoading, isError, data, error }: any = useQuery(
['artist', artistId],
() => getArtist(artistId)
const { isLoading, isError, data, error }: any = useQuery(['artist', artistId], () =>
getArtist(artistId)
);
const {
isLoading: isLoadingAI,
@ -54,10 +48,7 @@ const ArtistView = ({ ...rest }: any) => {
}: any = useQuery(['artistInfo', artistId], () => getArtistInfo(artistId, 8));
const [searchQuery, setSearchQuery] = useState('');
const filteredData = useSearchQuery(searchQuery, data?.album, [
'name',
'artist',
]);
const filteredData = useSearchQuery(searchQuery, data?.album, ['name', 'artist']);
let timeout: any = null;
const handleRowClick = (e: any, rowData: any) => {
@ -69,9 +60,7 @@ const ArtistView = ({ ...rest }: any) => {
dispatch(toggleSelected(rowData));
} else if (e.shiftKey) {
dispatch(setRangeSelected(rowData));
dispatch(
toggleRangeSelected(searchQuery !== '' ? filteredData : data.album)
);
dispatch(toggleRangeSelected(searchQuery !== '' ? filteredData : data.album));
}
}, 100);
}
@ -147,9 +136,7 @@ const ArtistView = ({ ...rest }: any) => {
<TagLink
onClick={() => {
if (!rest.isModal) {
history.push(
`/library/artist/${artist.id}`
);
history.push(`/library/artist/${artist.id}`);
} else {
dispatch(
addModalPage({

21
src/components/library/LibraryView.tsx

@ -28,21 +28,13 @@ const LibraryView = () => {
const [data, setData] = useState<any[]>([]);
const [offset, setOffset] = useState(0);
const [viewType, setViewType] = useState(settings.getSync('albumViewType'));
const { isLoading: isLoadingArtists, data: artists }: any = useQuery(
'artists',
getArtists,
{
enabled: currentPage === 'artists',
}
);
const { isLoading: isLoadingArtists, data: artists }: any = useQuery('artists', getArtists, {
enabled: currentPage === 'artists',
});
const [searchQuery, setSearchQuery] = useState('');
const filteredData = useSearchQuery(
searchQuery,
currentPage === 'artists'
? artists
: currentPage === 'albums'
? data
: data,
currentPage === 'artists' ? artists : currentPage === 'albums' ? data : data,
['name', 'artist']
);
@ -116,10 +108,7 @@ const LibraryView = () => {
{artists && (
<>
{currentPage === 'artists' && (
<ArtistList
viewType={viewType}
data={searchQuery === '' ? artists : filteredData}
/>
<ArtistList viewType={viewType} data={searchQuery === '' ? artists : filteredData} />
)}
</>
)}

6
src/components/loader/PageLoader.tsx

@ -10,12 +10,10 @@ const LoaderContainer = styled.div`
div {
span {
&:after {
border-color: ${(props) =>
`${props.theme.primary.main} transparent transparent`};
border-color: ${(props) => `${props.theme.primary.main} transparent transparent`};
}
&:before {
border: ${(props) =>
`3px solid ${props.theme.primary.spinnerBackground}`};
border: ${(props) => `3px solid ${props.theme.primary.spinnerBackground}`};
}
}
}

21
src/components/modal/PageModal.tsx

@ -42,25 +42,14 @@ const PageModal = () => {
</StyledButton>
</Modal.Header>
<Modal.Body style={{ height: '800px' }}>
{misc.modalPages[misc.modal.currentPageIndex]?.pageType ===
'artist' && (
<ArtistView
id={misc.modalPages[misc.modal.currentPageIndex].id}
isModal
/>
{misc.modalPages[misc.modal.currentPageIndex]?.pageType === 'artist' && (
<ArtistView id={misc.modalPages[misc.modal.currentPageIndex].id} isModal />
)}
{misc.modalPages[misc.modal.currentPageIndex]?.pageType === 'album' && (
<AlbumView
id={misc.modalPages[misc.modal.currentPageIndex].id}
isModal
/>
<AlbumView id={misc.modalPages[misc.modal.currentPageIndex].id} isModal />
)}
{misc.modalPages[misc.modal.currentPageIndex]?.pageType ===
'playlist' && (
<PlaylistView
id={misc.modalPages[misc.modal.currentPageIndex].id}
isModal
/>
{misc.modalPages[misc.modal.currentPageIndex]?.pageType === 'playlist' && (
<PlaylistView id={misc.modalPages[misc.modal.currentPageIndex].id} isModal />
)}
</Modal.Body>
</StyledModal>

13
src/components/player/NowPlayingMiniView.tsx

@ -50,12 +50,7 @@ const NowPlayingMiniView = () => {
);
}, 100);
}
}, [
playQueue.currentIndex,
tableRef,
playQueue.displayQueue,
playQueue.scrollWithCurrentSong,
]);
}, [playQueue.currentIndex, tableRef, playQueue.displayQueue, playQueue.scrollWithCurrentSong]);
let timeout: any = null;
const handleRowClick = (e: any, rowData: any) => {
@ -143,11 +138,7 @@ const NowPlayingMiniView = () => {
padding="0px"
header={
<>
<FlexboxGrid
justify="space-between"
align="middle"
style={{ height: '50px' }}
>
<FlexboxGrid justify="space-between" align="middle" style={{ height: '50px' }}>
<FlexboxGrid.Item>
<ButtonToolbar>
<StyledIconButton

6
src/components/player/NowPlayingView.tsx

@ -37,11 +37,7 @@ const NowPlayingView = () => {
const multiSelect = useAppSelector((state) => state.multiSelect);
const [searchQuery, setSearchQuery] = useState('');
const filteredData = useSearchQuery(searchQuery, playQueue.entry, [
'title',
'artist',
'album',
]);
const filteredData = useSearchQuery(searchQuery, playQueue.entry, ['title', 'artist', 'album']);
useEffect(() => {
if (playQueue.scrollWithCurrentSong) {

111
src/components/player/Player.tsx

@ -49,8 +49,7 @@ const gaplessListenHandler = (
// Add a bit of leeway for the second track to start since the
// seek value doesn't always reach the duration
const durationPadding =
pollingInterval <= 10 ? 0.12 : pollingInterval <= 20 ? 0.13 : 0.15;
const durationPadding = pollingInterval <= 10 ? 0.12 : pollingInterval <= 20 ? 0.13 : 0.15;
if (seek + durationPadding >= duration) {
nextPlayerRef.current.audioEl.current.play();
}
@ -68,15 +67,13 @@ const listenHandler = (
volumeFade: boolean,
debug: boolean
) => {
const currentSeek =
currentPlayerRef.current?.audioEl.current?.currentTime || 0;
const currentSeek = currentPlayerRef.current?.audioEl.current?.currentTime || 0;
const duration = currentPlayerRef.current?.audioEl.current?.duration;
const fadeAtTime = duration - fadeDuration;
// Fade only if repeat is 'all' or if not on the last track
if (
playQueue[`player${player}`].index + 1 <
playQueue[currentEntryList].length ||
playQueue[`player${player}`].index + 1 < playQueue[currentEntryList].length ||
playQueue.repeat === 'all'
) {
// Detect to start fading when seek is greater than the fade time
@ -100,18 +97,15 @@ const listenHandler = (
Math.sqrt(0.5 * (2 - percentageOfFadeLeft)) * playQueue.volume;
break;
case 'linear':
currentPlayerVolumeCalculation =
(timeLeft / fadeDuration) * playQueue.volume;
currentPlayerVolumeCalculation = (timeLeft / fadeDuration) * playQueue.volume;
nextPlayerVolumeCalculation =
((fadeDuration - timeLeft) / fadeDuration) * playQueue.volume;
break;
case 'dipped':
// https://math.stackexchange.com/a/4622
percentageOfFadeLeft = timeLeft / fadeDuration;
currentPlayerVolumeCalculation =
percentageOfFadeLeft ** 2 * playQueue.volume;
nextPlayerVolumeCalculation =
(percentageOfFadeLeft - 1) ** 2 * playQueue.volume;
currentPlayerVolumeCalculation = percentageOfFadeLeft ** 2 * playQueue.volume;
nextPlayerVolumeCalculation = (percentageOfFadeLeft - 1) ** 2 * playQueue.volume;
break;
case fadeType.match(/constantPower.*/)?.input:
// https://math.stackexchange.com/a/26159
@ -126,29 +120,22 @@ const listenHandler = (
percentageOfFadeLeft = timeLeft / fadeDuration;
currentPlayerVolumeCalculation =
Math.cos(
(Math.PI / 4) *
((2 * percentageOfFadeLeft - 1) ** (2 * n + 1) - 1)
) * playQueue.volume;
Math.cos((Math.PI / 4) * ((2 * percentageOfFadeLeft - 1) ** (2 * n + 1) - 1)) *
playQueue.volume;
nextPlayerVolumeCalculation =
Math.cos(
(Math.PI / 4) *
((2 * percentageOfFadeLeft - 1) ** (2 * n + 1) + 1)
) * playQueue.volume;
Math.cos((Math.PI / 4) * ((2 * percentageOfFadeLeft - 1) ** (2 * n + 1) + 1)) *
playQueue.volume;
break;
default:
currentPlayerVolumeCalculation =
(timeLeft / fadeDuration) * playQueue.volume;
currentPlayerVolumeCalculation = (timeLeft / fadeDuration) * playQueue.volume;
nextPlayerVolumeCalculation =
((fadeDuration - timeLeft) / fadeDuration) * playQueue.volume;
break;
}
const currentPlayerVolume =
currentPlayerVolumeCalculation >= 0
? currentPlayerVolumeCalculation
: 0;
currentPlayerVolumeCalculation >= 0 ? currentPlayerVolumeCalculation : 0;
const nextPlayerVolume =
nextPlayerVolumeCalculation <= playQueue.volume
@ -223,9 +210,7 @@ const Player = ({ currentEntryList, children }: any, ref: any) => {
const [fadeDuration, setFadeDuration] = useState(playQueue.fadeDuration);
const [fadeType, setFadeType] = useState(playQueue.fadeType);
const [volumeFade, setVolumeFade] = useState(playQueue.volumeFade);
const [pollingInterval, setPollingInterval] = useState(
playQueue.pollingInterval
);
const [pollingInterval, setPollingInterval] = useState(playQueue.pollingInterval);
const getSrc1 = useCallback(() => {
const cachedSongPath = `${cachePath}/${
@ -369,16 +354,10 @@ const Player = ({ currentEntryList, children }: any, ref: any) => {
if (cacheSongs) {
cacheSong(
`${playQueue[currentEntryList][playQueue.player1.index].id}.mp3`,
playQueue[currentEntryList][playQueue.player1.index].streamUrl.replace(
/stream/,
'download'
)
playQueue[currentEntryList][playQueue.player1.index].streamUrl.replace(/stream/, 'download')
);
}
if (
playQueue.repeat === 'none' &&
playQueue.player1.index > playQueue.player2.index
) {
if (playQueue.repeat === 'none' && playQueue.player1.index > playQueue.player2.index) {
dispatch(fixPlayer2Index());
setTimeout(() => {
player1Ref.current.audioEl.current.pause();
@ -387,15 +366,10 @@ const Player = ({ currentEntryList, children }: any, ref: any) => {
} else {
if (!playQueue.autoIncremented) {
dispatch(incrementCurrentIndex('none'));
dispatch(
setCurrentIndex(playQueue[currentEntryList][playQueue.player2.index])
);
dispatch(setCurrentIndex(playQueue[currentEntryList][playQueue.player2.index]));
dispatch(setAutoIncremented(true));
}
if (
playQueue[currentEntryList].length > 1 ||
playQueue.repeat === 'all'
) {
if (playQueue[currentEntryList].length > 1 || playQueue.repeat === 'all') {
dispatch(setCurrentPlayer(2));
dispatch(incrementPlayerIndex(1));
if (fadeDuration !== 0) {
@ -414,16 +388,10 @@ const Player = ({ currentEntryList, children }: any, ref: any) => {
if (cacheSongs) {
cacheSong(
`${playQueue[currentEntryList][playQueue.player2.index].id}.mp3`,
playQueue[currentEntryList][playQueue.player2.index].streamUrl.replace(
/stream/,
'download'
)
playQueue[currentEntryList][playQueue.player2.index].streamUrl.replace(/stream/, 'download')
);
}
if (
playQueue.repeat === 'none' &&
playQueue.player2.index > playQueue.player1.index
) {
if (playQueue.repeat === 'none' && playQueue.player2.index > playQueue.player1.index) {
dispatch(fixPlayer2Index());
setTimeout(() => {
player1Ref.current.audioEl.current.pause();
@ -432,15 +400,10 @@ const Player = ({ currentEntryList, children }: any, ref: any) => {
} else {
if (!playQueue.autoIncremented) {
dispatch(incrementCurrentIndex('none'));
dispatch(
setCurrentIndex(playQueue[currentEntryList][playQueue.player1.index])
);
dispatch(setCurrentIndex(playQueue[currentEntryList][playQueue.player1.index]));
dispatch(setAutoIncremented(true));
}
if (
playQueue[currentEntryList].length > 1 ||
playQueue.repeat === 'all'
) {
if (playQueue[currentEntryList].length > 1 || playQueue.repeat === 'all') {
dispatch(setCurrentPlayer(1));
dispatch(incrementPlayerIndex(2));
if (fadeDuration !== 0) {
@ -454,25 +417,11 @@ const Player = ({ currentEntryList, children }: any, ref: any) => {
};
const handleGaplessPlayer1 = () => {
gaplessListenHandler(
player1Ref,
player2Ref,
playQueue,
1,
dispatch,
pollingInterval
);
gaplessListenHandler(player1Ref, player2Ref, playQueue, 1, dispatch, pollingInterval);
};
const handleGaplessPlayer2 = () => {
gaplessListenHandler(
player2Ref,
player1Ref,
playQueue,
2,
dispatch,
pollingInterval
);
gaplessListenHandler(player2Ref, player1Ref, playQueue, 2, dispatch, pollingInterval);
};
return (
@ -486,9 +435,7 @@ const Player = ({ currentEntryList, children }: any, ref: any) => {
src={playQueue.player1.src}
listenInterval={pollingInterval}
preload="auto"
onListen={
fadeDuration === 0 ? handleGaplessPlayer1 : handleListenPlayer1
}
onListen={fadeDuration === 0 ? handleGaplessPlayer1 : handleListenPlayer1}
onEnded={handleOnEndedPlayer1}
volume={playQueue.player1.volume}
autoPlay={
@ -500,8 +447,7 @@ const Player = ({ currentEntryList, children }: any, ref: any) => {
if (playQueue[currentEntryList].length > 0) {
console.log('player error', e);
player1Ref.current.audioEl.current.src =
'./components/player/dummy.mp3';
player1Ref.current.audioEl.current.src = './components/player/dummy.mp3';
player1Ref.current.audioEl.current.src = getSrc1();
}
}}
@ -512,9 +458,7 @@ const Player = ({ currentEntryList, children }: any, ref: any) => {
src={playQueue.player2.src}
listenInterval={pollingInterval}
preload="auto"
onListen={
fadeDuration === 0 ? handleGaplessPlayer2 : handleListenPlayer2
}
onListen={fadeDuration === 0 ? handleGaplessPlayer2 : handleListenPlayer2}
onEnded={handleOnEndedPlayer2}
volume={playQueue.player2.volume}
autoPlay={
@ -526,8 +470,7 @@ const Player = ({ currentEntryList, children }: any, ref: any) => {
if (playQueue[currentEntryList].length > 0) {
console.log('player error', e);
player2Ref.current.audioEl.current.src =
'./components/player/dummy.mp3';
player2Ref.current.audioEl.current.src = './components/player/dummy.mp3';
player2Ref.current.audioEl.current.src = getSrc2();
}
}}

155
src/components/player/PlayerBar.tsx

@ -50,9 +50,7 @@ const PlayerBar = () => {
const [isDraggingVolume, setIsDraggingVolume] = useState(false);
const [manualSeek, setManualSeek] = useState(0);
const [currentEntryList, setCurrentEntryList] = useState('entry');
const [localVolume, setLocalVolume] = useState(
Number(settings.getSync('volume'))
);
const [localVolume, setLocalVolume] = useState(Number(settings.getSync('volume')));
const playersRef = useRef<any>();
const history = useHistory();
@ -91,13 +89,7 @@ const PlayerBar = () => {
}, 200);
return () => clearTimeout(debounce);
}, [
dispatch,
isDraggingVolume,
localVolume,
playQueue.currentPlayer,
playQueue.fadeDuration,
]);
}, [dispatch, isDraggingVolume, localVolume, playQueue.currentPlayer, playQueue.fadeDuration]);
useEffect(() => {
// Set the seek back to 0 when the player is incremented/decremented, otherwise the
@ -164,9 +156,7 @@ const PlayerBar = () => {
const handleVolumeKey = (e: any) => {
if (e.keyCode === keyCodes.UP) {
const vol = Number(
(playQueue.volume + 0.05 > 1 ? 1 : playQueue.volume + 0.05).toFixed(2)
);
const vol = Number((playQueue.volume + 0.05 > 1 ? 1 : playQueue.volume + 0.05).toFixed(2));
dispatch(setVolume(vol));
dispatch(
setPlayerVolume({
@ -175,9 +165,7 @@ const PlayerBar = () => {
})
);
} else if (e.keyCode === keyCodes.DOWN) {
const vol = Number(
(playQueue.volume - 0.05 < 0 ? 0 : playQueue.volume - 0.05).toFixed(2)
);
const vol = Number((playQueue.volume - 0.05 < 0 ? 0 : playQueue.volume - 0.05).toFixed(2));
dispatch(setVolume(vol));
dispatch(
setPlayerVolume({
@ -190,9 +178,7 @@ const PlayerBar = () => {
const handleClickForward = () => {
if (playQueue[currentEntryList].length > 0) {
const seekForwardInterval = Number(
settings.getSync('seekForwardInterval')
);
const seekForwardInterval = Number(settings.getSync('seekForwardInterval'));
setIsDragging(true);
if (playQueue.isFading) {
@ -211,30 +197,20 @@ const PlayerBar = () => {
if (playQueue.currentPlayer === 1) {
const calculatedTime =
playersRef.current.player1.audioEl.current.currentTime +
seekForwardInterval;
const songDuration =
playersRef.current.player1.audioEl.current.duration;
setManualSeek(
calculatedTime > songDuration ? songDuration - 1 : calculatedTime
);
playersRef.current.player1.audioEl.current.currentTime + seekForwardInterval;
const songDuration = playersRef.current.player1.audioEl.current.duration;
setManualSeek(calculatedTime > songDuration ? songDuration - 1 : calculatedTime);
} else {
const calculatedTime =
playersRef.current.player2.audioEl.current.currentTime +
seekForwardInterval;
const songDuration =
playersRef.current.player2.audioEl.current.duration;
setManualSeek(
calculatedTime > songDuration ? songDuration - 1 : calculatedTime
);
playersRef.current.player2.audioEl.current.currentTime + seekForwardInterval;
const songDuration = playersRef.current.player2.audioEl.current.duration;
setManualSeek(calculatedTime > songDuration ? songDuration - 1 : calculatedTime);
}
}
};
const handleClickBackward = () => {
const seekBackwardInterval = Number(
settings.getSync('seekBackwardInterval')
);
const seekBackwardInterval = Number(settings.getSync('seekBackwardInterval'));
if (playQueue[currentEntryList].length > 0) {
setIsDragging(true);
@ -254,13 +230,11 @@ const PlayerBar = () => {
if (playQueue.currentPlayer === 1) {
const calculatedTime =
playersRef.current.player1.audioEl.current.currentTime -
seekBackwardInterval;
playersRef.current.player1.audioEl.current.currentTime - seekBackwardInterval;
setManualSeek(calculatedTime < 0 ? 0 : calculatedTime);
} else {
const calculatedTime =
playersRef.current.player2.audioEl.current.currentTime -
seekBackwardInterval;
playersRef.current.player2.audioEl.current.currentTime - seekBackwardInterval;
setManualSeek(calculatedTime < 0 ? 0 : calculatedTime);
}
}
@ -290,12 +264,7 @@ const PlayerBar = () => {
const handleRepeat = () => {
const currentRepeat = settings.getSync('repeat');
const newRepeat =
currentRepeat === 'none'
? 'all'
: currentRepeat === 'all'
? 'one'
: 'none';
const newRepeat = currentRepeat === 'none' ? 'all' : currentRepeat === 'all' ? 'one' : 'none';
dispatch(toggleRepeat());
settings.setSync('repeat', newRepeat);
};
@ -311,10 +280,7 @@ const PlayerBar = () => {
const handleFavorite = async () => {
if (!playQueue[currentEntryList][playQueue.currentIndex].starred) {
await star(
playQueue[currentEntryList][playQueue.currentIndex].id,
'music'
);
await star(playQueue[currentEntryList][playQueue.currentIndex].id, 'music');
dispatch(
setStar({
id: playQueue[currentEntryList][playQueue.currentIndex].id,
@ -322,10 +288,7 @@ const PlayerBar = () => {
})
);
} else {
await unstar(
playQueue[currentEntryList][playQueue.currentIndex].id,
'song'
);
await unstar(playQueue[currentEntryList][playQueue.currentIndex].id, 'song');
dispatch(
setStar({
id: playQueue[currentEntryList][playQueue.currentIndex].id,
@ -347,15 +310,10 @@ const PlayerBar = () => {
return (
<Player ref={playersRef} currentEntryList={currentEntryList}>
{playQueue.showDebugWindow && (
<DebugWindow currentEntryList={currentEntryList} />
)}
{playQueue.showDebugWindow && <DebugWindow currentEntryList={currentEntryList} />}
<PlayerContainer>
<FlexboxGrid align="middle" style={{ height: '100%' }}>
<FlexboxGrid.Item
colspan={6}
style={{ textAlign: 'left', paddingLeft: '10px' }}
>
<FlexboxGrid.Item colspan={6} style={{ textAlign: 'left', paddingLeft: '10px' }}>
<PlayerColumn left height="80px">
<Grid>
<Row
@ -370,8 +328,8 @@ const PlayerBar = () => {
<LazyLoadImage
tabIndex={0}
src={
playQueue[currentEntryList][playQueue.currentIndex]
?.image || placeholderImg
playQueue[currentEntryList][playQueue.currentIndex]?.image ||
placeholderImg
}
alt="trackImg"
effect="opacity"
@ -400,30 +358,24 @@ const PlayerBar = () => {
enterable
placement="topStart"
text={
playQueue[currentEntryList][playQueue.currentIndex]
?.title || 'Unknown title'
playQueue[currentEntryList][playQueue.currentIndex]?.title ||
'Unknown title'
}
>
<LinkButton
tabIndex={0}
onClick={() => {
if (
playQueue[currentEntryList][
playQueue.currentIndex
]?.albumId
) {
if (playQueue[currentEntryList][playQueue.currentIndex]?.albumId) {
history.push(
`/library/album/${
playQueue[currentEntryList][
playQueue.currentIndex
]?.albumId
playQueue[currentEntryList][playQueue.currentIndex]?.albumId
}`
);
}
}}
>
{playQueue[currentEntryList][playQueue.currentIndex]
?.title || 'Unknown title'}
{playQueue[currentEntryList][playQueue.currentIndex]?.title ||
'Unknown title'}
</LinkButton>
</CustomTooltip>
</Row>
@ -439,8 +391,8 @@ const PlayerBar = () => {
enterable
placement="topStart"
text={
playQueue[currentEntryList][playQueue.currentIndex]
?.artist || 'Unknown artist'
playQueue[currentEntryList][playQueue.currentIndex]?.artist ||
'Unknown artist'
}
>
<span
@ -454,23 +406,17 @@ const PlayerBar = () => {
tabIndex={0}
subtitle="true"
onClick={() => {
if (
playQueue[currentEntryList][
playQueue.currentIndex
]?.artistId
) {
if (playQueue[currentEntryList][playQueue.currentIndex]?.artistId) {
history.push(
`/library/artist/${
playQueue[currentEntryList][
playQueue.currentIndex
]?.artistId
playQueue[currentEntryList][playQueue.currentIndex]?.artistId
}`
);
}
}}
>
{playQueue[currentEntryList][playQueue.currentIndex]
?.artist || 'Unknown artist'}
{playQueue[currentEntryList][playQueue.currentIndex]?.artist ||
'Unknown artist'}
</LinkButton>
</span>
</CustomTooltip>
@ -480,10 +426,7 @@ const PlayerBar = () => {
</Grid>
</PlayerColumn>
</FlexboxGrid.Item>
<FlexboxGrid.Item
colspan={12}
style={{ textAlign: 'center', verticalAlign: 'middle' }}
>
<FlexboxGrid.Item colspan={12} style={{ textAlign: 'center', verticalAlign: 'middle' }}>
<PlayerColumn center height="45px">
{/* Seek Backward Button */}
<CustomTooltip text="Seek backward" delay