From e0f6ddad4295c86e742403a9375d24726088c64e Mon Sep 17 00:00:00 2001 From: jeffvli Date: Fri, 5 Nov 2021 07:15:58 -0700 Subject: [PATCH] Handle individual page column sorts --- src/components/library/AlbumList.tsx | 1 + src/components/library/AlbumView.tsx | 1 + src/components/library/ArtistList.tsx | 1 + src/components/library/ArtistView.tsx | 1 + src/components/library/FolderList.tsx | 1 + src/components/library/GenreList.tsx | 1 + src/components/playlist/PlaylistList.tsx | 1 + src/components/starred/StarredView.tsx | 3 ++ src/components/viewtypes/ListViewTable.tsx | 38 ++++++++++++++++++++-- src/components/viewtypes/ListViewType.tsx | 2 ++ 10 files changed, 48 insertions(+), 2 deletions(-) diff --git a/src/components/library/AlbumList.tsx b/src/components/library/AlbumList.tsx index e1525af..c086ae0 100644 --- a/src/components/library/AlbumList.tsx +++ b/src/components/library/AlbumList.tsx @@ -209,6 +209,7 @@ const AlbumList = () => { cacheType: 'album', cacheIdProperty: 'albumId', }} + page="albumListPage" listType="album" virtualized disabledContextMenuOptions={[ diff --git a/src/components/library/AlbumView.tsx b/src/components/library/AlbumView.tsx index 28f7bed..70488dd 100644 --- a/src/components/library/AlbumView.tsx +++ b/src/components/library/AlbumView.tsx @@ -356,6 +356,7 @@ const AlbumView = ({ ...rest }: any) => { cacheType: 'album', cacheIdProperty: 'albumId', }} + page="albumPage" listType="music" isModal={rest.isModal} disabledContextMenuOptions={[ diff --git a/src/components/library/ArtistList.tsx b/src/components/library/ArtistList.tsx index 6e2d39f..11b47ea 100644 --- a/src/components/library/ArtistList.tsx +++ b/src/components/library/ArtistList.tsx @@ -138,6 +138,7 @@ const ArtistList = () => { cacheType: 'artist', cacheIdProperty: 'id', }} + page="artistListPage" listType="artist" virtualized disabledContextMenuOptions={[ diff --git a/src/components/library/ArtistView.tsx b/src/components/library/ArtistView.tsx index 2d1f4ad..146cb54 100644 --- a/src/components/library/ArtistView.tsx +++ b/src/components/library/ArtistView.tsx @@ -378,6 +378,7 @@ const ArtistView = ({ ...rest }: any) => { cacheType: 'album', cacheIdProperty: 'albumId', }} + page="artistPage" listType="album" isModal={rest.isModal} disabledContextMenuOptions={[ diff --git a/src/components/library/FolderList.tsx b/src/components/library/FolderList.tsx index 197be7e..5df3afa 100644 --- a/src/components/library/FolderList.tsx +++ b/src/components/library/FolderList.tsx @@ -227,6 +227,7 @@ const FolderList = () => { cacheType: 'folder', cacheIdProperty: 'albumId', }} + page="folderListPage" listType="folder" virtualized disabledContextMenuOptions={[ diff --git a/src/components/library/GenreList.tsx b/src/components/library/GenreList.tsx index ca458a9..58e020b 100644 --- a/src/components/library/GenreList.tsx +++ b/src/components/library/GenreList.tsx @@ -80,6 +80,7 @@ const GenreList = () => { fontSize={config.lookAndFeel.listView.genre.fontSize} handleRowClick={handleRowClick} handleRowDoubleClick={handleRowDoubleClick} + page="genreListPage" listType="genre" virtualized disabledContextMenuOptions={[ diff --git a/src/components/playlist/PlaylistList.tsx b/src/components/playlist/PlaylistList.tsx index edcf999..bb6d76d 100644 --- a/src/components/playlist/PlaylistList.tsx +++ b/src/components/playlist/PlaylistList.tsx @@ -161,6 +161,7 @@ const PlaylistList = () => { cacheType: 'playlist', cacheIdProperty: 'id', }} + page="playlistListPage" listType="playlist" virtualized disabledContextMenuOptions={[ diff --git a/src/components/starred/StarredView.tsx b/src/components/starred/StarredView.tsx index 4218803..bc88824 100644 --- a/src/components/starred/StarredView.tsx +++ b/src/components/starred/StarredView.tsx @@ -191,6 +191,7 @@ const StarredView = () => { cacheType: 'album', cacheIdProperty: 'albumId', }} + page="favoriteTracksPage" listType="music" virtualized disabledContextMenuOptions={[ @@ -217,6 +218,7 @@ const StarredView = () => { cacheType: 'album', cacheIdProperty: 'albumId', }} + page="favoriteAlbumsPage" listType="album" virtualized disabledContextMenuOptions={[ @@ -264,6 +266,7 @@ const StarredView = () => { cacheType: 'artist', cacheIdProperty: 'id', }} + page="favoriteArtistsPage" listType="artist" virtualized disabledContextMenuOptions={[ diff --git a/src/components/viewtypes/ListViewTable.tsx b/src/components/viewtypes/ListViewTable.tsx index 3102ec2..38cea90 100644 --- a/src/components/viewtypes/ListViewTable.tsx +++ b/src/components/viewtypes/ListViewTable.tsx @@ -46,7 +46,12 @@ import { } from '../../redux/multiSelectSlice'; import CustomTooltip from '../shared/CustomTooltip'; import { sortPlaylist } from '../../redux/playlistSlice'; -import { removePlaybackFilter, setColumnList, setPlaybackFilter } from '../../redux/configSlice'; +import { + removePlaybackFilter, + setColumnList, + setPageSort, + setPlaybackFilter, +} from '../../redux/configSlice'; import { setActive } from '../../redux/albumSlice'; import { resetPlayer, setStatus } from '../../redux/playerSlice'; @@ -89,6 +94,7 @@ const ListViewTable = ({ multiSelect, cacheImages, autoHeight, + page, listType, isModal, // onScroll, @@ -139,6 +145,16 @@ const ListViewTable = ({ sortType: type, }) ); + } else if (page) { + dispatch( + setPageSort({ + page, + sort: { + sortColumn: column, + sortType: type, + }, + }) + ); } if (column === (nowPlaying ? playQueue.sortColumn : sortColumn)) { @@ -152,6 +168,16 @@ const ListViewTable = ({ sortType: 'asc', }) ); + } else if (page) { + dispatch( + setPageSort({ + page, + sort: { + sortColumn: undefined, + sortType: 'asc', + }, + }) + ); } setSortColumn(undefined); @@ -211,6 +237,14 @@ const ListViewTable = ({ useEffect(() => { if (!nowPlaying) { + if (page === 'favoritePage') { + setSortColumn(configState.sort[page.split('.')[0]][page.split('.')[1]]?.sortColumn); + setSortType(configState.sort[page.split('.')[0]][page.split('.')[1]]?.sortType); + } else if (page) { + setSortColumn(configState.sort[page]?.sortColumn); + setSortType(configState.sort[page]?.sortType); + } + if (sortColumn && sortType) { // Since the column title(id) won't always match the actual column dataKey, we need to match it const normalizedSortColumn = columns.find((c: any) => c.id === sortColumn); @@ -232,7 +266,7 @@ const ListViewTable = ({ setSortedData(data); } } - }, [columns, data, nowPlaying, sortColumn, sortType]); + }, [columns, configState.sort, data, nowPlaying, page, sortColumn, sortType]); useEffect(() => { if (nowPlaying) { diff --git a/src/components/viewtypes/ListViewType.tsx b/src/components/viewtypes/ListViewType.tsx index fb6c8a8..ad60f45 100644 --- a/src/components/viewtypes/ListViewType.tsx +++ b/src/components/viewtypes/ListViewType.tsx @@ -25,6 +25,7 @@ const ListViewType = ( fontSize, cacheImages, children, + page, listType, isModal, handleDragEnd, @@ -325,6 +326,7 @@ const ListViewType = ( playQueue={playQueue} multiSelect={multiSelect} cacheImages={cacheImages} + page={page} listType={listType} nowPlaying={rest.nowPlaying} playlist={rest.playlist}