initialized

This commit is contained in:
dinotutic 2022-11-20 17:12:41 +01:00
commit be4c708718
30 changed files with 29967 additions and 0 deletions

23
.gitignore vendored Normal file
View File

@ -0,0 +1,23 @@
# See https://help.github.com/articles/ignoring-files/ for more about ignoring files.
# dependencies
/node_modules
/.pnp
.pnp.js
# testing
/coverage
# production
/build
# misc
.DS_Store
.env.local
.env.development.local
.env.test.local
.env.production.local
npm-debug.log*
yarn-debug.log*
yarn-error.log*

4
.vscode/settings.json vendored Normal file
View File

@ -0,0 +1,4 @@
{
"editor.defaultFormatter": "esbenp.prettier-vscode",
"editor.formatOnSave": true
}

70
README.md Normal file
View File

@ -0,0 +1,70 @@
# Getting Started with Create React App
This project was bootstrapped with [Create React App](https://github.com/facebook/create-react-app).
## Available Scripts
In the project directory, you can run:
### `npm start`
Runs the app in the development mode.\
Open [http://localhost:3000](http://localhost:3000) to view it in your browser.
The page will reload when you make changes.\
You may also see any lint errors in the console.
### `npm test`
Launches the test runner in the interactive watch mode.\
See the section about [running tests](https://facebook.github.io/create-react-app/docs/running-tests) for more information.
### `npm run build`
Builds the app for production to the `build` folder.\
It correctly bundles React in production mode and optimizes the build for the best performance.
The build is minified and the filenames include the hashes.\
Your app is ready to be deployed!
See the section about [deployment](https://facebook.github.io/create-react-app/docs/deployment) for more information.
### `npm run eject`
**Note: this is a one-way operation. Once you `eject`, you can't go back!**
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.
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.
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.
## Learn More
You can learn more in the [Create React App documentation](https://facebook.github.io/create-react-app/docs/getting-started).
To learn React, check out the [React documentation](https://reactjs.org/).
### Code Splitting
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)
### Analyzing the Bundle Size
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)
### Making a Progressive Web App
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)
### Advanced Configuration
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)
### Deployment
This section has moved here: [https://facebook.github.io/create-react-app/docs/deployment](https://facebook.github.io/create-react-app/docs/deployment)
### `npm run build` fails to minify
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)

29057
package-lock.json generated Normal file

File diff suppressed because it is too large Load Diff

38
package.json Normal file
View File

@ -0,0 +1,38 @@
{
"name": "jamming",
"version": "0.1.0",
"private": true,
"dependencies": {
"@testing-library/jest-dom": "^5.16.5",
"@testing-library/react": "^13.4.0",
"@testing-library/user-event": "^13.5.0",
"react": "^18.2.0",
"react-dom": "^18.2.0",
"react-scripts": "5.0.1",
"web-vitals": "^2.1.4"
},
"scripts": {
"start": "react-scripts start",
"build": "react-scripts build",
"test": "react-scripts test",
"eject": "react-scripts eject"
},
"eslintConfig": {
"extends": [
"react-app",
"react-app/jest"
]
},
"browserslist": {
"production": [
">0.2%",
"not dead",
"not op_mini all"
],
"development": [
"last 1 chrome version",
"last 1 firefox version",
"last 1 safari version"
]
}
}

BIN
public/favicon.ico Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 11 KiB

52
public/index.html Normal file
View File

@ -0,0 +1,52 @@
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="utf-8" />
<link rel="icon" href="%PUBLIC_URL%/favicon.ico" />
<meta name="viewport" content="width=device-width, initial-scale=1" />
<meta name="theme-color" content="#000000" />
<meta
name="description"
content="Web site created using create-react-app"
/>
<link rel="stylesheet" type="text/css" href="reset.css" />
<link
rel="stylesheet"
href="https://fonts.googleapis.com/css?family=Poppins:600"
/>
<link
rel="stylesheet"
href="https://fonts.googleapis.com/css?family=Work%20Sans:300,500"
/>
<link rel="apple-touch-icon" href="%PUBLIC_URL%/logo192.png" />
<!--
manifest.json provides metadata used when your web app is installed on a
user's mobile device or desktop. See https://developers.google.com/web/fundamentals/web-app-manifest/
-->
<link rel="manifest" href="%PUBLIC_URL%/manifest.json" />
<!--
Notice the use of %PUBLIC_URL% in the tags above.
It will be replaced with the URL of the `public` folder during the build.
Only files inside the `public` folder can be referenced from the HTML.
Unlike "/favicon.ico" or "favicon.ico", "%PUBLIC_URL%/favicon.ico" will
work correctly both with client-side routing and a non-root public URL.
Learn how to configure a non-root public URL by running `npm run build`.
-->
<title>Jamming</title>
</head>
<body>
<noscript>You need to enable JavaScript to run this app.</noscript>
<div id="root"></div>
<!--
This HTML file is a template.
If you open it directly in the browser, you will see an empty page.
You can add webfonts, meta tags, or analytics to this file.
The build step will place the bundled scripts into the <body> tag.
To begin the development, run `npm start` or `yarn start`.
To create a production bundle, use `npm run build` or `yarn build`.
-->
</body>
</html>

BIN
public/logo192.png Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 5.2 KiB

BIN
public/logo512.png Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 9.4 KiB

25
public/manifest.json Normal file
View File

@ -0,0 +1,25 @@
{
"short_name": "React App",
"name": "Create React App Sample",
"icons": [
{
"src": "favicon.ico",
"sizes": "64x64 32x32 24x24 16x16",
"type": "image/x-icon"
},
{
"src": "logo192.png",
"type": "image/png",
"sizes": "192x192"
},
{
"src": "logo512.png",
"type": "image/png",
"sizes": "512x512"
}
],
"start_url": ".",
"display": "standalone",
"theme_color": "#000000",
"background_color": "#ffffff"
}

124
public/reset.css Normal file
View File

@ -0,0 +1,124 @@
html,
body,
div,
span,
applet,
object,
iframe,
h1,
h2,
h3,
h4,
h5,
h6,
p,
blockquote,
pre,
a,
abbr,
acronym,
address,
big,
cite,
code,
del,
dfn,
em,
img,
ins,
kbd,
q,
s,
samp,
small,
strike,
strong,
sub,
sup,
tt,
var,
b,
u,
i,
center,
dl,
dt,
dd,
ol,
ul,
li,
fieldset,
form,
label,
legend,
table,
caption,
tbody,
tfoot,
thead,
tr,
th,
td,
article,
aside,
canvas,
details,
embed,
figure,
figcaption,
footer,
header,
hgroup,
menu,
nav,
output,
ruby,
section,
summary,
time,
mark,
audio,
video {
margin: 0;
padding: 0;
border: 0;
font-size: 100%;
font: inherit;
vertical-align: baseline;
}
/* HTML5 display-role reset for older browsers */
article,
aside,
details,
figcaption,
figure,
footer,
header,
hgroup,
menu,
nav,
section {
display: block;
}
body {
line-height: 1;
}
ol,
ul {
list-style: none;
}
blockquote,
q {
quotes: none;
}
blockquote:before,
blockquote:after,
q:before,
q:after {
content: "";
content: none;
}
table {
border-collapse: collapse;
border-spacing: 0;
}

3
public/robots.txt Normal file
View File

@ -0,0 +1,3 @@
# https://www.robotstxt.org/robotstxt.html
User-agent: *
Disallow:

View File

@ -0,0 +1,52 @@
body,
html,
#root {
height: 100%;
}
html {
font-size: 18px;
}
h1 {
padding: 0.77rem 0;
background-color: #010c3f;
text-align: center;
font-family: "Poppins", sans-serif;
font-size: 1.88rem;
color: #fff;
}
h1 .highlight {
color: #6c41ec;
}
h2 {
font-family: "Poppins", sans-serif;
font-size: 1.55rem;
}
.App {
height: 100%;
padding: 0 17% 10% 17%;
background-image: url("./background_photo_desktop.jpg");
background-size: cover;
background-position: center;
background-repeat: no-repeat;
font-family: "Work Sans", sans-serif;
font-weight: 500;
color: #fff;
}
.App-playlist {
display: flex;
justify-content: space-between;
width: 100%;
}
@media only screen and (max-width: 1020px) {
.App-playlist {
align-items: center;
flex-direction: column;
}
}

79
src/Components/App/App.js Normal file
View File

@ -0,0 +1,79 @@
import React from "react";
import "./App.css";
import SearchBar from "../SearchBar/SearchBar";
import SearchResults from "../SearchResults/SearchResults";
import Playlist from "../Playlist/Playlist";
import Spotify from "../../util/Spotify";
class App extends React.Component {
constructor(props) {
super(props);
this.state = {
searchResults: [],
playlistName: "My Playlist",
playlistTracks: [],
};
this.addTrack = this.addTrack.bind(this);
this.removeTrack = this.removeTrack.bind(this);
this.updatePlaylistName = this.updatePlaylistName.bind(this);
this.savePlaylist = this.savePlaylist.bind(this);
this.search = this.search.bind(this);
}
addTrack(track) {
let tracks = this.state.playlistTracks;
if (tracks.find((savedTrack) => savedTrack.id === track.id)) {
return;
}
tracks.push(track);
this.setState({ playlistTracks: tracks });
}
removeTrack = (track) => {
let tracks = this.state.playlistTracks;
tracks = tracks.filter((selectedTrack) => selectedTrack !== track);
this.setState({ playlistTracks: tracks });
};
updatePlaylistName = (name) => {
this.setState({ playlistName: name });
};
savePlaylist = () => {
const trackUris = this.state.playlistTracks.map((track) => track.uri);
Spotify.savePlaylist(this.state.playlistName, trackUris).then(() => {
this.setState({
playlistName: "New Playlist",
playlistTracks: [],
});
});
};
search = (term) => {
Spotify.search(term).then((searchResults) => {
this.setState({ searchResults: searchResults });
});
};
render() {
return (
<div>
<h1>
Ja<span className="highlight">mmm</span>ing
</h1>
<div className="App">
<SearchBar />
<div className="App-playlist" onSearch={this.search}>
<SearchResults
searchResults={this.state.searchResults}
onAdd={this.addTrack}
/>
<Playlist
playlistName={this.state.playlistName}
playlistTracks={this.state.playlistTracks}
onRemove={this.removeTrack}
onNameChange={this.updatePlaylistName}
onSave={this.savePlaylist}
/>
</div>
</div>
</div>
);
}
}
export default App;

Binary file not shown.

After

Width:  |  Height:  |  Size: 3.3 MiB

View File

@ -0,0 +1,52 @@
.Playlist {
display: flex;
flex-direction: column;
align-items: center;
overflow-y: scroll;
width: 37%;
max-height: 950px;
padding: 2.27rem 1.16rem;
background-color: rgba(1, 12, 63, 0.7);
box-shadow: 0 4px 2px 2px #000000;
}
.Playlist input {
width: 100%;
border: 0;
outline: 0;
background: transparent;
border-bottom: 1px solid #6f6f6f;
font-family: "Poppins", sans-serif;
font-size: 1.55rem;
color: #fff;
}
.Playlist-save {
cursor: pointer;
width: 10rem;
padding: 0.77rem 0;
border-radius: 54px;
border-width: 0px;
margin-top: 1.27rem;
background-color: #6c41ec;
text-align: center;
font-size: 0.83rem;
transition: background-color 0.25s;
color: #fff;
font-weight: 500;
}
.Playlist-save:hover {
background-color: rgba(108, 65, 233, 0.7);
}
::-webkit-scrollbar {
width: 0px;
background: transparent;
}
@media only screen and (max-width: 1020px) {
.Playlist {
width: 90%;
}
}

View File

@ -0,0 +1,31 @@
import React from "react";
import "./Playlist.css";
import Tracklist from "../Tracklist/Tracklist";
class Playlist extends React.Component {
constructor(props) {
super(props);
this.handleNameChange = this.handleNameChange.bind(this);
}
handleNameChange = (e) => {
this.props.onNameChange(e.target.value);
};
render() {
return (
<div className="Playlist">
<input defaultValue={"New Playlist"} onChange={this.handleNameChange} />
<Tracklist
tracks={this.props.playlistTracks}
onRemove={this.props.onRemove}
isRemoval={true}
/>
<button className="Playlist-save" onClick={this.props.onSave}>
SAVE TO SPOTIFY
</button>
</div>
);
}
}
export default Playlist;

View File

@ -0,0 +1,40 @@
.SearchBar {
display: flex;
flex-direction: column;
align-items: center;
padding-top: 6.94rem;
margin-bottom: 6.33rem;
}
.SearchBar input {
width: 287px;
padding: 0.88rem 0;
border: 1px solid #fff;
border-radius: 3px;
margin-bottom: 2.22rem;
color: #010c3f;
text-align: center;
font-size: 1rem;
}
.SearchBar input:focus {
outline: none;
}
.SearchButton {
cursor: pointer;
width: 8.11rem;
padding: 0.77rem 0;
border-radius: 54px;
background-color: #010c3f;
text-align: center;
font-size: 0.833rem;
transition: background-color 0.25s;
border: 0px;
color: #fff;
font-weight: 500;
}
.SearchButton:hover {
background-color: rgba(108, 65, 233, 0.7);
}

View File

@ -0,0 +1,31 @@
import React from "react";
import "./SearchBar.css";
class SearchBar extends React.Component {
constructor(props) {
super(props);
this.search = this.search.bind(this);
this.state = {
term: "",
};
}
search = () => {
this.props.onSearch(this.state.term);
};
handleTermChange = (event) => {
this.setState({ term: event.target.value });
};
render() {
return (
<div className="SearchBar">
<input
placeholder="Enter A Song, Album, or Artist"
onChange={this.handleTermChange}
/>
<button className="SearchButton">SEARCH</button>
</div>
);
}
}
export default SearchBar;

View File

@ -0,0 +1,20 @@
.SearchResults {
width: 50%;
height: 950px;
overflow-y: scroll;
padding: 0.88rem;
background-color: rgba(1, 12, 63, 0.7);
box-shadow: 0 4px 2px 2px #000000;
}
::-webkit-scrollbar {
width: 0px;
background: transparent;
}
@media only screen and (max-width: 1020px) {
.SearchResults {
width: 90%;
margin-bottom: 2rem;
}
}

View File

@ -0,0 +1,20 @@
import React from "react";
import "./SearchResults.css";
import Tracklist from "../Tracklist/Tracklist";
class SearchResults extends React.Component {
render() {
return (
<div className="SearchResults">
<h2>Results</h2>
<Tracklist
tracks={this.props.searchResults}
onAdd={this.props.onAdd}
isRemoval={false}
/>
</div>
);
}
}
export default SearchResults;

View File

@ -0,0 +1,37 @@
.Track {
display: flex;
align-items: center;
border-bottom: 1px solid rgba(256, 256, 256, 0.8);
}
.Track-action {
cursor: pointer;
padding: 0.5rem;
font-size: 1.05rem;
transition: color 0.25s;
border: 0px;
background-color: rgba(0, 0, 0, 0);
color: #fff;
}
.Track-action:hover {
color: rgba(265, 265, 265, 0.5);
}
.Track-information {
flex-grow: 1;
display: flex;
flex-direction: column;
justify-content: center;
height: 72px;
}
.Track-information h3 {
margin-bottom: 0.22rem;
}
.Track-information p {
font-size: 0.83rem;
font-weight: 300;
color: rgba(256, 256, 256, 0.8);
}

View File

@ -0,0 +1,47 @@
import React from "react";
import "./Track.css";
class Track extends React.Component {
constructor(props) {
super(props);
this.addTrack = this.addTrack.bind(this);
this.removeTrack = this.removeTrack.bind(this);
}
addTrack = () => {
this.props.onAdd(this.props.track);
};
removeTrack = () => {
this.props.onRemove(this.props.track);
};
renderAction() {
if (this.props.isRemoval) {
return (
<button className="Track-action" onClick={this.removeTrack}>
-
</button>
);
} else {
return (
<button className="Track-action" onClick={this.addTrack}>
+
</button>
);
}
}
render() {
return (
<div className="Track">
<div className="Track-information">
<h3>{this.props.track.name}</h3>
<p>
{this.props.track.artist} | {this.props.track.album}
</p>
</div>
{this.renderAction()}
</div>
);
}
}
export default Track;

View File

@ -0,0 +1,3 @@
.TrackList {
width: 100%;
}

View File

@ -0,0 +1,26 @@
import React from "react";
import "./Tracklist.css";
import Track from "../Track/Track";
import { toHaveFocus } from "@testing-library/jest-dom/dist/matchers";
class Tracklist extends React.Component {
render() {
return (
<div className="TrackList">
{this.props.tracks.map((track) => {
return (
<Track
track={track}
key={track.id}
onAdd={this.props.onAdd}
onRemove={this.props.onRemove}
isRemoval={this.props.isRemoval}
/>
);
})}
</div>
);
}
}
export default Tracklist;

13
src/index.css Normal file
View File

@ -0,0 +1,13 @@
body {
margin: 0;
font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', 'Roboto', 'Oxygen',
'Ubuntu', 'Cantarell', 'Fira Sans', 'Droid Sans', 'Helvetica Neue',
sans-serif;
-webkit-font-smoothing: antialiased;
-moz-osx-font-smoothing: grayscale;
}
code {
font-family: source-code-pro, Menlo, Monaco, Consolas, 'Courier New',
monospace;
}

17
src/index.js Normal file
View File

@ -0,0 +1,17 @@
import React from 'react';
import ReactDOM from 'react-dom/client';
import './index.css';
import App from './Components/App/App.js';
import reportWebVitals from './reportWebVitals';
const root = ReactDOM.createRoot(document.getElementById('root'));
root.render(
<React.StrictMode>
<App />
</React.StrictMode>
);
// If you want to start measuring performance in your app, pass a function
// to log results (for example: reportWebVitals(console.log))
// or send to an analytics endpoint. Learn more: https://bit.ly/CRA-vitals
reportWebVitals();

13
src/reportWebVitals.js Normal file
View File

@ -0,0 +1,13 @@
const reportWebVitals = onPerfEntry => {
if (onPerfEntry && onPerfEntry instanceof Function) {
import('web-vitals').then(({ getCLS, getFID, getFCP, getLCP, getTTFB }) => {
getCLS(onPerfEntry);
getFID(onPerfEntry);
getFCP(onPerfEntry);
getLCP(onPerfEntry);
getTTFB(onPerfEntry);
});
}
};
export default reportWebVitals;

5
src/setupTests.js Normal file
View File

@ -0,0 +1,5 @@
// jest-dom adds custom jest matchers for asserting on DOM nodes.
// allows you to do things like:
// expect(element).toHaveTextContent(/react/i)
// learn more: https://github.com/testing-library/jest-dom
import '@testing-library/jest-dom';

85
src/util/Spotify.js Normal file
View File

@ -0,0 +1,85 @@
const clientId = "c39c93bbf05745fb986d1e566004eb31";
const redirectUri = "http://localhost:3000/";
let accessToken = "";
export const Spotify = {
getAccessToken() {
if (accessToken) {
return accessToken;
}
//check for access token match
const accessTokenMatch = window.location.href.match(/access_token=([^&]*)/);
const expiresInMatch = window.location.href.match(/expires_in=([^&]*)/);
if (accessTokenMatch && expiresInMatch) {
accessToken = accessTokenMatch[1];
const expiresIn = Number(expiresInMatch[1]);
//This clears the parameters, allowing us to grab a new access token when it expires.
window.setTimeout(() => (accessToken = ""), expiresIn * 1000);
window.history.pushState("Access Token", null, "/");
return accessToken;
} else {
const accessUrl = `https://accounts.spotify.com/authorize?client_id=${clientId}&response_type=
token&scope=playlist-modify-public&redirect_uri=${redirectUri}`;
window.location = accessUrl;
}
},
search(term) {
const accessToken = Spotify.getAccessToken();
return fetch(`https://api.spotify.com/v1/search?type=track&q=${term}`, {
headers: {
Authorization: `Bearer ${accessToken}`,
},
})
.then((response) => {
return response.json();
})
.then((jsonResponse) => {
if (!jsonResponse.tracks) {
return [];
}
return jsonResponse.tracks.items.map((track) => ({
id: track.id,
name: track.name,
artist: track.artists[0].name,
album: track.album.name,
uri: track.uri,
}));
});
},
savePlaylist(name, trackUris) {
if (!name || !trackUris.length) {
return;
}
const accessToken = Spotify.getAccessToken;
const headers = { Authorization: `Bearer ${accessToken}` };
let userId;
return fetch(`https://api.spotify.com/v1/me`, { headers: headers })
.then((response) => response.json())
.then((jsonResponse) => {
userId = jsonResponse.Id;
return fetch(`https://api.spotify.com/v1/users/${userId}/playlists`, {
headers: headers,
method: "POST",
body: JSON.stringify({ name: name }),
})
.then((response) => response.json())
.then((jsonResponse) => {
const playlistId = jsonResponse.Id;
return fetch(
`https:/api.spotify.com/v1/users/${userId}/playlists/${playlistId}/tracks`,
{
headers: headers,
method: "POST",
body: JSON.stringify({ uris: trackUris }),
}
);
});
});
},
};
export default Spotify;