Skip to content

Commit

Permalink
Added filter to Artits page
Browse files Browse the repository at this point in the history
  • Loading branch information
mgireesha committed Oct 7, 2024
1 parent ba69f29 commit a05ff29
Show file tree
Hide file tree
Showing 5 changed files with 61 additions and 9 deletions.
6 changes: 6 additions & 0 deletions src/g-player-react/src/Components/FilterComp.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,10 @@ import {IoMdClose} from 'react-icons/io';
import { useDispatch } from "react-redux";
import { setGlobalFilterText } from "./redux/library/LibraryActions";
import { camelize } from "./utilities/util";
import { useLocation } from "react-router-dom";
export const FilterComp = ({onSetFilterTxt, isSetToStore, placeHolder}) =>{
const dispatch = useDispatch();
const locationL = useLocation();

const [filterInputEvent, setFilterInputEvent] = useState(undefined);

Expand All @@ -15,6 +17,10 @@ export const FilterComp = ({onSetFilterTxt, isSetToStore, placeHolder}) =>{
filterInpFld.blur();
}

useEffect(()=>{
if(locationL.pathname)dispatch(setGlobalFilterText(""));
},[locationL.pathname]);

useEffect(() => {
if(filterInputEvent){
const timeOutId = setTimeout(() => {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -63,9 +63,9 @@ export function* onAddToPlaylistAsnc(payload){
//successMessage = "Added "+addedSongsCount+" tracks to "+playlistItem.playlist+" playlist!";
successMessage = data.status1;
if(addedSongsCount === 1){
const songPath = playlistItem.songPath;
addedSongsCount = songPath.substring(songPath.lastIndexOf("\\")+1, songPath.indexOf("."));
successMessage = "Added "+addedSongsCount+" to "+playlistItem.playlist+" playlist!";
// const songPath = playlistItem.songPath;
//addedSongsCount = songPath.substring(songPath.lastIndexOf("\\")+1, songPath.indexOf("."));
successMessage = "Added "+data?.playlistItems?.at(0)?.songTitle+" to "+playlistItem.playlist+" playlist!";
}
yield put(addToPlaylistSucc(data));
}else{
Expand Down
35 changes: 29 additions & 6 deletions src/g-player-react/src/Components/screen/artist/ArtistsList.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,14 +5,19 @@ import { fetchAllArtistsDtls } from "../../redux/library/LibraryActions";
import { setCookies, sortGroupByField } from "../../utilities/util";
import { SortingContainer } from "../SortingContainer";
import { ArtistThumb } from "./ArtistThumb";
import { filterArtistDetails, filterArtistDetailsList } from "./artistUtil";

export const ArtistsList = () => {
const dispatch = useDispatch();
let artistsDetailsFS = useSelector(state => state.library.artistsDetails);
const [artistsDetails, setAlbumArtistsDetails] = useState([]);
const globalFilterText = useSelector(state => state.library.globalFilterText);
const [artistsDetails, setArtistsDetails] = useState([]);
const [filteredArtistsDetails, setFilteredArtistsDetails] = useState([]);
const [artistsDetailsList, setArtistsDetailsList] = useState({});
const [filteredrtistsDetailsList, setFilteredArtistsDetailsList] = useState({});
const [artistsDetailsListKeys, setArtistsDetailsListKeys] = useState([]);
const [sortBy, setSortBy] = useState(SORT_COUNT_TRACKS);
const [isFilterActive, setFilterActive] = useState(false);

useEffect(()=>{
dispatch(fetchAllArtistsDtls(ARTIST));
Expand All @@ -27,7 +32,7 @@ export const ArtistsList = () => {
if(sortBy===SORT_COUNT_TRACKS){
let tempArtistsDetails = [...artistsDetailsFS];
tempArtistsDetails = tempArtistsDetails.sort((a, b)=>a.count > b.count?-1:1);
setAlbumArtistsDetails(tempArtistsDetails);
setArtistsDetails(tempArtistsDetails);
}
}
},[artistsDetailsFS, sortBy]);
Expand All @@ -41,18 +46,36 @@ export const ArtistsList = () => {
setArtistsDetailsListKeys(tempArtistsDetailsListKeys);
}
},[artistsDetailsList]);

useEffect(() => {
if (globalFilterText && globalFilterText.length > 2) {
if(sortBy === SORT_COUNT_TRACKS){
console.log("artistsDetails: 0",artistsDetails)
console.log("globalFilterText: 0",globalFilterText)
setFilteredArtistsDetails(filterArtistDetails(globalFilterText, artistsDetails))
}else{
setFilteredArtistsDetailsList(filterArtistDetailsList(globalFilterText,artistsDetailsList,artistsDetailsListKeys))
}
setFilterActive(true);
} else {
setFilteredArtistsDetails(artistsDetails)
setFilteredArtistsDetailsList(artistsDetailsList)
setFilterActive(false);
}
}, [globalFilterText,artistsDetailsListKeys, artistsDetails,artistsDetailsList, sortBy]);


return(
<>
<SortingContainer sortListKeys={artistsDetailsListKeys} setSortBy={setSortBy} sortBy={sortBy} sortSelectors={[SORT_A_TO_Z,SORT_A_TO_Z_DESC, SORT_COUNT_TRACKS]} showSortByLabel={true} />
{!isFilterActive && <SortingContainer sortListKeys={artistsDetailsListKeys} setSortBy={setSortBy} sortBy={sortBy} sortSelectors={[SORT_A_TO_Z,SORT_A_TO_Z_DESC, SORT_COUNT_TRACKS]} showSortByLabel={true} />}
<div className="artists-list">
{sortBy === SORT_COUNT_TRACKS && artistsDetails?.map((artist, index) =>
{sortBy === SORT_COUNT_TRACKS && filteredArtistsDetails?.map((artist, index) =>
<ArtistThumb artist={artist} key={index} />
)}
{sortBy!==SORT_COUNT_TRACKS && artistsDetailsListKeys?.map((lKey, index) =>
<>
<label id={"lKey" + lKey} className="artists-lKey" key={index}>{lKey}</label>
{artistsDetailsList[lKey]?.map((artist, artistIndex) =>
{!isFilterActive && <label id={"lKey" + lKey} className="artists-lKey" key={index}>{lKey}</label>}
{filteredrtistsDetailsList[lKey]?.map((artist, artistIndex) =>
<ArtistThumb artist={artist} key={artistIndex} />
)}
</>
Expand Down
14 changes: 14 additions & 0 deletions src/g-player-react/src/Components/screen/artist/artistUtil.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
export const filterArtistDetails = (globalFilterText, artistDetails) => {
return artistDetails?.filter(artist =>artist.artistName?.toLowerCase().includes(globalFilterText)).filter(Boolean);
}

export const filterArtistDetailsList = (globalFilterText, sortedArtists, artistListKeys) => {
let tempFilteredArtists = [];
let filteredArtists = {};
artistListKeys?.forEach(lKey =>{
tempFilteredArtists = sortedArtists[lKey];
filteredArtists[lKey] = tempFilteredArtists
?.filter(artist => {return artist.artistName.toLowerCase().includes(globalFilterText)});
})
return filteredArtists;
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
select * FROM playlist_item
LEFT OUTER JOIN (
SELECT MIN(id) as RowId, playlist, playlist_id, song_id
FROM playlist_item
GROUP BY playlist, playlist_id, song_id
) as KeepRows ON
playlist_item.id = KeepRows.RowId
WHERE
KeepRows.RowId IS NULL

0 comments on commit a05ff29

Please sign in to comment.