From 748ac0d8647fa49a9d82dc7d43196dbe6798b8e8 Mon Sep 17 00:00:00 2001 From: Gireesh Date: Sun, 5 May 2024 14:12:35 +0530 Subject: [PATCH] Add to playlist - Add ability to add to multiple playlists at once #141 --- src/g-player-react/src/Components/main.scss | 46 +++++- .../src/Components/playlist/PlaylistImg.js | 10 +- .../Components/playlist/PlaylistPageHeader.js | 2 +- .../playlist/PlayllistSelectorV2.js | 138 ++++++++++++++++++ .../src/Components/redux/GPActionTypes.js | 1 + .../src/Components/redux/GPApis.js | 4 + .../src/Components/redux/GPSaga.js | 5 +- .../redux/playlist/PlaylistActionTypes.js | 3 + .../redux/playlist/PlaylistActions.js | 26 +++- .../redux/playlist/PlaylistReducer.js | 13 +- .../Components/redux/playlist/PlaylistSaga.js | 24 ++- .../src/Components/screen/GPContextMenu.js | 21 ++- .../gp/controllers/PlaylistController.java | 5 + .../repositories/PlaylistItemRepository.java | 6 + .../com/gmt/gp/services/PlaylistService.java | 10 ++ .../java/com/gmt/gp/util/GP_CONSTANTS.java | 2 + 16 files changed, 295 insertions(+), 21 deletions(-) create mode 100644 src/g-player-react/src/Components/playlist/PlayllistSelectorV2.js diff --git a/src/g-player-react/src/Components/main.scss b/src/g-player-react/src/Components/main.scss index 3d97dab..1b1fa0a 100644 --- a/src/g-player-react/src/Components/main.scss +++ b/src/g-player-react/src/Components/main.scss @@ -1660,21 +1660,21 @@ body{ display: grid; grid-template-columns: 1fr 1fr; - img{ + img, a{ height: 4.5em; width: 4.5em; } - img:first-child{ + >img:first-child, a:first-child img{ border-top-left-radius: 5px; } - img:nth-child(2){ + >img:nth-child(2), a:nth-child(2) img{ border-top-right-radius: 5px; } - img:nth-child(3){ + >img:nth-child(3), a:nth-child(3) img{ border-bottom-left-radius: 5px; } - img:last-child{ + >img:last-child, a:last-child img{ border-bottom-right-radius: 5px; } } @@ -2660,6 +2660,42 @@ a.disabled-click{ } +.playlist-selector-v2{ + display: flex; + flex-wrap: wrap; + column-gap: 20px; + row-gap: 10px; + justify-content: space-between; + padding: 0 5px; + + .row{ + border: 1px solid; + padding: 5px; + border-radius: 4px; + width: 10em; + text-wrap: nowrap; + overflow: hidden; + text-overflow: ellipsis; + text-align: center; + justify-content: center; + cursor: pointer; + label{ + cursor: pointer; + } + } + + // .row:hover{ + // text-wrap: unset; + // } + + .row.selected{ + background-color: #0e684b; + color: beige; + } +} + + + .playlist-selector::-webkit-scrollbar{ width: 5px; } diff --git a/src/g-player-react/src/Components/playlist/PlaylistImg.js b/src/g-player-react/src/Components/playlist/PlaylistImg.js index 7c17c42..8dd8b77 100644 --- a/src/g-player-react/src/Components/playlist/PlaylistImg.js +++ b/src/g-player-react/src/Components/playlist/PlaylistImg.js @@ -1,7 +1,8 @@ import React, { useEffect, useState } from "react"; import def_album_art from '../images/def_album_art.png'; +import { Link } from "react-router-dom"; -export const PlaylistImg = ({albumNames}) => { +export const PlaylistImg = ({albumNames, link}) => { const [albumNameList, setAlbumNameList] = useState([]); useEffect(()=>{ @@ -16,7 +17,12 @@ export const PlaylistImg = ({albumNames}) => {
{albumNameList.length > 0 &&
- {albumNameList.map((albumName, i) => + {link && albumNameList.map((albumName, i) => + + + + )} + {!link && albumNameList.map((albumName, i) => )}
diff --git a/src/g-player-react/src/Components/playlist/PlaylistPageHeader.js b/src/g-player-react/src/Components/playlist/PlaylistPageHeader.js index 72f2446..9faacba 100644 --- a/src/g-player-react/src/Components/playlist/PlaylistPageHeader.js +++ b/src/g-player-react/src/Components/playlist/PlaylistPageHeader.js @@ -97,7 +97,7 @@ export const PlaylistPageHeader = ({albumNames, songsCount, playAll}) => { return(
- +

{playlistName}

diff --git a/src/g-player-react/src/Components/playlist/PlayllistSelectorV2.js b/src/g-player-react/src/Components/playlist/PlayllistSelectorV2.js new file mode 100644 index 0000000..1fbd6fd --- /dev/null +++ b/src/g-player-react/src/Components/playlist/PlayllistSelectorV2.js @@ -0,0 +1,138 @@ +import React, { useEffect, useState } from "react"; +import { useDispatch, useSelector } from "react-redux"; +import { ADD_TO_NEW_PLAYLIST_LABEL, ALBUM, ARTIST, CREATE, CREATE_LABEL, GENRE, GP_CONTEXT_MENU, INPUT, LANGUAGE, MAIN_CONTAINER, NEW_PLAYLIST_BTN_LABEL, PLAYLIST_NAME, PLAYLIST_SELECTOR, TRACK } from "../redux/GPActionTypes"; +import { addToPlaylist, createPlaylist, fetchAssignedPlaylists, fetchAssignedPlaylistsSucc, removeFromPlaylist } from "../redux/playlist/PlaylistActions"; +import { PLAYLIST_ADD_TO_PLAYLIST_FAIL, PLAYLIST_ADD_TO_PLAYLIST_SUCCESS } from "../redux/playlist/PlaylistActionTypes"; +import { setCommonPopupObj, setShowContextMenu, setShowPlaylistSelector } from "../redux/library/LibraryActions"; +import { HiPlus } from 'react-icons/hi'; +import { getCreatePlaylistObj } from "./PlalistUtil"; + +export const PlaylistSelector = () => { + const dispatch = useDispatch(); + const playLists = useSelector(state => state.playlist.playlists); + const contextObj = useSelector(state => state.library.contextObj); + const plPhase = useSelector(state => state.playlist.phase); + const assignedPlaylists = useSelector(state => state.playlist.assignedPlaylists); + + const [styles, setStyles] = useState({display:'none'}); + const [obj, setobj] = useState(null); + + useEffect(()=>{ + if(contextObj.type === TRACK){ + dispatch(fetchAssignedPlaylists(contextObj.type, contextObj.obj.songId)); + }else if(contextObj.type === ALBUM){ + // console.log(contextObj) + dispatch(fetchAssignedPlaylistsSucc([])); + } + setobj(contextObj.obj); + },[contextObj]) + + console.log("contextObj: ",contextObj) + + + useEffect(()=>{ + if(contextObj && contextObj.position){ + const position = contextObj.position; + const tempStyles = { + left: parseInt(position.x)+185, + width: 'auto', + overflowY:'auto', + maxHeight:'50vh' + } + // const mainContainerHeight = document.getElementById(MAIN_CONTAINER).clientHeight; + // let gpCtxtMenuHeight = document.getElementById(GP_CONTEXT_MENU).clientHeight; + // if(gpCtxtMenuHeight === undefined || gpCtxtMenuHeight === 0)gpCtxtMenuHeight = 160; + + // if((mainContainerHeight - position.top) > gpCtxtMenuHeight+ 40){ + // tempStyles.top = parseInt(position.y)+25; + + // }else{ + // tempStyles.top = parseInt(position.y)-gpCtxtMenuHeight; + // } + + // const mainContainerWidth = document.getElementById(MAIN_CONTAINER).clientWidth; + // let gpCtxtMenuWidth = document.getElementById(GP_CONTEXT_MENU).clientWidth; + // if(gpCtxtMenuWidth === undefined || gpCtxtMenuWidth === 0)gpCtxtMenuWidth = 200; + // if((mainContainerWidth - position.left) < gpCtxtMenuWidth+40){ + // tempStyles.left = parseInt(position.x)-gpCtxtMenuWidth-154; + // } + + setStyles(tempStyles); + } + },[contextObj]); + + const onAddToPlaylist = (playlistId,playlistName) => { + const reqPLObj = { + playlist: playlistName, + playlistId: playlistId + } + if(contextObj.type === ALBUM){ + reqPLObj["albumId"] = parseInt(contextObj.obj.albumId); + reqPLObj["albumName"] = contextObj.obj.albumName; + }else if(contextObj.type === TRACK){ + reqPLObj["songId"] = contextObj.obj.songId; + reqPLObj["albumName"] = contextObj.obj.album; + }else if(contextObj.type === LANGUAGE){ + reqPLObj["language"] = contextObj.obj; + }else if(contextObj.type === GENRE){ + reqPLObj["genre"] = contextObj.obj; + }else if(contextObj.type === ARTIST){ + reqPLObj["artist"] = contextObj.obj; + } + dispatch(addToPlaylist(reqPLObj)); + } + + useEffect(()=>{ + + if(plPhase === PLAYLIST_ADD_TO_PLAYLIST_SUCCESS || plPhase === PLAYLIST_ADD_TO_PLAYLIST_FAIL){ + dispatch(setShowPlaylistSelector(false)); + dispatch(setShowContextMenu(false)); + } + + },[plPhase]); + + const addToNewPlayist = () => { + const addToNewPLPopupObj = { + showPopup: true, + title: ADD_TO_NEW_PLAYLIST_LABEL, + content: "Untitled Playlist", + placeHolder:'New Playlist Name', + contentType: INPUT, + primaryBtnAction: CREATE, + primaryBtnLabel:CREATE_LABEL, + className:"create", + elementId:PLAYLIST_NAME, + primaryBtnFun: onAddToNewPlaylist + } + dispatch(setCommonPopupObj(addToNewPLPopupObj)); + } + + const onAddToNewPlaylist = () => { + const createPlaylistObj = getCreatePlaylistObj(); + createPlaylistObj.addedNewPlaylistObj = {isAddToNewPlaylist: true}; + dispatch(createPlaylist(createPlaylistObj)); + } + const handleOnPlaylistClick = (id, name) => { + if(assignedPlaylists.includes(name)){ + dispatch(removeFromPlaylist(id, contextObj.obj.songId)) + }else{ + onAddToPlaylist(id, name); + } + } + + return( +
+
+ {obj && obj.title+" - "+obj.album} +
+
+ +
+ {playLists && playLists.map(playlist => +
handleOnPlaylistClick(playlist.id,playlist.name)} title={playlist.name}> + +
+ )} +
+ ); +} \ No newline at end of file diff --git a/src/g-player-react/src/Components/redux/GPActionTypes.js b/src/g-player-react/src/Components/redux/GPActionTypes.js index 661f3aa..3f42756 100644 --- a/src/g-player-react/src/Components/redux/GPActionTypes.js +++ b/src/g-player-react/src/Components/redux/GPActionTypes.js @@ -2,6 +2,7 @@ export const A_TO_Z = "A_TO_Z"; export const A_TO_Z_DESC = "A_TO_Z_DESC"; export const ADD = 'ADD'; export const ADD_TO_NEW_PLAYLIST_LABEL = 'ADD_TO_NEW_PLAYLIST_LABEL'; +export const ADD_TOPLAYLIST_LABEL = 'Add to Playlist'; export const ALBUM = 'ALBUM'; export const ALBUM_LABEL = 'Album'; export const ALBUMS = 'ALBUMS'; diff --git a/src/g-player-react/src/Components/redux/GPApis.js b/src/g-player-react/src/Components/redux/GPApis.js index e1dfee0..a6843f7 100644 --- a/src/g-player-react/src/Components/redux/GPApis.js +++ b/src/g-player-react/src/Components/redux/GPApis.js @@ -205,6 +205,10 @@ export const exportPlaylistsAPI = () => { export const importPlaylistsAPI = (payload, fileType) => { return iAxios.post(`/playlist/import/${fileType}`, JSON.stringify(payload)).then(response => response); } + +export const fetchAssignedPlaylistsAPI = (payload) => { + return iAxios.get(`/playlist/playlists/${payload.objType}/identifier/${payload.identifier}`).then(response => response); +} //Playlist - End //Edit metadata - start diff --git a/src/g-player-react/src/Components/redux/GPSaga.js b/src/g-player-react/src/Components/redux/GPSaga.js index da72869..f9e055b 100644 --- a/src/g-player-react/src/Components/redux/GPSaga.js +++ b/src/g-player-react/src/Components/redux/GPSaga.js @@ -1,7 +1,7 @@ import { onDeleteMusicPath, onEditAlbumInfo, onEditTrackInfo, onFetchAlbum, onFetchAlbumimgs, onFetchAlbumListOfAA, onFetchAlbumsByGenre, onFetchAlbumTracks, onFetchAllAlbumArtistsDtls, onFetchAllAlbumDtls, onFetchAllAlbums, onFetchAllArtistsDtls, onFetchAllHistory, onFetchAllSongs, onFetchBuildStatus, onFetchGenreDetails, onFetchLanguageDetails, onFetchMessagesByType, onFetchMostPlayedData, onFetchMusicPath, onFetchSongsByArtist, onFetchSongsByGenre, onFetchSongsByLanguage, onInitArtistImgDownload, onInitDeltaLibraryBuild, onInitLibraryBuild, onsaveMusicPath, onSearchByKey, onUpdateHistory, onUploadArtistImg } from "./library/LibrarySaga"; import {all} from 'redux-saga/effects' import { onDeleteLyrics, onFetchCurrentSongAndStatus, onFetchCurrentSongStatus, onPlayASong, onPlayPause, onSetMediaVolume, onSetPlayBackTime, onUpdateLyrics } from "./player/PlayerSaga"; -import { onAddToPlaylist, onCreatePlaylist, onDeletePlaylist, onExportPlaylists, onFetchPlaylistNames, onFetchSongsInPlaylist, onImportPlaylists, onRemoveFromPlaylist, onRenamePlaylist } from "./playlist/PlaylistSaga"; +import { onAddToPlaylist, onCreatePlaylist, onDeletePlaylist, onExportPlaylists, onFetchAssignedPlaylits, onFetchPlaylistNames, onFetchSongsInPlaylist, onImportPlaylists, onRemoveFromPlaylist, onRenamePlaylist } from "./playlist/PlaylistSaga"; export function* GPSaga(){ yield all([ @@ -51,6 +51,7 @@ export function* GPSaga(){ onFetchSongsByLanguage(), onEditTrackInfo(), onEditAlbumInfo(), - onFetchMessagesByType() + onFetchMessagesByType(), + onFetchAssignedPlaylits() ]) } \ No newline at end of file diff --git a/src/g-player-react/src/Components/redux/playlist/PlaylistActionTypes.js b/src/g-player-react/src/Components/redux/playlist/PlaylistActionTypes.js index 0bb7ebf..51091aa 100644 --- a/src/g-player-react/src/Components/redux/playlist/PlaylistActionTypes.js +++ b/src/g-player-react/src/Components/redux/playlist/PlaylistActionTypes.js @@ -25,5 +25,8 @@ export const PLAYLIST_EXPORT_PLAYLISTS_FAIL = 'PLAYLIST_EXPORT_PLAYLISTS_FAIL'; export const PLAYLIST_IMPORT_PLAYLISTS_START = 'PLAYLIST_IMPORT_PLAYLISTS_START'; export const PLAYLIST_IMPORT_PLAYLISTS_SUCCESS= 'PLAYLIST_IMPORT_PLAYLISTS_SUCCESS'; export const PLAYLIST_IMPORT_PLAYLISTS_FAIL = 'PLAYLIST_IMPORT_PLAYLISTS_FAIL'; +export const PLAYLIST_FETCH_ASSIGNED_PLAYLISTS_START = 'PLAYLIST_FETCH_ASSIGNED_PLAYLISTS_START'; +export const PLAYLIST_FETCH_ASSIGNED_PLAYLISTS_SUCCESS = 'PLAYLIST_FETCH_ASSIGNED_PLAYLISTS_SUCCESS'; +export const PLAYLIST_FETCH_ASSIGNED_PLAYLISTS_FAILURE = 'PLAYLIST_FETCH_ASSIGNED_PLAYLISTS_FAILURE'; export const SET_ADDED_NEW_PLAYLIST_OBJ = 'SET_ADDED_NEW_PLAYLIST_OBJ'; \ No newline at end of file diff --git a/src/g-player-react/src/Components/redux/playlist/PlaylistActions.js b/src/g-player-react/src/Components/redux/playlist/PlaylistActions.js index 46462bd..d834204 100644 --- a/src/g-player-react/src/Components/redux/playlist/PlaylistActions.js +++ b/src/g-player-react/src/Components/redux/playlist/PlaylistActions.js @@ -3,6 +3,8 @@ import { PLAYLIST_ADD_TO_PLAYLIST_FAIL, PLAYLIST_ADD_TO_PLAYLIST_START, PLAYLIST PLAYLIST_CREATE_PLAYLIST_START, PLAYLIST_CREATE_PLAYLIST_SUCCESS, PLAYLIST_DELETE_PLAYLIST_START, PLAYLIST_DELETE_PLAYLIST_SUCCESS, PLAYLIST_EXPORT_PLAYLISTS_START, PLAYLIST_EXPORT_PLAYLISTS_SUCCESS, + PLAYLIST_FETCH_ASSIGNED_PLAYLISTS_START, + PLAYLIST_FETCH_ASSIGNED_PLAYLISTS_SUCCESS, PLAYLIST_FETCH_PLAYLIST_NAMES_START, PLAYLIST_FETCH_PLAYLIST_NAMES_SUCCESS, PLAYLIST_FETCH_SONGS_IN_PLAYLIST_START, PLAYLIST_FETCH_SONGS_IN_PLAYLIST_SUCCESS, PLAYLIST_IMPORT_PLAYLISTS_START, PLAYLIST_IMPORT_PLAYLISTS_SUCCESS, @@ -36,9 +38,9 @@ export const addToPlaylist = (reqPLObj) => ({ reqPLObj }) -export const addToPlaylistSucc = (playlists) => ({ +export const addToPlaylistSucc = (response) => ({ type:PLAYLIST_ADD_TO_PLAYLIST_SUCCESS, - playlists + response }) export const addToPlaylistFail = (error) => ({ @@ -110,6 +112,17 @@ export const importPlaylistsSucc = () => ({ type: PLAYLIST_IMPORT_PLAYLISTS_SUCCESS }) +export const fetchAssignedPlaylists = (objType, identifier) => ({ + type: PLAYLIST_FETCH_ASSIGNED_PLAYLISTS_START, + objType, + identifier +}) + +export const fetchAssignedPlaylistsSucc = (response) => ({ + type: PLAYLIST_FETCH_ASSIGNED_PLAYLISTS_SUCCESS, + response +}) + export const getUpdatedPlayListNames = (playlists, playlist, action) => { if(action === ADD){ return [...playlists, playlist]; @@ -140,4 +153,13 @@ export const removeRemovedSongFromPlaylist = (playlistSongs, playlistItem) => { } } return playlistSongs; +} + +export const getUpdatedAssignedPlaylits = (assignedPlaylists, plItem, action) => { + if(action === ADD){ + assignedPlaylists.push(plItem.playlist); + }else{ + assignedPlaylists = assignedPlaylists.filter(pl=>pl!=plItem.playlist); + } + return assignedPlaylists; } \ No newline at end of file diff --git a/src/g-player-react/src/Components/redux/playlist/PlaylistReducer.js b/src/g-player-react/src/Components/redux/playlist/PlaylistReducer.js index 34471e5..1967cb4 100644 --- a/src/g-player-react/src/Components/redux/playlist/PlaylistReducer.js +++ b/src/g-player-react/src/Components/redux/playlist/PlaylistReducer.js @@ -1,6 +1,6 @@ import { ADD, INIT, LOADING, PLAYLIST_ALBUMS, PLAYLIST_NAMES, PLAYLIST_SONGS_COUNT, REMOVE, RENAME, SUCCESS } from "../GPActionTypes"; -import { PLAYLIST_ADD_TO_PLAYLIST_FAIL, PLAYLIST_ADD_TO_PLAYLIST_SUCCESS, PLAYLIST_CREATE_PLAYLIST_START, PLAYLIST_CREATE_PLAYLIST_SUCCESS, PLAYLIST_DELETE_PLAYLIST_START, PLAYLIST_DELETE_PLAYLIST_SUCCESS, PLAYLIST_FETCH_PLAYLIST_NAMES_START, PLAYLIST_FETCH_PLAYLIST_NAMES_SUCCESS, PLAYLIST_FETCH_SONGS_IN_PLAYLIST_START, PLAYLIST_FETCH_SONGS_IN_PLAYLIST_SUCCESS, PLAYLIST_REMOVE_FROM_PLAYLIST_START, PLAYLIST_REMOVE_FROM_PLAYLIST_SUCCESS, PLAYLIST_RENAME_PLAYLIST_START, PLAYLIST_RENAME_PLAYLIST_SUCCESS, SET_SHOW_CREATE_PLAYLIST_POPUP } from "./PlaylistActionTypes"; -import { getUpdatedPlayListAlbums, getUpdatedPlayListNames, removeRemovedSongFromPlaylist } from "./PlaylistActions"; +import { PLAYLIST_ADD_TO_PLAYLIST_FAIL, PLAYLIST_ADD_TO_PLAYLIST_SUCCESS, PLAYLIST_CREATE_PLAYLIST_START, PLAYLIST_CREATE_PLAYLIST_SUCCESS, PLAYLIST_DELETE_PLAYLIST_START, PLAYLIST_DELETE_PLAYLIST_SUCCESS, PLAYLIST_FETCH_ASSIGNED_PLAYLISTS_SUCCESS, PLAYLIST_FETCH_PLAYLIST_NAMES_START, PLAYLIST_FETCH_PLAYLIST_NAMES_SUCCESS, PLAYLIST_FETCH_SONGS_IN_PLAYLIST_START, PLAYLIST_FETCH_SONGS_IN_PLAYLIST_SUCCESS, PLAYLIST_REMOVE_FROM_PLAYLIST_START, PLAYLIST_REMOVE_FROM_PLAYLIST_SUCCESS, PLAYLIST_RENAME_PLAYLIST_START, PLAYLIST_RENAME_PLAYLIST_SUCCESS, SET_SHOW_CREATE_PLAYLIST_POPUP } from "./PlaylistActionTypes"; +import { getUpdatedAssignedPlaylits, getUpdatedPlayListAlbums, getUpdatedPlayListNames, removeRemovedSongFromPlaylist } from "./PlaylistActions"; export const initialState = { playlists:[], @@ -8,6 +8,7 @@ export const initialState = { playlistSongs:[], playlistSongsCount:{}, addedNewPlaylistObj:{}, + assignedPlaylists:[], phase:INIT } @@ -16,6 +17,7 @@ const playlistReducer = (state = initialState, action) => { case PLAYLIST_ADD_TO_PLAYLIST_SUCCESS: return{ ...state, + assignedPlaylists: getUpdatedAssignedPlaylits([...state.assignedPlaylists],action.response.playlistItems[0], ADD), phase: PLAYLIST_ADD_TO_PLAYLIST_SUCCESS } case PLAYLIST_ADD_TO_PLAYLIST_FAIL: @@ -93,8 +95,15 @@ const playlistReducer = (state = initialState, action) => { return{ ...state, playlistSongs: removeRemovedSongFromPlaylist([...state.playlistSongs], action.playlistItem), + assignedPlaylists: getUpdatedAssignedPlaylits([...state.assignedPlaylists],action.playlistItem, REMOVE), phase: PLAYLIST_REMOVE_FROM_PLAYLIST_SUCCESS } + case PLAYLIST_FETCH_ASSIGNED_PLAYLISTS_SUCCESS: + return{ + ...state, + assignedPlaylists: action.response, + phase: PLAYLIST_FETCH_ASSIGNED_PLAYLISTS_SUCCESS + } default: return { ...state, diff --git a/src/g-player-react/src/Components/redux/playlist/PlaylistSaga.js b/src/g-player-react/src/Components/redux/playlist/PlaylistSaga.js index 1d3ab74..b97706d 100644 --- a/src/g-player-react/src/Components/redux/playlist/PlaylistSaga.js +++ b/src/g-player-react/src/Components/redux/playlist/PlaylistSaga.js @@ -1,7 +1,7 @@ import { call, put, takeEvery, takeLatest } from "redux-saga/effects"; -import { addToPlaylistAPI, createPlaylistAPI, deletePlaylistAPI, exportPlaylistsAPI, fetchPlaylistNamesAPI, fetchSongsInPlaylistAPI, importPlaylistsAPI, removeFromPlaylistAPI, renamePlaylistAPI } from "../GPApis"; -import { PLAYLIST_ADD_TO_PLAYLIST_START, PLAYLIST_CREATE_PLAYLIST_START, PLAYLIST_DELETE_PLAYLIST_START, PLAYLIST_EXPORT_PLAYLISTS_START, PLAYLIST_FETCH_PLAYLIST_NAMES_START, PLAYLIST_FETCH_SONGS_IN_PLAYLIST_START, PLAYLIST_IMPORT_PLAYLISTS_START, PLAYLIST_REMOVE_FROM_PLAYLIST_START, PLAYLIST_RENAME_PLAYLIST_START } from "./PlaylistActionTypes"; -import { addToPlaylistFail, addToPlaylistSucc, createPlaylistSucc, deltePlaylistSucc, fetchSongsInPlaylistSucc, fethPLaylistNamesSucc, importPlaylistsSucc, removeFromPlaylistSucc, renamePlaylistSucc } from "./PlaylistActions"; +import { addToPlaylistAPI, createPlaylistAPI, deletePlaylistAPI, exportPlaylistsAPI, fetchAssignedPlaylistsAPI, fetchPlaylistNamesAPI, fetchSongsInPlaylistAPI, importPlaylistsAPI, removeFromPlaylistAPI, renamePlaylistAPI } from "../GPApis"; +import { PLAYLIST_ADD_TO_PLAYLIST_START, PLAYLIST_CREATE_PLAYLIST_START, PLAYLIST_DELETE_PLAYLIST_START, PLAYLIST_EXPORT_PLAYLISTS_START, PLAYLIST_FETCH_ASSIGNED_PLAYLISTS_START, PLAYLIST_FETCH_PLAYLIST_NAMES_START, PLAYLIST_FETCH_SONGS_IN_PLAYLIST_START, PLAYLIST_IMPORT_PLAYLISTS_START, PLAYLIST_REMOVE_FROM_PLAYLIST_START, PLAYLIST_RENAME_PLAYLIST_START } from "./PlaylistActionTypes"; +import { addToPlaylistFail, addToPlaylistSucc, createPlaylistSucc, deltePlaylistSucc, fetchAssignedPlaylistsSucc, fetchSongsInPlaylistSucc, fethPLaylistNamesSucc, importPlaylistsSucc, removeFromPlaylistSucc, renamePlaylistSucc } from "./PlaylistActions"; import { handleAPIError } from "../../utilities/util"; import { setCommonPopupObj, setPlayerTracks, setPlaylistSongs, setShowContextMenu, setShowPlaylistSelector, setStatusMessage } from "../library/LibraryActions"; import { FAILED, SUCCESS } from "../GPActionTypes"; @@ -213,4 +213,22 @@ export function* onImportPlaylistsAsnc(payload){ handleAPIError(error); } +} + +export function* onFetchAssignedPlaylits(){ + yield takeLatest(PLAYLIST_FETCH_ASSIGNED_PLAYLISTS_START, onFetchAssignedPlaylitsAsnc); +} + +export function* onFetchAssignedPlaylitsAsnc(payload){ + try { + const response = yield call(fetchAssignedPlaylistsAPI, payload); + if(response.status === 200){ + const data = response.data; + yield put(fetchAssignedPlaylistsSucc(data)); + } + } catch (error) { + console.log(error); + handleAPIError(error); + } + } \ No newline at end of file diff --git a/src/g-player-react/src/Components/screen/GPContextMenu.js b/src/g-player-react/src/Components/screen/GPContextMenu.js index 9d98c93..cc88eea 100644 --- a/src/g-player-react/src/Components/screen/GPContextMenu.js +++ b/src/g-player-react/src/Components/screen/GPContextMenu.js @@ -1,10 +1,11 @@ import React, { useEffect, useState } from "react"; import { useDispatch, useSelector } from "react-redux"; -import { setShowContextMenu, setShowPlaylistSelector } from "../redux/library/LibraryActions"; -import { ALBUM, ARTIST, GP_CONTEXT_MENU, GP_CONTEXT_MENU_ELEM_IDS, MAIN_CONTAINER } from "../redux/GPActionTypes"; +import { setCommonPopupObj, setShowContextMenu, setShowPlaylistSelector } from "../redux/library/LibraryActions"; +import { ADD_TOPLAYLIST_LABEL, ADD_TO_NEW_PLAYLIST_LABEL, ALBUM, ARTIST, COMPONENT, GP_CONTEXT_MENU, GP_CONTEXT_MENU_ELEM_IDS, MAIN_CONTAINER, TRACK } from "../redux/GPActionTypes"; import { MdKeyboardArrowRight } from 'react-icons/md'; import { Link } from "react-router-dom"; import { checkIfActionAllowed } from "../utilities/util"; +import { PlaylistSelector as PlaylistSelectorV2 } from "../playlist/PlayllistSelectorV2"; export const GPContexMenu = () => { const dispatch = useDispatch(); @@ -78,7 +79,19 @@ export const GPContexMenu = () => { },[]); const onSetShowPlaylistSelector = (showPlaylistSelector) => { - dispatch(setShowPlaylistSelector(showPlaylistSelector)); + if(contextObj.type===TRACK){ + const commonPopupObj = { + showPopup: true, + title: ADD_TOPLAYLIST_LABEL, + contentType: COMPONENT, + component: PlaylistSelectorV2, + primaryClassName: "no-display", + + } + dispatch(setCommonPopupObj(commonPopupObj)); + }else{ + dispatch(setShowPlaylistSelector(showPlaylistSelector)); + } } const closeCOntextMenu = () => { @@ -88,7 +101,7 @@ export const GPContexMenu = () => { return(
-
onSetShowPlaylistSelector(true)}> +
{onSetShowPlaylistSelector(true);if(contextObj.type===TRACK)closeCOntextMenu()}}>
diff --git a/src/main/java/com/gmt/gp/controllers/PlaylistController.java b/src/main/java/com/gmt/gp/controllers/PlaylistController.java index 74dca23..20f63b0 100644 --- a/src/main/java/com/gmt/gp/controllers/PlaylistController.java +++ b/src/main/java/com/gmt/gp/controllers/PlaylistController.java @@ -92,4 +92,9 @@ public GPResponse movePlaylistsFromMesaagesToPlaylistTable(){ return playlistService.movePlaylistNames(); } + @GetMapping("/playlists/{type}/identifier/{identifier}") + public List getAssignedPlaylists(@PathVariable String type, @PathVariable String identifier){ + return playlistService.getAssignedPlaylists(type, identifier); + } + } diff --git a/src/main/java/com/gmt/gp/repositories/PlaylistItemRepository.java b/src/main/java/com/gmt/gp/repositories/PlaylistItemRepository.java index 7cd4fc4..9d04ebe 100644 --- a/src/main/java/com/gmt/gp/repositories/PlaylistItemRepository.java +++ b/src/main/java/com/gmt/gp/repositories/PlaylistItemRepository.java @@ -22,4 +22,10 @@ public interface PlaylistItemRepository extends CrudRepository getByPlaylistIdAndSongId(long playlistId, long songId); PlaylistItem getByPlaylistIdAndSongPath(long playlistId, String songPath); + + @Query("SELECT p.playlist FROM PlaylistItem p where p.songId =:songId") + List getPlaylistsBySongId(long songId); + + @Query("SELECT p.playlist FROM PlaylistItem p where p.albumName =:albumName") + List getPlaylistsByAlbumName(String albumName); } diff --git a/src/main/java/com/gmt/gp/services/PlaylistService.java b/src/main/java/com/gmt/gp/services/PlaylistService.java index c108e37..87489f1 100644 --- a/src/main/java/com/gmt/gp/services/PlaylistService.java +++ b/src/main/java/com/gmt/gp/services/PlaylistService.java @@ -520,4 +520,14 @@ public GPResponse movePlaylistNames() { return new GPResponse(GP_CONSTANTS.SUCCESS, null); } + public List getAssignedPlaylists(String type, String identifier) { + if(GP_CONSTANTS.TRACK.equalsIgnoreCase(type)){ + return playlistItemRepository.getPlaylistsBySongId(Long.parseLong(identifier)); + }else if(StringUtils.equals(type, GP_CONSTANTS.ALBUM)){ + System.out.println(playlistItemRepository.getPlaylistsByAlbumName(identifier)); + return playlistItemRepository.getPlaylistsByAlbumName(identifier); + } + return new ArrayList();//returning an empty list + } + } diff --git a/src/main/java/com/gmt/gp/util/GP_CONSTANTS.java b/src/main/java/com/gmt/gp/util/GP_CONSTANTS.java index b1a6618..e37c634 100644 --- a/src/main/java/com/gmt/gp/util/GP_CONSTANTS.java +++ b/src/main/java/com/gmt/gp/util/GP_CONSTANTS.java @@ -2,6 +2,7 @@ public class GP_CONSTANTS { + public static final String ALBUM = "ALBUM"; public static final String ALBUM_ARTIST_COUNT = "ALBUM_ARTIST_COUNT"; public static final String ALBUM_ARTIST = "ALBUM_ARTIST"; public static final String ALBUM_ARTISTS = "ALBUM_ARTISTS"; @@ -70,6 +71,7 @@ public class GP_CONSTANTS { public static final String RUNNING = "RUNNING"; public static final String SINGLE_GENRE = "SINGLE_GENRE"; + public static final String SONG = "SONG"; public static final String STATUS = "STATUS"; public static final String SUCCESS = "SUCCESS";