File size: 1,823 Bytes
f5071ca
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
import React, { useContext, useEffect, useState } from 'react'
import { Navigate, useNavigate } from 'react-router-dom';
import {BiSolidPlaylist} from "react-icons/bi"
import  {MdPlayArrow} from "react-icons/md"
import "./style.css";
import { AppContext } from '../../context/AppContext';

const Sidebar = ({playlistArr,clickHandler,trackId}) => {

  const [color,setColor] = useState("green");
  const {hamburger,setHamburger} = useContext(AppContext);
  //setHamburger(true);
  console.log("HAMBURGER",hamburger);

  const navigate = useNavigate();

  function newclickHandler(e){
    clickHandler(e.target.id);
    navigate("/");
    if(window.innerWidth < 600){
      setHamburger(false);
    }
  }

  useEffect(()=>{
    console.log("windowInnerwidth",window.innerWidth);
    if(window.innerWidth < 600){
      setHamburger(false);
    }
    else{
      setHamburger(true);
    }
  },[])


  return (
    <>
    {
      hamburger && (
        <div className='sidebar  border-0 pt-3 outline-none h-full border-r-[1px] border-[#1db954] fixed w-[20%] px-3 bg-[#121212] '>
      <div>
      <p className='font-bold text-white text-[13px] mt-2 mb-3 flex'><BiSolidPlaylist className='mr-2 text-[20px]'/>PLAYLISTS</p>
      <hr></hr>
      </div>

      <div>
      {
        playlistArr.map((item,index)=>{
          const id = item.id;
          return(
            
            <div key={item.id} id={item.id}
            onClick={newclickHandler}
            className='flex cursor-pointer items-center py-3 text-white hover:text-[#1db954] gap-x-3 ease-linear duration-500 '
            
            >
            <MdPlayArrow className={id == trackId ? ("active") : ("")} />  {item.name}
            </div>
          )
        })
      }
      </div>
     
    </div>
      )
    }
    </>
  )
}

export default Sidebar