From 25d6ca82549229e1bbdc41f2c69cb5dc76116e0e Mon Sep 17 00:00:00 2001 From: Gireesh Date: Sun, 6 Oct 2024 18:54:00 +0530 Subject: [PATCH 1/2] Code cleanu and issue fixes --- src/g-player-react/src/Components/main.scss | 3 +- .../src/Components/playlist/Playlists.js | 11 +++-- .../playlist/PlayllistSelectorV2.js | 7 ++- .../src/Components/redux/GPActionTypes.js | 16 ++++++- .../src/Components/screen/GroupBand.js | 2 +- .../src/Components/screen/album/AlbumList.js | 44 +++++-------------- .../src/Components/screen/album/Albums.js | 6 +-- .../src/Components/screen/album/albumUtil.js | 28 ++++++++++++ .../Components/screen/artist/ArtistsList.js | 12 +++-- .../src/Components/screen/genre/Genres.js | 2 +- .../Components/screen/language/Languages.js | 34 +++++++++++++- .../src/Components/screen/lyrics/Lyrics.js | 3 +- .../screen/metadata/EditAlbumInfo.js | 15 ++++--- .../src/Components/utilities/util.js | 16 ++++++- .../com/gmt/gp/services/PlaylistService.java | 13 +++++- 15 files changed, 148 insertions(+), 64 deletions(-) create mode 100644 src/g-player-react/src/Components/screen/album/albumUtil.js diff --git a/src/g-player-react/src/Components/main.scss b/src/g-player-react/src/Components/main.scss index b6257b6..02abf61 100644 --- a/src/g-player-react/src/Components/main.scss +++ b/src/g-player-react/src/Components/main.scss @@ -1791,7 +1791,7 @@ a.disabled-click{ flex-direction: column; row-gap: 5px; margin-right: 1.5em; - background: #253434; + background: #560C53; box-shadow: rgb(0 0 0 / 25%) 0px 54px 55px, rgb(0 0 0 / 12%) 0px -12px 30px, rgb(0 0 0 / 12%) 0px 4px 6px, rgb(0 0 0 / 17%) 0px 12px 13px, rgb(0 0 0 / 9%) 0px -3px 5px; position: relative; overflow: hidden; @@ -2988,6 +2988,7 @@ a.disabled-click{ } .row.song-path{ + >label{width: 150px;} grid-column: span 2; display: flex; flex-direction: row; diff --git a/src/g-player-react/src/Components/playlist/Playlists.js b/src/g-player-react/src/Components/playlist/Playlists.js index c6a5578..167a926 100644 --- a/src/g-player-react/src/Components/playlist/Playlists.js +++ b/src/g-player-react/src/Components/playlist/Playlists.js @@ -4,7 +4,7 @@ import { Link } from "react-router-dom"; import { useDispatch, useSelector } from "react-redux"; import { PlaylistImg } from "./PlaylistImg"; import { ImportExportPlaylistBtn } from "./ImportExportPlaylistBtn"; -import { CURRENT_PAGE, DELETE_LABEL, DELETE_PLAYLIST_CONF_TEXT, DELETE_PLAYLIST_LABEL, PLAYLISTS, REMOVE, SORT_A_TO_Z, SORT_A_TO_Z_DESC, SORT_COUNT_TRACKS, SORT_CREATED_DATE_NEW, SORT_CREATED_DATE_OLD, TEXT } from "../redux/GPActionTypes"; +import { CURRENT_PAGE, PLAYLISTS, SORT_A_TO_Z, SORT_A_TO_Z_DESC, SORT_COUNT_TRACKS, SORT_CREATED_DATE_NEW, SORT_CREATED_DATE_OLD, SORT_UPDATED_DATE_NEW, SORT_UPDATED_DATE_OLD } from "../redux/GPActionTypes"; import { setCookies } from "../utilities/util"; import { SortingContainer } from "../screen/SortingContainer"; import { ThumbnailActionBtn } from "../ThumbnailActionBtn"; @@ -19,7 +19,7 @@ export const Playlists = () => { const playlistAlbums = useSelector(state => state.playlist.playlistAlbums); const playlistSongsCount = useSelector(state => state.playlist.playlistSongsCount); - const [sortBy, setSortBy] = useState(SORT_CREATED_DATE_NEW); + const [sortBy, setSortBy] = useState(SORT_UPDATED_DATE_NEW); const globalFilterText = useSelector(state => state.library.globalFilterText); @@ -40,6 +40,10 @@ export const Playlists = () => { tempPlaylists = tempPlaylists.sort((a,b)=>{return new Date(a.createdDate)>new Date(b.createdDate)?-1:1}); }else if(sortBy === SORT_CREATED_DATE_OLD){ tempPlaylists = tempPlaylists.sort((a,b)=>{return new Date(a.createdDate)>new Date(b.createdDate)?1:-1}); + }else if(sortBy === SORT_UPDATED_DATE_NEW){ + tempPlaylists = tempPlaylists.sort((a,b)=>{return new Date(a.lastUpdated)>new Date(b.lastUpdated)?-1:1}); + }else if(sortBy === SORT_UPDATED_DATE_OLD){ + tempPlaylists = tempPlaylists.sort((a,b)=>{return new Date(a.lastUpdated)>new Date(b.lastUpdated)?1:-1}); }else if(sortBy === SORT_COUNT_TRACKS){ tempPlaylists = tempPlaylists.sort((a,b)=>{return playlistSongsCount[a.id]>playlistSongsCount[b.id]?-1:1}) } @@ -77,8 +81,9 @@ export const Playlists = () => { showLKey={false} sortSelectors={ [ + SORT_UPDATED_DATE_NEW, SORT_CREATED_DATE_NEW, - SORT_CREATED_DATE_OLD, + SORT_UPDATED_DATE_OLD, SORT_COUNT_TRACKS, SORT_A_TO_Z, SORT_A_TO_Z_DESC, diff --git a/src/g-player-react/src/Components/playlist/PlayllistSelectorV2.js b/src/g-player-react/src/Components/playlist/PlayllistSelectorV2.js index fc53255..04308f5 100644 --- a/src/g-player-react/src/Components/playlist/PlayllistSelectorV2.js +++ b/src/g-player-react/src/Components/playlist/PlayllistSelectorV2.js @@ -16,6 +16,11 @@ export const PlaylistSelector = () => { const [styles, setStyles] = useState({display:'none'}); const [obj, setobj] = useState(null); + const [displayPlaylists, setDisplayPlaylists] = useState([]); + + useEffect(()=>{ + setDisplayPlaylists(playLists?.sort((a,b)=>a.name>b.name?1:-1)) + },[playLists]) useEffect(()=>{ if(contextObj.type === TRACK){ @@ -126,7 +131,7 @@ export const PlaylistSelector = () => { {obj && obj.title+" - "+obj.album} - {playLists && playLists.map(playlist => + {displayPlaylists && displayPlaylists.map(playlist =>
handleOnPlaylistClick(playlist.id,playlist.name)} title={playlist.name}>
diff --git a/src/g-player-react/src/Components/redux/GPActionTypes.js b/src/g-player-react/src/Components/redux/GPActionTypes.js index 39c95b4..64f47fe 100644 --- a/src/g-player-react/src/Components/redux/GPActionTypes.js +++ b/src/g-player-react/src/Components/redux/GPActionTypes.js @@ -151,6 +151,8 @@ export const SORT_TRACK_NUMBER = 'SORT_TRACK_NUMBER'; export const SORT_YEAR = 'SORT_YEAR'; export const SORT_CREATED_DATE_NEW = 'SORT_CREATED_DATE_NEW'; export const SORT_CREATED_DATE_OLD = 'SORT_CREATED_DATE_OLD'; +export const SORT_UPDATED_DATE_NEW = 'SORT_UPDATED_DATE_NEW'; +export const SORT_UPDATED_DATE_OLD = 'SORT_UPDATED_DATE_OLD'; export const SUCCESS = 'SUCCESS'; export const THIS_MONTH_COUNT = 'THIS_MONTH_COUNT'; @@ -245,7 +247,19 @@ export const GP_SORT_SELECTOR_LABEL_MAPPING = { SORT_NONE : 'None', SORT_YEAR : "Year", SORT_TRACK_NUMBER: 'Track Number', - SORT_CREATED_DATE_NEW: 'Latest', + SORT_CREATED_DATE_NEW: 'New', SORT_CREATED_DATE_OLD: 'Old', + SORT_UPDATED_DATE_NEW: 'Last Modified', + SORT_UPDATED_DATE_OLD: 'First Modified', SORT_PLAY_COUNT: 'Play Count' +} + +export const GP_SORTING_KEY_MAPPING = { + SORT_A_TO_Z:1, + SORT_A_TO_Z_DESC:-1, + SORT_COUNT_TRACKS:-1, + SORT_CREATED_DATE_NEW:1, + SORT_CREATED_DATE_OLD:-1, + SORT_UPDATED_DATE_NEW:1, + SORT_UPDATED_DATE_OLD:-1 } \ No newline at end of file diff --git a/src/g-player-react/src/Components/screen/GroupBand.js b/src/g-player-react/src/Components/screen/GroupBand.js index c32a55c..9398f42 100644 --- a/src/g-player-react/src/Components/screen/GroupBand.js +++ b/src/g-player-react/src/Components/screen/GroupBand.js @@ -51,7 +51,7 @@ export const GroupBand = () => {

{LANGUAGES_LABEL}

- {[TRACKS, ALBUMS].includes(selectedBand) && } + {[TRACKS, ALBUMS, ARTISTS].includes(selectedBand) && } ); } \ No newline at end of file diff --git a/src/g-player-react/src/Components/screen/album/AlbumList.js b/src/g-player-react/src/Components/screen/album/AlbumList.js index 9a3011d..0926f0a 100644 --- a/src/g-player-react/src/Components/screen/album/AlbumList.js +++ b/src/g-player-react/src/Components/screen/album/AlbumList.js @@ -1,10 +1,10 @@ import React, { useEffect, useState } from "react"; -import { useDispatch, useSelector } from "react-redux"; -import { A_TO_Z_DESC, CURRENT_PAGE, GP_ALBUMS_SORT_FIELD_MAPPING, LANGUAGE, MULTI_LINGUAL, NONE, NO_SORT, SOME_PAGE, SORT_ARTIST, SORT_NONE, SORT_YEAR } from "../../redux/GPActionTypes"; -import { fetchAllAlbums } from "../../redux/library/LibraryActions"; +import { useSelector } from "react-redux"; +import { CURRENT_PAGE, GP_ALBUMS_SORT_FIELD_MAPPING, NO_SORT, SOME_PAGE, SORT_YEAR } from "../../redux/GPActionTypes"; import { replace_AndCamelize, setCookies, sortGroupByField } from "../../utilities/util"; import { AlbumThumb } from "./AlbumThumb"; import { SortingContainer } from "../SortingContainer"; +import { filterAlbums, sortAlbumKeys } from "./albumUtil"; export const AlbumList = ({albums, albumListInp}) => { @@ -20,6 +20,10 @@ export const AlbumList = ({albums, albumListInp}) => { setCookies(CURRENT_PAGE, JSON.stringify({type:SOME_PAGE})); },[]); + useEffect(()=>{ + albumListInp && albumListInp.selectedSortBy ? setSortBy(albumListInp.selectedSortBy) : setSortBy(NO_SORT); + },[albumListInp]); + useEffect(()=>{ if(sortBy && albums.length>0){ setAlbumListKeys([]); @@ -27,40 +31,16 @@ export const AlbumList = ({albums, albumListInp}) => { } },[sortBy]); - useEffect(()=>{ - albumListInp && albumListInp.selectedSortBy ? setSortBy(albumListInp.selectedSortBy) : setSortBy(NO_SORT); - },[albumListInp]) - useEffect(()=>{ if(Object.keys(sortedAlbums).length>0){ - let tempAlbumListKeys = Object.keys(sortedAlbums); - if(sortBy===SORT_YEAR || sortBy===A_TO_Z_DESC){ - tempAlbumListKeys = tempAlbumListKeys.sort((a,b)=>{return a>b?-1:1}); - } - if(sortBy===SORT_ARTIST){ - tempAlbumListKeys = tempAlbumListKeys.sort((a,b)=>{return a>b?1:-1}); - } - setAlbumListKeys(tempAlbumListKeys); + setAlbumListKeys(sortAlbumKeys(sortBy, sortedAlbums)); setFilteredAlbums(sortedAlbums); } - },[sortedAlbums]) + },[sortedAlbums]); useEffect(() => { - //console.log("globalFilterText",globalFilterText) if (globalFilterText && globalFilterText.length > 2) { - let tempFilteredAlbums = []; - let filteredAlbums = {}; - albumListKeys.forEach(lKey =>{ - tempFilteredAlbums = sortedAlbums[lKey]; - tempFilteredAlbums = tempFilteredAlbums.filter(album => { - return album.albumName.toLowerCase().includes(globalFilterText) - || album.year === globalFilterText - || album.genre.toLowerCase().includes(globalFilterText) - || album.albumArtist.toLowerCase().includes(globalFilterText) - }); - filteredAlbums[lKey] = tempFilteredAlbums; - }) - setFilteredAlbums(filteredAlbums); + setFilteredAlbums(filterAlbums(globalFilterText, sortedAlbums, albumListKeys)); setFilterActive(true); } else { setFilteredAlbums(sortedAlbums) @@ -71,9 +51,9 @@ export const AlbumList = ({albums, albumListInp}) => {
{albumListInp.showSort && !isFilterActive && }
- {albumListKeys !== undefined && albumListKeys.length > 0 && albumListKeys.map((lKey, index) => + {albumListKeys && albumListKeys.length > 0 && albumListKeys.map((lKey, index) => <> - {!isFilterActive && albumListInp.showLKey && } + {!isFilterActive && albumListInp.showLKey && } {filteredAlbums[lKey] !== undefined && filteredAlbums[lKey].length > 0 && filteredAlbums[lKey].map((album, albumIndex) => )} diff --git a/src/g-player-react/src/Components/screen/album/Albums.js b/src/g-player-react/src/Components/screen/album/Albums.js index 93d1c10..6ad351f 100644 --- a/src/g-player-react/src/Components/screen/album/Albums.js +++ b/src/g-player-react/src/Components/screen/album/Albums.js @@ -1,10 +1,8 @@ import React, { useEffect, useState } from "react"; import { useDispatch, useSelector } from "react-redux"; -import { A_TO_Z, A_TO_Z_DESC, CURRENT_PAGE, GP_ALBUMS_SORT_FIELD_MAPPING, LANGUAGE, MULTI_LINGUAL, SOME_PAGE, SORT_ARTIST, SORT_A_TO_Z, SORT_A_TO_Z_DESC, SORT_LANGUAGE, SORT_MULTI_LINGUAL, SORT_YEAR } from "../../redux/GPActionTypes"; +import { CURRENT_PAGE, SOME_PAGE, SORT_ARTIST, SORT_A_TO_Z, SORT_A_TO_Z_DESC, SORT_LANGUAGE, SORT_MULTI_LINGUAL, SORT_YEAR } from "../../redux/GPActionTypes"; import { fetchAllAlbums } from "../../redux/library/LibraryActions"; -import { camelize, replace_AndCamelize, setCookies, sortGroupByField } from "../../utilities/util"; -import { AlbumThumb } from "./AlbumThumb"; -import { SortingContainer } from "../SortingContainer"; +import { setCookies } from "../../utilities/util"; import { Spinner } from "../../utilities/Spinner"; import { AlbumList } from "./AlbumList"; diff --git a/src/g-player-react/src/Components/screen/album/albumUtil.js b/src/g-player-react/src/Components/screen/album/albumUtil.js new file mode 100644 index 0000000..324cdff --- /dev/null +++ b/src/g-player-react/src/Components/screen/album/albumUtil.js @@ -0,0 +1,28 @@ +import { A_TO_Z_DESC, SORT_ARTIST, SORT_YEAR } from "../../redux/GPActionTypes"; + +export const filterAlbums = (globalFilterText, sortedAlbums, albumListKeys) => { + let tempFilteredAlbums = []; + let filteredAlbums = {}; + albumListKeys.forEach(lKey =>{ + tempFilteredAlbums = sortedAlbums[lKey]; + tempFilteredAlbums = tempFilteredAlbums.filter(album => { + return album.albumName.toLowerCase().includes(globalFilterText) + || album.year === globalFilterText + || album.genre.toLowerCase().includes(globalFilterText) + || album.albumArtist.toLowerCase().includes(globalFilterText) + }); + filteredAlbums[lKey] = tempFilteredAlbums; + }) + return filteredAlbums; +} + +export const sortAlbumKeys = (sortBy, sortedAlbums) => { + let tempAlbumListKeys = Object.keys(sortedAlbums); + if (sortBy === SORT_YEAR || sortBy === A_TO_Z_DESC) { + tempAlbumListKeys = tempAlbumListKeys.sort((a, b) => { return a > b ? -1 : 1 }); + } + if (sortBy === SORT_ARTIST) { + tempAlbumListKeys = tempAlbumListKeys.sort((a, b) => { return a > b ? 1 : -1 }); + } + return tempAlbumListKeys; +} \ No newline at end of file diff --git a/src/g-player-react/src/Components/screen/artist/ArtistsList.js b/src/g-player-react/src/Components/screen/artist/ArtistsList.js index 3cee12c..795f054 100644 --- a/src/g-player-react/src/Components/screen/artist/ArtistsList.js +++ b/src/g-player-react/src/Components/screen/artist/ArtistsList.js @@ -1,6 +1,6 @@ import React, { useEffect, useState } from "react"; import { useDispatch, useSelector } from "react-redux"; -import { ARTIST, ARTISTS, A_TO_Z, A_TO_Z_DESC, CURRENT_PAGE, SORT_A_TO_Z, SORT_A_TO_Z_DESC, SORT_COUNT_TRACKS } from "../../redux/GPActionTypes"; +import { ARTIST, ARTISTS, CURRENT_PAGE, SORT_A_TO_Z, SORT_A_TO_Z_DESC, SORT_COUNT_TRACKS } from "../../redux/GPActionTypes"; import { fetchAllArtistsDtls } from "../../redux/library/LibraryActions"; import { setCookies, sortGroupByField } from "../../utilities/util"; import { SortingContainer } from "../SortingContainer"; @@ -27,8 +27,6 @@ export const ArtistsList = () => { if(sortBy===SORT_COUNT_TRACKS){ let tempArtistsDetails = [...artistsDetailsFS]; tempArtistsDetails = tempArtistsDetails.sort((a, b)=>a.count > b.count?-1:1); - //tempArtistsDetails = tempArtistsDetails.sort((a, b)=>b.imgAvl?1:-1); - //tempArtistsDetails = tempArtistsDetails.filter(artist => {return artist.imgAvl || artist.count>1}) setAlbumArtistsDetails(tempArtistsDetails); } } @@ -48,13 +46,13 @@ export const ArtistsList = () => { <>
- {sortBy === SORT_COUNT_TRACKS && artistsDetails!==null && artistsDetails!==undefined && artistsDetails.length>0 && artistsDetails.map((artist, index) => + {sortBy === SORT_COUNT_TRACKS && artistsDetails?.map((artist, index) => )} - {sortBy!==SORT_COUNT_TRACKS && artistsDetailsListKeys !== undefined && artistsDetailsListKeys.length > 0 && artistsDetailsListKeys.map((lKey, index) => + {sortBy!==SORT_COUNT_TRACKS && artistsDetailsListKeys?.map((lKey, index) => <> - - {artistsDetailsList[lKey] !== undefined && artistsDetailsList[lKey].length > 0 && artistsDetailsList[lKey].map((artist, artistIndex) => + + {artistsDetailsList[lKey]?.map((artist, artistIndex) => )} diff --git a/src/g-player-react/src/Components/screen/genre/Genres.js b/src/g-player-react/src/Components/screen/genre/Genres.js index d589ffb..1a48890 100644 --- a/src/g-player-react/src/Components/screen/genre/Genres.js +++ b/src/g-player-react/src/Components/screen/genre/Genres.js @@ -3,7 +3,7 @@ import { useDispatch, useSelector } from "react-redux"; import { fetchGenreDetails } from "../../redux/library/LibraryActions"; import { Link } from "react-router-dom"; import { GroupedThumbImg4 } from "../../GroupedThumbImg4"; -import { CURRENT_PAGE, GENRE, GENRES, GENRE_LABEL, SORT_ARTIST, SORT_A_TO_Z, SORT_A_TO_Z_DESC, SORT_COUNT_TRACKS, TRACKS_LABEL } from "../../redux/GPActionTypes"; +import { CURRENT_PAGE, GENRE, GENRES, GENRE_LABEL, SORT_A_TO_Z, SORT_A_TO_Z_DESC, SORT_COUNT_TRACKS, TRACKS_LABEL } from "../../redux/GPActionTypes"; import { ThumbnailActionBtn } from "../../ThumbnailActionBtn"; import { camelize, setCookies } from "../../utilities/util"; import { SortingContainer } from "../SortingContainer"; diff --git a/src/g-player-react/src/Components/screen/language/Languages.js b/src/g-player-react/src/Components/screen/language/Languages.js index 280d6b0..ebd31e2 100644 --- a/src/g-player-react/src/Components/screen/language/Languages.js +++ b/src/g-player-react/src/Components/screen/language/Languages.js @@ -3,9 +3,10 @@ import { useDispatch, useSelector } from "react-redux"; import { fetchLanguageDetails } from "../../redux/library/LibraryActions"; import { Link } from "react-router-dom"; import { GroupedThumbImg4 } from "../../GroupedThumbImg4"; -import { CURRENT_PAGE, LANGUAGE, LANGUAGES, LANGUAGE_LABEL, TRACKS_LABEL } from "../../redux/GPActionTypes"; +import { CURRENT_PAGE, LANGUAGE, LANGUAGES, LANGUAGE_LABEL, SORT_A_TO_Z, SORT_A_TO_Z_DESC, SORT_COUNT_TRACKS, TRACKS_LABEL } from "../../redux/GPActionTypes"; import { ThumbnailActionBtn } from "../../ThumbnailActionBtn"; -import { camelize, setCookies } from "../../utilities/util"; +import { camelize, setCookies, sortByKey } from "../../utilities/util"; +import { SortingContainer } from "../SortingContainer"; export const Languages = () => { const dispatch = useDispatch(); @@ -15,6 +16,7 @@ export const Languages = () => { const [languageAlbums, setLanguageAlbums] = useState({}); const [languages, setLanguages] = useState([]); const [languageSongCount, setLanguageSongCount] = useState({}); + const [sortBy, setSortBy] = useState(SORT_A_TO_Z); useEffect(()=>{ if(!languageDetails || (languageDetails && !languageDetails.LANGUAGE_SONG_COUNT)){ @@ -37,8 +39,36 @@ export const Languages = () => { } },[languageDetails]); + useEffect(()=>{ + if(languages && languages.length>0){ + let sortedLanguages = [...languages]; + if(sortBy === SORT_A_TO_Z){ + sortedLanguages = sortedLanguages.sort((a,b)=>{return a>b?1:-1}); + } + if(sortBy === SORT_A_TO_Z_DESC){ + sortedLanguages = sortedLanguages.sort((a,b)=>{return a>b?-1:1}); + } + if(sortBy === SORT_COUNT_TRACKS){ + sortedLanguages = sortedLanguages.sort((a,b)=>{return languageSongCount[a]>languageSongCount[b]?-1:1}); + } + setLanguages(sortedLanguages); + } + },[sortBy, languages]) + return(
+
{languages.length > 0 && languages.map(language =>
diff --git a/src/g-player-react/src/Components/screen/lyrics/Lyrics.js b/src/g-player-react/src/Components/screen/lyrics/Lyrics.js index 1a44b72..c1fc347 100644 --- a/src/g-player-react/src/Components/screen/lyrics/Lyrics.js +++ b/src/g-player-react/src/Components/screen/lyrics/Lyrics.js @@ -16,6 +16,7 @@ import { MdOutlineCancelPresentation } from "react-icons/md"; import { FaHourglassStart } from "react-icons/fa6"; import { IoMdDownload } from "react-icons/io"; import { RiDeleteBin6Line } from "react-icons/ri"; +import { TbWriting } from "react-icons/tb"; export const Lyrics = () => { const dispatch = useDispatch(); @@ -253,7 +254,7 @@ export const Lyrics = () => {
{songPlaying!==null && songPlaying.lyricist!==null &&
- Lyricist: {songPlaying.lyricist} +  : {songPlaying.lyricist}
}
} diff --git a/src/g-player-react/src/Components/screen/metadata/EditAlbumInfo.js b/src/g-player-react/src/Components/screen/metadata/EditAlbumInfo.js index 0d5822f..61aa2ca 100644 --- a/src/g-player-react/src/Components/screen/metadata/EditAlbumInfo.js +++ b/src/g-player-react/src/Components/screen/metadata/EditAlbumInfo.js @@ -29,24 +29,25 @@ export const EditAlbumInfo = () => { const updateModifiedAlbum = async (event, field, type, songId) => { const target = event.target; + let targetValue = ""; if(target.type !== "file"){ - target.value = target.value.trim(); + targetValue = target.value.trim(); } const tempModifiedAlbum = {...modifiedAlbum}; if(type === ALBUM){ - tempModifiedAlbum[field] = target.value; + tempModifiedAlbum[field] = targetValue; }else if(type === TRACK){ let tempAlbumTracks = tempModifiedAlbum.albumTracks; let track = {}; if(!tempAlbumTracks){ tempAlbumTracks = []; - track[field] = target.value; + track[field] = targetValue; track['songId'] = songId; tempAlbumTracks.push(track); }else{ track = tempAlbumTracks.find(elem => {return elem.songId === songId}); if(track){ - track[field] = target.value; + track[field] = targetValue; tempAlbumTracks.forEach((element,i) => { if(element.songId === songId){ tempAlbumTracks[i] = track; @@ -54,7 +55,7 @@ export const EditAlbumInfo = () => { }); }else{ track = {}; - track[field] = target.value; + track[field] = targetValue; track['songId'] = songId; tempAlbumTracks.push(track); } @@ -74,13 +75,13 @@ export const EditAlbumInfo = () => { } if(track){ trackIndex = tempAlbumTracks.findIndex(elem1=> elem1.songId === track.songId); - track[field] = target.value; + track[field] = targetValue; tempAlbumTracks[trackIndex] = track; }else{ track = { songId : elem.songId, } - track[field] = target.value; + track[field] = targetValue; tempAlbumTracks.push(track); } }); diff --git a/src/g-player-react/src/Components/utilities/util.js b/src/g-player-react/src/Components/utilities/util.js index d13094c..1c0c1e4 100644 --- a/src/g-player-react/src/Components/utilities/util.js +++ b/src/g-player-react/src/Components/utilities/util.js @@ -1,4 +1,4 @@ -import { SORT_NONE, SORT_PLAY_COUNT, WIKI_SUMMARY_URL } from "../redux/GPActionTypes"; +import { GP_SORTING_KEY_MAPPING, SORT_NONE, SORT_PLAY_COUNT, WIKI_SUMMARY_URL } from "../redux/GPActionTypes"; export const getMins = (seconds) =>{ @@ -182,6 +182,20 @@ export const sortGroupByField = (entArr, field, histArr) => { return entListObj; } +export const sortByKey = (key,arr,obj) => { + console.log("sortByKey key: ",key) + console.log("sortByKey arr: ",arr) + console.log("sortByKey obj: ",obj) + let sarr = [...arr]; + if(obj && Object.keys(obj).length>0){ + sarr = arr.sort((a,b)=>obj[a]>obj[b]?GP_SORTING_KEY_MAPPING[key]:GP_SORTING_KEY_MAPPING[key]*-1); + }else{ + sarr = arr.sort((a,b)=>a>b?GP_SORTING_KEY_MAPPING[key]:GP_SORTING_KEY_MAPPING[key]*-1); + } + console.log("sarr: ",sarr) + return sarr; +} + export const getCountArr = (maxCount, countArr) => { for(let i=5;i songs = null; try { + Playlist playlist = playlistRepository.getByName(reqPlaylist.getPlaylist()); if (reqPlaylist.getSongId() != 0) { Library library = libraryService.getSongBySongId(reqPlaylist.getSongId()); playlistItem = createPlaylistItemBySong(library, reqPlaylist); @@ -82,6 +83,11 @@ public GPResponse addToPlaList(PlaylistItem reqPlaylist) { playlistItems.add(playlistItem); resp.setStatus(GP_CONSTANTS.SUCCESS); resp.setPlaylistItems(playlistItems); + if(null != playlist){ + playlist.setLastUpdated(LocalDateTime.now()); + playlistRepository.save(playlist); + } + } else { resp.setStatus(GP_CONSTANTS.FAILED); resp.setPlaylistItems(playlistItems); @@ -112,6 +118,7 @@ public GPResponse addToPlaList(PlaylistItem reqPlaylist) { resp.setStatus(GP_CONSTANTS.SUCCESS); resp.setPlaylistItems(playlistItems); } + } catch (Exception e) { resp.setStatus(GP_CONSTANTS.FAILED); resp.setStatus1(null); @@ -439,7 +446,7 @@ public GPResponse importPlaylists(String payload, String fileType) { for (String reqPlName : reqPlaylistObjKeys) { playlist = playlistRepository.getByName(reqPlName); if (playlist == null) { - playlist = new Playlist(reqPlName, LocalDateTime.now(), null); + playlist = new Playlist(reqPlName, LocalDateTime.now(), LocalDateTime.now()); playlist = playlistRepository.save(playlist); } reqPlaylistArr = (JSONArray) reqPlaylistsObj.get(reqPlName); @@ -463,6 +470,8 @@ public GPResponse importPlaylists(String payload, String fileType) { } addSongsToPlaylist(songs, playlist); + playlist.setLastUpdated(LocalDateTime.now()); + playlistRepository.save(playlist); } resp.setResponse(getPlaylists()); resp.setStatus1(String.valueOf(reqPlaylistObjKeys.size())); @@ -507,7 +516,7 @@ public GPResponse createPlalist(String name) { resp.setError(GP_ERRORS.ERR_PLAYLIST_ALREADY_EXISTS); return resp; } - temPlaylist = playlistRepository.save(new Playlist(name, LocalDateTime.now(), null)); + temPlaylist = playlistRepository.save(new Playlist(name, LocalDateTime.now(), LocalDateTime.now())); resp.setStatus(GP_CONSTANTS.SUCCESS); resp.setResponse(temPlaylist); return resp; From 3da88b1c0afbe6271957872d9c73ed7c435de727 Mon Sep 17 00:00:00 2001 From: Gireesh Date: Sun, 6 Oct 2024 18:55:41 +0530 Subject: [PATCH 2/2] code cleanup --- src/g-player-react/src/Components/utilities/util.js | 4 ---- 1 file changed, 4 deletions(-) diff --git a/src/g-player-react/src/Components/utilities/util.js b/src/g-player-react/src/Components/utilities/util.js index 1c0c1e4..5d9a4da 100644 --- a/src/g-player-react/src/Components/utilities/util.js +++ b/src/g-player-react/src/Components/utilities/util.js @@ -183,16 +183,12 @@ return entListObj; } export const sortByKey = (key,arr,obj) => { - console.log("sortByKey key: ",key) - console.log("sortByKey arr: ",arr) - console.log("sortByKey obj: ",obj) let sarr = [...arr]; if(obj && Object.keys(obj).length>0){ sarr = arr.sort((a,b)=>obj[a]>obj[b]?GP_SORTING_KEY_MAPPING[key]:GP_SORTING_KEY_MAPPING[key]*-1); }else{ sarr = arr.sort((a,b)=>a>b?GP_SORTING_KEY_MAPPING[key]:GP_SORTING_KEY_MAPPING[key]*-1); } - console.log("sarr: ",sarr) return sarr; }