├── .gitignore ├── README.md ├── package-lock.json ├── package.json ├── public ├── favicon.ico ├── index.html ├── logo192.png ├── logo512.png ├── manifest.json └── robots.txt ├── src ├── App.jsx ├── components │ ├── Body.jsx │ ├── CurrentTrack.jsx │ ├── Footer.jsx │ ├── Login.jsx │ ├── Navbar.jsx │ ├── PlayerControls.jsx │ ├── Playlists.jsx │ ├── Sidebar.jsx │ ├── Spotify.jsx │ └── Volume.jsx ├── index.css ├── index.js └── utils │ ├── Constants.js │ ├── Reducer.js │ └── StateProvider.jsx └── yarn.lock /.gitignore: -------------------------------------------------------------------------------- 1 | # See https://help.github.com/articles/ignoring-files/ for more about ignoring files. 2 | 3 | # dependencies 4 | /node_modules 5 | /.pnp 6 | .pnp.js 7 | 8 | # testing 9 | /coverage 10 | 11 | # production 12 | /build 13 | 14 | # misc 15 | .DS_Store 16 | .env.local 17 | .env.development.local 18 | .env.test.local 19 | .env.production.local 20 | 21 | npm-debug.log* 22 | yarn-debug.log* 23 | yarn-error.log* 24 | 25 | # Local Netlify folder 26 | .netlify 27 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # Getting Started with Create React App 2 | 3 | This project was bootstrapped with [Create React App](https://github.com/facebook/create-react-app). 4 | 5 | ## Available Scripts 6 | 7 | In the project directory, you can run: 8 | 9 | ### `npm start` 10 | 11 | Runs the app in the development mode.\ 12 | Open [http://localhost:3000](http://localhost:3000) to view it in your browser. 13 | 14 | The page will reload when you make changes.\ 15 | You may also see any lint errors in the console. 16 | 17 | ### `npm test` 18 | 19 | Launches the test runner in the interactive watch mode.\ 20 | See the section about [running tests](https://facebook.github.io/create-react-app/docs/running-tests) for more information. 21 | 22 | ### `npm run build` 23 | 24 | Builds the app for production to the `build` folder.\ 25 | It correctly bundles React in production mode and optimizes the build for the best performance. 26 | 27 | The build is minified and the filenames include the hashes.\ 28 | Your app is ready to be deployed! 29 | 30 | See the section about [deployment](https://facebook.github.io/create-react-app/docs/deployment) for more information. 31 | 32 | ### `npm run eject` 33 | 34 | **Note: this is a one-way operation. Once you `eject`, you can't go back!** 35 | 36 | If you aren't satisfied with the build tool and configuration choices, you can `eject` at any time. This command will remove the single build dependency from your project. 37 | 38 | Instead, it will copy all the configuration files and the transitive dependencies (webpack, Babel, ESLint, etc) right into your project so you have full control over them. All of the commands except `eject` will still work, but they will point to the copied scripts so you can tweak them. At this point you're on your own. 39 | 40 | You don't have to ever use `eject`. The curated feature set is suitable for small and middle deployments, and you shouldn't feel obligated to use this feature. However we understand that this tool wouldn't be useful if you couldn't customize it when you are ready for it. 41 | 42 | ## Learn More 43 | 44 | You can learn more in the [Create React App documentation](https://facebook.github.io/create-react-app/docs/getting-started). 45 | 46 | To learn React, check out the [React documentation](https://reactjs.org/). 47 | 48 | ### Code Splitting 49 | 50 | This section has moved here: [https://facebook.github.io/create-react-app/docs/code-splitting](https://facebook.github.io/create-react-app/docs/code-splitting) 51 | 52 | ### Analyzing the Bundle Size 53 | 54 | This section has moved here: [https://facebook.github.io/create-react-app/docs/analyzing-the-bundle-size](https://facebook.github.io/create-react-app/docs/analyzing-the-bundle-size) 55 | 56 | ### Making a Progressive Web App 57 | 58 | This section has moved here: [https://facebook.github.io/create-react-app/docs/making-a-progressive-web-app](https://facebook.github.io/create-react-app/docs/making-a-progressive-web-app) 59 | 60 | ### Advanced Configuration 61 | 62 | This section has moved here: [https://facebook.github.io/create-react-app/docs/advanced-configuration](https://facebook.github.io/create-react-app/docs/advanced-configuration) 63 | 64 | ### Deployment 65 | 66 | This section has moved here: [https://facebook.github.io/create-react-app/docs/deployment](https://facebook.github.io/create-react-app/docs/deployment) 67 | 68 | ### `npm run build` fails to minify 69 | 70 | This section has moved here: [https://facebook.github.io/create-react-app/docs/troubleshooting#npm-run-build-fails-to-minify](https://facebook.github.io/create-react-app/docs/troubleshooting#npm-run-build-fails-to-minify) 71 | -------------------------------------------------------------------------------- /package.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "spotify-clone", 3 | "version": "0.1.0", 4 | "private": true, 5 | "dependencies": { 6 | "@testing-library/jest-dom": "^5.16.2", 7 | "@testing-library/react": "^12.1.4", 8 | "@testing-library/user-event": "^13.5.0", 9 | "axios": "^0.26.1", 10 | "netlify-cli": "^9.16.4", 11 | "react": "^17.0.2", 12 | "react-dom": "^17.0.2", 13 | "react-icons": "^4.3.1", 14 | "react-scripts": "5.0.0", 15 | "styled-components": "^5.3.5", 16 | "web-vitals": "^2.1.4" 17 | }, 18 | "scripts": { 19 | "start": "react-scripts start", 20 | "build": "react-scripts build", 21 | "test": "react-scripts test", 22 | "eject": "react-scripts eject" 23 | }, 24 | "eslintConfig": { 25 | "extends": [ 26 | "react-app", 27 | "react-app/jest" 28 | ] 29 | }, 30 | "browserslist": { 31 | "production": [ 32 | ">0.2%", 33 | "not dead", 34 | "not op_mini all" 35 | ], 36 | "development": [ 37 | "last 1 chrome version", 38 | "last 1 firefox version", 39 | "last 1 safari version" 40 | ] 41 | } 42 | } 43 | -------------------------------------------------------------------------------- /public/favicon.ico: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/koolkishan/react-spotify-clone/76386663f53336ea65482f1987db7242fcc0df62/public/favicon.ico -------------------------------------------------------------------------------- /public/index.html: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 12 | 13 | 17 | 18 | 27 | React App 28 | 29 | 30 | 31 |
32 | 42 | 43 | 44 | -------------------------------------------------------------------------------- /public/logo192.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/koolkishan/react-spotify-clone/76386663f53336ea65482f1987db7242fcc0df62/public/logo192.png -------------------------------------------------------------------------------- /public/logo512.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/koolkishan/react-spotify-clone/76386663f53336ea65482f1987db7242fcc0df62/public/logo512.png -------------------------------------------------------------------------------- /public/manifest.json: -------------------------------------------------------------------------------- 1 | { 2 | "short_name": "React App", 3 | "name": "Create React App Sample", 4 | "icons": [ 5 | { 6 | "src": "favicon.ico", 7 | "sizes": "64x64 32x32 24x24 16x16", 8 | "type": "image/x-icon" 9 | }, 10 | { 11 | "src": "logo192.png", 12 | "type": "image/png", 13 | "sizes": "192x192" 14 | }, 15 | { 16 | "src": "logo512.png", 17 | "type": "image/png", 18 | "sizes": "512x512" 19 | } 20 | ], 21 | "start_url": ".", 22 | "display": "standalone", 23 | "theme_color": "#000000", 24 | "background_color": "#ffffff" 25 | } 26 | -------------------------------------------------------------------------------- /public/robots.txt: -------------------------------------------------------------------------------- 1 | # https://www.robotstxt.org/robotstxt.html 2 | User-agent: * 3 | Disallow: 4 | -------------------------------------------------------------------------------- /src/App.jsx: -------------------------------------------------------------------------------- 1 | import React, { useEffect } from "react"; 2 | import Login from "./components/Login"; 3 | import Spotify from "./components/Spotify"; 4 | import { reducerCases } from "./utils/Constants"; 5 | import { useStateProvider } from "./utils/StateProvider"; 6 | export default function App() { 7 | const [{ token }, dispatch] = useStateProvider(); 8 | useEffect(() => { 9 | const hash = window.location.hash; 10 | if (hash) { 11 | const token = hash.substring(1).split("&")[0].split("=")[1]; 12 | if (token) { 13 | dispatch({ type: reducerCases.SET_TOKEN, token }); 14 | } 15 | } 16 | document.title = "Spotify"; 17 | }, [dispatch, token]); 18 | return
{token ? : }
; 19 | } 20 | -------------------------------------------------------------------------------- /src/components/Body.jsx: -------------------------------------------------------------------------------- 1 | import axios from "axios"; 2 | import React, { useEffect } from "react"; 3 | import styled from "styled-components"; 4 | import { useStateProvider } from "../utils/StateProvider"; 5 | import { AiFillClockCircle } from "react-icons/ai"; 6 | import { reducerCases } from "../utils/Constants"; 7 | export default function Body({ headerBackground }) { 8 | const [{ token, selectedPlaylist, selectedPlaylistId }, dispatch] = 9 | useStateProvider(); 10 | 11 | useEffect(() => { 12 | const getInitialPlaylist = async () => { 13 | const response = await axios.get( 14 | `https://api.spotify.com/v1/playlists/${selectedPlaylistId}`, 15 | { 16 | headers: { 17 | Authorization: "Bearer " + token, 18 | "Content-Type": "application/json", 19 | }, 20 | } 21 | ); 22 | const selectedPlaylist = { 23 | id: response.data.id, 24 | name: response.data.name, 25 | description: response.data.description.startsWith(" ({ 30 | id: track.id, 31 | name: track.name, 32 | artists: track.artists.map((artist) => artist.name), 33 | image: track.album.images[2].url, 34 | duration: track.duration_ms, 35 | album: track.album.name, 36 | context_uri: track.album.uri, 37 | track_number: track.track_number, 38 | })), 39 | }; 40 | dispatch({ type: reducerCases.SET_PLAYLIST, selectedPlaylist }); 41 | }; 42 | getInitialPlaylist(); 43 | }, [token, dispatch, selectedPlaylistId]); 44 | const playTrack = async ( 45 | id, 46 | name, 47 | artists, 48 | image, 49 | context_uri, 50 | track_number 51 | ) => { 52 | const response = await axios.put( 53 | `https://api.spotify.com/v1/me/player/play`, 54 | { 55 | context_uri, 56 | offset: { 57 | position: track_number - 1, 58 | }, 59 | position_ms: 0, 60 | }, 61 | { 62 | headers: { 63 | "Content-Type": "application/json", 64 | Authorization: "Bearer " + token, 65 | }, 66 | } 67 | ); 68 | if (response.status === 204) { 69 | const currentPlaying = { 70 | id, 71 | name, 72 | artists, 73 | image, 74 | }; 75 | dispatch({ type: reducerCases.SET_PLAYING, currentPlaying }); 76 | dispatch({ type: reducerCases.SET_PLAYER_STATE, playerState: true }); 77 | } else { 78 | dispatch({ type: reducerCases.SET_PLAYER_STATE, playerState: true }); 79 | } 80 | }; 81 | const msToMinutesAndSeconds = (ms) => { 82 | var minutes = Math.floor(ms / 60000); 83 | var seconds = ((ms % 60000) / 1000).toFixed(0); 84 | return minutes + ":" + (seconds < 10 ? "0" : "") + seconds; 85 | }; 86 | return ( 87 | 88 | {selectedPlaylist && ( 89 | <> 90 |
91 |
92 | selected playlist 93 |
94 |
95 | PLAYLIST 96 |

{selectedPlaylist.name}

97 |

{selectedPlaylist.description}

98 |
99 |
100 |
101 |
102 |
103 | # 104 |
105 |
106 | TITLE 107 |
108 |
109 | ALBUM 110 |
111 |
112 | 113 | 114 | 115 |
116 |
117 |
118 | {selectedPlaylist.tracks.map( 119 | ( 120 | { 121 | id, 122 | name, 123 | artists, 124 | image, 125 | duration, 126 | album, 127 | context_uri, 128 | track_number, 129 | }, 130 | index 131 | ) => { 132 | return ( 133 |
137 | playTrack( 138 | id, 139 | name, 140 | artists, 141 | image, 142 | context_uri, 143 | track_number 144 | ) 145 | } 146 | > 147 |
148 | {index + 1} 149 |
150 |
151 |
152 | track 153 |
154 |
155 | {name} 156 | {artists} 157 |
158 |
159 |
160 | {album} 161 |
162 |
163 | {msToMinutesAndSeconds(duration)} 164 |
165 |
166 | ); 167 | } 168 | )} 169 |
170 |
171 | 172 | )} 173 |
174 | ); 175 | } 176 | 177 | const Container = styled.div` 178 | .playlist { 179 | margin: 0 2rem; 180 | display: flex; 181 | align-items: center; 182 | gap: 2rem; 183 | .image { 184 | img { 185 | height: 15rem; 186 | box-shadow: rgba(0, 0, 0, 0.25) 0px 25px 50px -12px; 187 | } 188 | } 189 | .details { 190 | display: flex; 191 | flex-direction: column; 192 | gap: 1rem; 193 | color: #e0dede; 194 | .title { 195 | color: white; 196 | font-size: 4rem; 197 | } 198 | } 199 | } 200 | .list { 201 | .header-row { 202 | display: grid; 203 | grid-template-columns: 0.3fr 3fr 2fr 0.1fr; 204 | margin: 1rem 0 0 0; 205 | color: #dddcdc; 206 | position: sticky; 207 | top: 15vh; 208 | padding: 1rem 3rem; 209 | transition: 0.3s ease-in-out; 210 | background-color: ${({ headerBackground }) => 211 | headerBackground ? "#000000dc" : "none"}; 212 | } 213 | .tracks { 214 | margin: 0 2rem; 215 | display: flex; 216 | flex-direction: column; 217 | margin-bottom: 5rem; 218 | .row { 219 | padding: 0.5rem 1rem; 220 | display: grid; 221 | grid-template-columns: 0.3fr 3.1fr 2fr 0.1fr; 222 | &:hover { 223 | background-color: rgba(0, 0, 0, 0.7); 224 | } 225 | .col { 226 | display: flex; 227 | align-items: center; 228 | color: #dddcdc; 229 | img { 230 | height: 40px; 231 | width: 40px; 232 | } 233 | } 234 | .detail { 235 | display: flex; 236 | gap: 1rem; 237 | .info { 238 | display: flex; 239 | flex-direction: column; 240 | } 241 | } 242 | } 243 | } 244 | } 245 | `; 246 | -------------------------------------------------------------------------------- /src/components/CurrentTrack.jsx: -------------------------------------------------------------------------------- 1 | import React, { useEffect } from "react"; 2 | import styled from "styled-components"; 3 | import axios from "axios"; 4 | import { useStateProvider } from "../utils/StateProvider"; 5 | import { reducerCases } from "../utils/Constants"; 6 | export default function CurrentTrack() { 7 | const [{ token, currentPlaying }, dispatch] = useStateProvider(); 8 | useEffect(() => { 9 | const getCurrentTrack = async () => { 10 | const response = await axios.get( 11 | "https://api.spotify.com/v1/me/player/currently-playing", 12 | { 13 | headers: { 14 | "Content-Type": "application/json", 15 | Authorization: "Bearer " + token, 16 | }, 17 | } 18 | ); 19 | if (response.data !== "") { 20 | const currentPlaying = { 21 | id: response.data.item.id, 22 | name: response.data.item.name, 23 | artists: response.data.item.artists.map((artist) => artist.name), 24 | image: response.data.item.album.images[2].url, 25 | }; 26 | dispatch({ type: reducerCases.SET_PLAYING, currentPlaying }); 27 | } else { 28 | dispatch({ type: reducerCases.SET_PLAYING, currentPlaying: null }); 29 | } 30 | }; 31 | getCurrentTrack(); 32 | }, [token, dispatch]); 33 | return ( 34 | 35 | {currentPlaying && ( 36 |
37 |
38 | currentPlaying 39 |
40 |
41 |

{currentPlaying.name}

42 |
43 | {currentPlaying.artists.join(", ")} 44 |
45 |
46 |
47 | )} 48 |
49 | ); 50 | } 51 | 52 | const Container = styled.div` 53 | .track { 54 | display: flex; 55 | align-items: center; 56 | gap: 1rem; 57 | &__image { 58 | } 59 | &__info { 60 | display: flex; 61 | flex-direction: column; 62 | gap: 0.3rem; 63 | &__track__name { 64 | color: white; 65 | } 66 | &__track__artists { 67 | color: #b3b3b3; 68 | } 69 | } 70 | } 71 | `; 72 | -------------------------------------------------------------------------------- /src/components/Footer.jsx: -------------------------------------------------------------------------------- 1 | import React from "react"; 2 | import styled from "styled-components"; 3 | import CurrentTrack from "./CurrentTrack"; 4 | 5 | import PlayerControls from "./PlayerControls"; 6 | import Volume from "./Volume"; 7 | export default function Footer() { 8 | return ( 9 | 10 | 11 | 12 | 13 | 14 | ); 15 | } 16 | 17 | const Container = styled.div` 18 | height: 100%; 19 | width: 100%; 20 | background-color: #181818; 21 | border-top: 1px solid #282828; 22 | display: grid; 23 | grid-template-columns: 1fr 2fr 1fr; 24 | align-items: center; 25 | justify-content: center; 26 | padding: 0 1rem; 27 | `; 28 | -------------------------------------------------------------------------------- /src/components/Login.jsx: -------------------------------------------------------------------------------- 1 | import React from "react"; 2 | import styled from "styled-components"; 3 | 4 | export default function Login() { 5 | const handleClick = async () => { 6 | const client_id = "b10ac7cc459d474e961a6603c15da715"; 7 | const redirect_uri = "https://spotify-clone-api.netlify.app/"; 8 | const api_uri = "https://accounts.spotify.com/authorize"; 9 | const scope = [ 10 | "user-read-private", 11 | "user-read-email", 12 | "user-modify-playback-state", 13 | "user-read-playback-state", 14 | "user-read-currently-playing", 15 | "user-read-recently-played", 16 | "user-top-read", 17 | ]; 18 | window.location.href = `${api_uri}?client_id=${client_id}&redirect_uri=${redirect_uri}&scope=${scope.join( 19 | " " 20 | )}&response_type=token&show_dialog=true`; 21 | }; 22 | return ( 23 | 24 | spotify 28 | 29 | 30 | ); 31 | } 32 | 33 | const Container = styled.div` 34 | display: flex; 35 | justify-content: center; 36 | align-items: center; 37 | flex-direction: column; 38 | height: 100vh; 39 | width: 100vw; 40 | background-color: #1db954; 41 | gap: 5rem; 42 | img { 43 | height: 20vh; 44 | } 45 | button { 46 | padding: 1rem 5rem; 47 | border-radius: 5rem; 48 | background-color: black; 49 | color: #49f585; 50 | border: none; 51 | font-size: 1.4rem; 52 | cursor: pointer; 53 | } 54 | `; 55 | -------------------------------------------------------------------------------- /src/components/Navbar.jsx: -------------------------------------------------------------------------------- 1 | import React from "react"; 2 | import styled from "styled-components"; 3 | import { useStateProvider } from "../utils/StateProvider"; 4 | import { FaSearch } from "react-icons/fa"; 5 | import { CgProfile } from "react-icons/cg"; 6 | export default function Navbar({ navBackground }) { 7 | const [{ userInfo }] = useStateProvider(); 8 | return ( 9 | 10 |
11 | 12 | 13 |
14 |
15 | 16 | 17 | {userInfo?.name} 18 | 19 |
20 |
21 | ); 22 | } 23 | 24 | const Container = styled.div` 25 | display: flex; 26 | justify-content: space-between; 27 | align-items: center; 28 | padding: 2rem; 29 | height: 15vh; 30 | position: sticky; 31 | top: 0; 32 | transition: 0.3s ease-in-out; 33 | background-color: ${({ navBackground }) => 34 | navBackground ? "rgba(0,0,0,0.7)" : "none"}; 35 | .search__bar { 36 | background-color: white; 37 | width: 30%; 38 | padding: 0.4rem 1rem; 39 | border-radius: 2rem; 40 | display: flex; 41 | align-items: center; 42 | gap: 0.5rem; 43 | input { 44 | border: none; 45 | height: 2rem; 46 | width: 100%; 47 | &:focus { 48 | outline: none; 49 | } 50 | } 51 | } 52 | .avatar { 53 | background-color: black; 54 | padding: 0.3rem 0.4rem; 55 | padding-right: 1rem; 56 | border-radius: 2rem; 57 | display: flex; 58 | justify-content: center; 59 | align-items: center; 60 | a { 61 | display: flex; 62 | justify-content: center; 63 | align-items: center; 64 | gap: 0.5rem; 65 | text-decoration: none; 66 | color: white; 67 | font-weight: bold; 68 | svg { 69 | font-size: 1.3rem; 70 | background-color: #282828; 71 | padding: 0.2rem; 72 | border-radius: 1rem; 73 | color: #c7c5c5; 74 | } 75 | } 76 | } 77 | `; 78 | -------------------------------------------------------------------------------- /src/components/PlayerControls.jsx: -------------------------------------------------------------------------------- 1 | import React from "react"; 2 | import styled from "styled-components"; 3 | import { 4 | BsFillPlayCircleFill, 5 | BsFillPauseCircleFill, 6 | BsShuffle, 7 | } from "react-icons/bs"; 8 | import { CgPlayTrackNext, CgPlayTrackPrev } from "react-icons/cg"; 9 | import { FiRepeat } from "react-icons/fi"; 10 | import { useStateProvider } from "../utils/StateProvider"; 11 | import axios from "axios"; 12 | import { reducerCases } from "../utils/Constants"; 13 | export default function PlayerControls() { 14 | const [{ token, playerState }, dispatch] = useStateProvider(); 15 | 16 | const changeState = async () => { 17 | const state = playerState ? "pause" : "play"; 18 | await axios.put( 19 | `https://api.spotify.com/v1/me/player/${state}`, 20 | {}, 21 | { 22 | headers: { 23 | "Content-Type": "application/json", 24 | Authorization: "Bearer " + token, 25 | }, 26 | } 27 | ); 28 | dispatch({ 29 | type: reducerCases.SET_PLAYER_STATE, 30 | playerState: !playerState, 31 | }); 32 | }; 33 | const changeTrack = async (type) => { 34 | await axios.post( 35 | `https://api.spotify.com/v1/me/player/${type}`, 36 | {}, 37 | { 38 | headers: { 39 | "Content-Type": "application/json", 40 | Authorization: "Bearer " + token, 41 | }, 42 | } 43 | ); 44 | dispatch({ type: reducerCases.SET_PLAYER_STATE, playerState: true }); 45 | const response1 = await axios.get( 46 | "https://api.spotify.com/v1/me/player/currently-playing", 47 | { 48 | headers: { 49 | "Content-Type": "application/json", 50 | Authorization: "Bearer " + token, 51 | }, 52 | } 53 | ); 54 | if (response1.data !== "") { 55 | const currentPlaying = { 56 | id: response1.data.item.id, 57 | name: response1.data.item.name, 58 | artists: response1.data.item.artists.map((artist) => artist.name), 59 | image: response1.data.item.album.images[2].url, 60 | }; 61 | dispatch({ type: reducerCases.SET_PLAYING, currentPlaying }); 62 | } else { 63 | dispatch({ type: reducerCases.SET_PLAYING, currentPlaying: null }); 64 | } 65 | }; 66 | return ( 67 | 68 |
69 | 70 |
71 |
72 | changeTrack("previous")} /> 73 |
74 |
75 | {playerState ? ( 76 | 77 | ) : ( 78 | 79 | )} 80 |
81 |
82 | changeTrack("next")} /> 83 |
84 |
85 | 86 |
87 |
88 | ); 89 | } 90 | 91 | const Container = styled.div` 92 | display: flex; 93 | align-items: center; 94 | justify-content: center; 95 | gap: 2rem; 96 | svg { 97 | color: #b3b3b3; 98 | transition: 0.2s ease-in-out; 99 | &:hover { 100 | color: white; 101 | } 102 | } 103 | .state { 104 | svg { 105 | color: white; 106 | } 107 | } 108 | .previous, 109 | .next, 110 | .state { 111 | font-size: 2rem; 112 | } 113 | `; 114 | -------------------------------------------------------------------------------- /src/components/Playlists.jsx: -------------------------------------------------------------------------------- 1 | import axios from "axios"; 2 | import React, { useEffect } from "react"; 3 | import styled from "styled-components"; 4 | import { reducerCases } from "../utils/Constants"; 5 | import { useStateProvider } from "../utils/StateProvider"; 6 | 7 | export default function Playlists() { 8 | const [{ token, playlists }, dispatch] = useStateProvider(); 9 | useEffect(() => { 10 | const getPlaylistData = async () => { 11 | const response = await axios.get( 12 | "https://api.spotify.com/v1/me/playlists", 13 | { 14 | headers: { 15 | Authorization: "Bearer " + token, 16 | "Content-Type": "application/json", 17 | }, 18 | } 19 | ); 20 | const { items } = response.data; 21 | const playlists = items.map(({ name, id }) => { 22 | return { name, id }; 23 | }); 24 | dispatch({ type: reducerCases.SET_PLAYLISTS, playlists }); 25 | }; 26 | getPlaylistData(); 27 | }, [token, dispatch]); 28 | const changeCurrentPlaylist = (selectedPlaylistId) => { 29 | dispatch({ type: reducerCases.SET_PLAYLIST_ID, selectedPlaylistId }); 30 | }; 31 | return ( 32 | 33 | 42 | 43 | ); 44 | } 45 | 46 | const Container = styled.div` 47 | color: #b3b3b3; 48 | height: 100%; 49 | overflow: hidden; 50 | ul { 51 | list-style-type: none; 52 | display: flex; 53 | flex-direction: column; 54 | gap: 1rem; 55 | padding: 1rem; 56 | height: 55vh; 57 | max-height: 100%; 58 | overflow: auto; 59 | &::-webkit-scrollbar { 60 | width: 0.7rem; 61 | &-thumb { 62 | background-color: rgba(255, 255, 255, 0.6); 63 | } 64 | } 65 | li { 66 | transition: 0.3s ease-in-out; 67 | cursor: pointer; 68 | &:hover { 69 | color: white; 70 | } 71 | } 72 | } 73 | `; 74 | -------------------------------------------------------------------------------- /src/components/Sidebar.jsx: -------------------------------------------------------------------------------- 1 | import React from "react"; 2 | import styled from "styled-components"; 3 | import { MdHomeFilled, MdSearch } from "react-icons/md"; 4 | import { IoLibrary } from "react-icons/io5"; 5 | import Playlists from "./Playlists"; 6 | export default function Sidebar() { 7 | return ( 8 | 9 |
10 |
11 | spotify 15 |
16 |
    17 |
  • 18 | 19 | Home 20 |
  • 21 |
  • 22 | 23 | Search 24 |
  • 25 |
  • 26 | 27 | Your Library 28 |
  • 29 |
30 |
31 | 32 |
33 | ); 34 | } 35 | 36 | const Container = styled.div` 37 | background-color: black; 38 | color: #b3b3b3; 39 | display: flex; 40 | flex-direction: column; 41 | height: 100%; 42 | width: 100%; 43 | .top__links { 44 | display: flex; 45 | flex-direction: column; 46 | .logo { 47 | text-align: center; 48 | margin: 1rem 0; 49 | img { 50 | max-inline-size: 80%; 51 | block-size: auto; 52 | } 53 | } 54 | ul { 55 | list-style-type: none; 56 | display: flex; 57 | flex-direction: column; 58 | gap: 1rem; 59 | padding: 1rem; 60 | li { 61 | display: flex; 62 | gap: 1rem; 63 | cursor: pointer; 64 | transition: 0.3s ease-in-out; 65 | &:hover { 66 | color: white; 67 | } 68 | } 69 | } 70 | } 71 | `; 72 | -------------------------------------------------------------------------------- /src/components/Spotify.jsx: -------------------------------------------------------------------------------- 1 | import React, { useEffect, useRef, useState } from "react"; 2 | import Sidebar from "./Sidebar"; 3 | import styled from "styled-components"; 4 | import Footer from "./Footer"; 5 | import Navbar from "./Navbar"; 6 | import axios from "axios"; 7 | import { useStateProvider } from "../utils/StateProvider"; 8 | import Body from "./Body"; 9 | import { reducerCases } from "../utils/Constants"; 10 | 11 | export default function Spotify() { 12 | const [{ token }, dispatch] = useStateProvider(); 13 | const [navBackground, setNavBackground] = useState(false); 14 | const [headerBackground, setHeaderBackground] = useState(false); 15 | const bodyRef = useRef(); 16 | const bodyScrolled = () => { 17 | bodyRef.current.scrollTop >= 30 18 | ? setNavBackground(true) 19 | : setNavBackground(false); 20 | bodyRef.current.scrollTop >= 268 21 | ? setHeaderBackground(true) 22 | : setHeaderBackground(false); 23 | }; 24 | useEffect(() => { 25 | const getUserInfo = async () => { 26 | const { data } = await axios.get("https://api.spotify.com/v1/me", { 27 | headers: { 28 | Authorization: "Bearer " + token, 29 | "Content-Type": "application/json", 30 | }, 31 | }); 32 | const userInfo = { 33 | userId: data.id, 34 | userUrl: data.external_urls.spotify, 35 | name: data.display_name, 36 | }; 37 | dispatch({ type: reducerCases.SET_USER, userInfo }); 38 | }; 39 | getUserInfo(); 40 | }, [dispatch, token]); 41 | useEffect(() => { 42 | const getPlaybackState = async () => { 43 | const { data } = await axios.get("https://api.spotify.com/v1/me/player", { 44 | headers: { 45 | Authorization: "Bearer " + token, 46 | "Content-Type": "application/json", 47 | }, 48 | }); 49 | dispatch({ 50 | type: reducerCases.SET_PLAYER_STATE, 51 | playerState: data.is_playing, 52 | }); 53 | }; 54 | getPlaybackState(); 55 | }, [dispatch, token]); 56 | return ( 57 | 58 |
59 | 60 |
61 | 62 |
63 | 64 |
65 |
66 |
67 |
68 |
69 |
70 |
71 | ); 72 | } 73 | 74 | const Container = styled.div` 75 | max-width: 100vw; 76 | max-height: 100vh; 77 | overflow: hidden; 78 | display: grid; 79 | grid-template-rows: 85vh 15vh; 80 | .spotify__body { 81 | display: grid; 82 | grid-template-columns: 15vw 85vw; 83 | height: 100%; 84 | width: 100%; 85 | background: linear-gradient(transparent, rgba(0, 0, 0, 1)); 86 | background-color: rgb(32, 87, 100); 87 | .body { 88 | height: 100%; 89 | width: 100%; 90 | overflow: auto; 91 | &::-webkit-scrollbar { 92 | width: 0.7rem; 93 | max-height: 2rem; 94 | &-thumb { 95 | background-color: rgba(255, 255, 255, 0.6); 96 | } 97 | } 98 | } 99 | } 100 | `; 101 | -------------------------------------------------------------------------------- /src/components/Volume.jsx: -------------------------------------------------------------------------------- 1 | import axios from "axios"; 2 | import React from "react"; 3 | import styled from "styled-components"; 4 | import { useStateProvider } from "../utils/StateProvider"; 5 | 6 | export default function Volume() { 7 | const [{ token }] = useStateProvider(); 8 | const setVolume = async (e) => { 9 | await axios.put( 10 | "https://api.spotify.com/v1/me/player/volume", 11 | {}, 12 | { 13 | params: { 14 | volume_percent: parseInt(e.target.value), 15 | }, 16 | headers: { 17 | "Content-Type": "application/json", 18 | Authorization: "Bearer " + token, 19 | }, 20 | } 21 | ); 22 | }; 23 | return ( 24 | 25 | setVolume(e)} min={0} max={100} /> 26 | 27 | ); 28 | } 29 | 30 | const Container = styled.div` 31 | display: flex; 32 | justify-content: flex-end; 33 | align-content: center; 34 | input { 35 | width: 15rem; 36 | border-radius: 2rem; 37 | height: 0.5rem; 38 | } 39 | `; 40 | -------------------------------------------------------------------------------- /src/index.css: -------------------------------------------------------------------------------- 1 | body { 2 | font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", "Roboto", "Oxygen", 3 | "Ubuntu", "Cantarell", "Fira Sans", "Droid Sans", "Helvetica Neue", 4 | sans-serif; 5 | -webkit-font-smoothing: antialiased; 6 | -moz-osx-font-smoothing: grayscale; 7 | } 8 | 9 | * { 10 | margin: 0; 11 | padding: 0; 12 | box-sizing: border-box; 13 | } 14 | -------------------------------------------------------------------------------- /src/index.js: -------------------------------------------------------------------------------- 1 | import React from "react"; 2 | import ReactDOM from "react-dom"; 3 | import "./index.css"; 4 | import App from "./App.jsx"; 5 | import { StateProvider } from "./utils/StateProvider"; 6 | import reducer, { initialState } from "./utils/Reducer"; 7 | ReactDOM.render( 8 | 9 | 10 | 11 | 12 | , 13 | document.getElementById("root") 14 | ); 15 | -------------------------------------------------------------------------------- /src/utils/Constants.js: -------------------------------------------------------------------------------- 1 | export const reducerCases = { 2 | SET_TOKEN: "SET_TOKEN", 3 | SET_USER: "SET_USER", 4 | SET_PLAYLISTS: "SET_PLAYLISTS", 5 | SET_PLAYING: "SET_PLAYING", 6 | SET_PLAYER_STATE: "SET_PLAYER_STATE", 7 | SET_PLAYLIST: "SET_PLAYLIST", 8 | SET_PLAYLIST_ID: "SET_PLAYLIST_ID", 9 | }; 10 | -------------------------------------------------------------------------------- /src/utils/Reducer.js: -------------------------------------------------------------------------------- 1 | import { reducerCases } from "./Constants"; 2 | 3 | export const initialState = { 4 | token: null, 5 | userInfo: null, 6 | playlists: [], 7 | currentPlaying: null, 8 | playerState: false, 9 | selectedPlaylist: null, 10 | selectedPlaylistId: "37i9dQZF1E37jO8SiMT0yN", 11 | }; 12 | 13 | const reducer = (state, action) => { 14 | switch (action.type) { 15 | case reducerCases.SET_TOKEN: 16 | return { 17 | ...state, 18 | token: action.token, 19 | }; 20 | case reducerCases.SET_USER: 21 | return { 22 | ...state, 23 | userInfo: action.userInfo, 24 | }; 25 | case reducerCases.SET_PLAYLISTS: 26 | return { 27 | ...state, 28 | playlists: action.playlists, 29 | }; 30 | case reducerCases.SET_PLAYING: 31 | return { 32 | ...state, 33 | currentPlaying: action.currentPlaying, 34 | }; 35 | case reducerCases.SET_PLAYER_STATE: 36 | return { 37 | ...state, 38 | playerState: action.playerState, 39 | }; 40 | case reducerCases.SET_PLAYLIST: 41 | return { 42 | ...state, 43 | selectedPlaylist: action.selectedPlaylist, 44 | }; 45 | case reducerCases.SET_PLAYLIST_ID: 46 | return { 47 | ...state, 48 | selectedPlaylistId: action.selectedPlaylistId, 49 | }; 50 | default: 51 | return state; 52 | } 53 | }; 54 | 55 | export default reducer; 56 | -------------------------------------------------------------------------------- /src/utils/StateProvider.jsx: -------------------------------------------------------------------------------- 1 | import { createContext, useContext, useReducer } from "react"; 2 | 3 | export const StateContext = createContext(); 4 | 5 | export const StateProvider = ({ initialState, reducer, children }) => ( 6 | 7 | {children} 8 | 9 | ); 10 | 11 | export const useStateProvider = () => useContext(StateContext); 12 | --------------------------------------------------------------------------------