From f53f31038756fe5238778bf12f3e43ecb2ea5671 Mon Sep 17 00:00:00 2001 From: jeffvli Date: Fri, 17 Sep 2021 05:19:58 -0700 Subject: [PATCH] update playlist endpoints --- src/api/api.ts | 21 ++++++++++++++++++--- src/components/playlist/PlaylistList.tsx | 2 +- 2 files changed, 19 insertions(+), 4 deletions(-) diff --git a/src/api/api.ts b/src/api/api.ts index 86265e2..877b9db 100644 --- a/src/api/api.ts +++ b/src/api/api.ts @@ -120,6 +120,16 @@ export const getPlaylists = async (sortBy: string) => { ? data.playlists?.playlist.sort((a: any, b: any) => { return a.changed > b.changed ? -1 : a.changed < b.changed ? 1 : 0; }) + : sortBy === 'name' + ? data.playlists?.playlist.sort((a: any, b: any) => { + if (a.name < b.name) { + return -1; + } + if (a.name > b.name) { + return 1; + } + return 0; + }) : data.playlists?.playlist; return (newData || []).map((playlist: any) => ({ @@ -499,6 +509,7 @@ export const populatePlaylist = async (id: string, entry: any[]) => { // Set these in chunks so the api doesn't break const entryIdChunks = _.chunk(entryIds, 325); + let data; for (let i = 0; i < entryIdChunks.length; i += 1) { const params = new URLSearchParams(); @@ -511,8 +522,12 @@ export const populatePlaylist = async (id: string, entry: any[]) => { params.append('songIdToAdd', String(entryIdChunks[i][x])); } - await playlistApi.get(`/updatePlaylist`, { - params, - }); + data = ( + await playlistApi.get(`/updatePlaylist`, { + params, + }) + ).data; } + + return data; }; diff --git a/src/components/playlist/PlaylistList.tsx b/src/components/playlist/PlaylistList.tsx index e93e34d..dddaeaa 100644 --- a/src/components/playlist/PlaylistList.tsx +++ b/src/components/playlist/PlaylistList.tsx @@ -13,7 +13,7 @@ import GridViewType from '../viewtypes/GridViewType'; const PlaylistList = () => { const history = useHistory(); - const [sortBy] = useState(''); + const [sortBy] = useState('name'); const [viewType, setViewType] = useState( settings.getSync('playlistViewType') || 'list' );