|
@ -20,25 +20,24 @@ import { |
|
|
} from '../../redux/multiSelectSlice'; |
|
|
} from '../../redux/multiSelectSlice'; |
|
|
import { StyledInputPicker } from '../shared/styled'; |
|
|
import { StyledInputPicker } from '../shared/styled'; |
|
|
import { RefreshButton } from '../shared/ToolbarButtons'; |
|
|
import { RefreshButton } from '../shared/ToolbarButtons'; |
|
|
import useRouterQuery from '../../hooks/useRouterQuery'; |
|
|
import { setActive } from '../../redux/albumSlice'; |
|
|
|
|
|
|
|
|
const ALBUM_SORT_TYPES = [ |
|
|
const ALBUM_SORT_TYPES = [ |
|
|
{ label: 'A-Z (Name)', value: 'alphabeticalByName', role: 'Default' }, |
|
|
{ label: 'A-Z (Name)', value: 'alphabeticalByName', role: 'Default' }, |
|
|
{ label: 'A-Z (Artist)', value: 'alphabeticalByArtist', role: 'Default' }, |
|
|
{ label: 'A-Z (Artist)', value: 'alphabeticalByArtist', role: 'Default' }, |
|
|
{ label: 'Most Played', value: 'frequent', role: 'Default' }, |
|
|
{ label: 'Most Played', value: 'frequent', role: 'Default' }, |
|
|
{ label: 'Newly Added', value: 'newest', role: 'Default' }, |
|
|
|
|
|
{ label: 'Random', value: 'random', role: 'Default' }, |
|
|
{ label: 'Random', value: 'random', role: 'Default' }, |
|
|
|
|
|
{ label: 'Recently Added', value: 'newest', role: 'Default' }, |
|
|
{ label: 'Recently Played', value: 'recent', role: 'Default' }, |
|
|
{ label: 'Recently Played', value: 'recent', role: 'Default' }, |
|
|
]; |
|
|
]; |
|
|
|
|
|
|
|
|
const AlbumList = () => { |
|
|
const AlbumList = () => { |
|
|
const dispatch = useAppDispatch(); |
|
|
const dispatch = useAppDispatch(); |
|
|
const history = useHistory(); |
|
|
const history = useHistory(); |
|
|
const query = useRouterQuery(); |
|
|
|
|
|
const queryClient = useQueryClient(); |
|
|
const queryClient = useQueryClient(); |
|
|
const folder = useAppSelector((state) => state.folder); |
|
|
const folder = useAppSelector((state) => state.folder); |
|
|
|
|
|
const album = useAppSelector((state) => state.album); |
|
|
const [isRefreshing, setIsRefreshing] = useState(false); |
|
|
const [isRefreshing, setIsRefreshing] = useState(false); |
|
|
const [sortBy, setSortBy] = useState(query.get('sortType') || 'random'); |
|
|
|
|
|
const [sortTypes, setSortTypes] = useState<any[]>(); |
|
|
const [sortTypes, setSortTypes] = useState<any[]>(); |
|
|
const [viewType, setViewType] = useState(settings.getSync('albumViewType')); |
|
|
const [viewType, setViewType] = useState(settings.getSync('albumViewType')); |
|
|
const [musicFolder, setMusicFolder] = useState(undefined); |
|
|
const [musicFolder, setMusicFolder] = useState(undefined); |
|
@ -50,16 +49,16 @@ const AlbumList = () => { |
|
|
}, [folder]); |
|
|
}, [folder]); |
|
|
|
|
|
|
|
|
const { isLoading, isError, data: albums, error }: any = useQuery( |
|
|
const { isLoading, isError, data: albums, error }: any = useQuery( |
|
|
['albumList', sortBy, musicFolder], |
|
|
['albumList', album.active.filter, musicFolder], |
|
|
() => |
|
|
() => |
|
|
sortBy === 'random' |
|
|
album.active.filter === 'random' |
|
|
? getAlbumsDirect({ |
|
|
? getAlbumsDirect({ |
|
|
type: 'random', |
|
|
type: 'random', |
|
|
size: Number(settings.getSync('gridCardSize')), |
|
|
size: Number(settings.getSync('gridCardSize')), |
|
|
musicFolderId: musicFolder, |
|
|
musicFolderId: musicFolder, |
|
|
}) |
|
|
}) |
|
|
: getAllAlbums({ |
|
|
: getAllAlbums({ |
|
|
type: sortBy, |
|
|
type: album.active.filter, |
|
|
size: 500, |
|
|
size: 500, |
|
|
offset: 0, |
|
|
offset: 0, |
|
|
musicFolderId: musicFolder, |
|
|
musicFolderId: musicFolder, |
|
@ -127,7 +126,7 @@ const AlbumList = () => { |
|
|
const handleRowFavorite = async (rowData: any) => { |
|
|
const handleRowFavorite = async (rowData: any) => { |
|
|
if (!rowData.starred) { |
|
|
if (!rowData.starred) { |
|
|
await star(rowData.id, 'album'); |
|
|
await star(rowData.id, 'album'); |
|
|
queryClient.setQueryData(['albumList', sortBy, musicFolder], (oldData: any) => { |
|
|
queryClient.setQueryData(['albumList', album.active.filter, musicFolder], (oldData: any) => { |
|
|
const starredIndices = _.keys(_.pickBy(oldData, { id: rowData.id })); |
|
|
const starredIndices = _.keys(_.pickBy(oldData, { id: rowData.id })); |
|
|
starredIndices.forEach((index) => { |
|
|
starredIndices.forEach((index) => { |
|
|
oldData[index].starred = Date.now(); |
|
|
oldData[index].starred = Date.now(); |
|
@ -137,7 +136,7 @@ const AlbumList = () => { |
|
|
}); |
|
|
}); |
|
|
} else { |
|
|
} else { |
|
|
await unstar(rowData.id, 'album'); |
|
|
await unstar(rowData.id, 'album'); |
|
|
queryClient.setQueryData(['albumList', sortBy, musicFolder], (oldData: any) => { |
|
|
queryClient.setQueryData(['albumList', album.active.filter, musicFolder], (oldData: any) => { |
|
|
const starredIndices = _.keys(_.pickBy(oldData, { id: rowData.id })); |
|
|
const starredIndices = _.keys(_.pickBy(oldData, { id: rowData.id })); |
|
|
starredIndices.forEach((index) => { |
|
|
starredIndices.forEach((index) => { |
|
|
oldData[index].starred = undefined; |
|
|
oldData[index].starred = undefined; |
|
@ -159,15 +158,15 @@ const AlbumList = () => { |
|
|
<StyledInputPicker |
|
|
<StyledInputPicker |
|
|
size="sm" |
|
|
size="sm" |
|
|
width={180} |
|
|
width={180} |
|
|
defaultValue={sortBy} |
|
|
defaultValue={album.active.filter} |
|
|
groupBy="role" |
|
|
groupBy="role" |
|
|
data={sortTypes} |
|
|
data={sortTypes} |
|
|
cleanable={false} |
|
|
cleanable={false} |
|
|
placeholder="Sort Type" |
|
|
placeholder="Sort Type" |
|
|
onChange={async (value: string) => { |
|
|
onChange={async (value: string) => { |
|
|
await queryClient.cancelQueries(['albumList', sortBy, musicFolder]); |
|
|
await queryClient.cancelQueries(['albumList', album.active.filter, musicFolder]); |
|
|
setSearchQuery(''); |
|
|
setSearchQuery(''); |
|
|
setSortBy(value); |
|
|
dispatch(setActive({ filter: value })); |
|
|
}} |
|
|
}} |
|
|
/> |
|
|
/> |
|
|
<RefreshButton onClick={handleRefresh} size="sm" loading={isRefreshing} width={100} /> |
|
|
<RefreshButton onClick={handleRefresh} size="sm" loading={isRefreshing} width={100} /> |
|
|