Login and artist search pages
This commit is contained in:
parent
3802bce17d
commit
f4dce4653f
5 changed files with 50 additions and 24 deletions
27
src/App.js
27
src/App.js
|
@ -1,29 +1,10 @@
|
||||||
import React, { useState, useEffect } from 'react'
|
import React from 'react'
|
||||||
import logo from './logo.svg'
|
import Router from './components/Router'
|
||||||
import './App.css'
|
|
||||||
|
|
||||||
function App() {
|
function App() {
|
||||||
let [token, setToken] = useState(null)
|
|
||||||
|
|
||||||
useEffect(() => {
|
|
||||||
const search = window.location.search
|
|
||||||
const params = new URLSearchParams(search)
|
|
||||||
setToken(params.get('access_token'))
|
|
||||||
}, [])
|
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<div className="App">
|
<div className="app">
|
||||||
<header className="App-header">
|
<Router />
|
||||||
<img src={logo} className="App-logo" alt="logo" />
|
|
||||||
|
|
||||||
<p>
|
|
||||||
Edit <code>src/App.js</code> and save to reload.
|
|
||||||
</p>
|
|
||||||
|
|
||||||
<a href='http://localhost:8888/login' className='App-link'> Login to Spotify </a>
|
|
||||||
|
|
||||||
<p>{token}</p>
|
|
||||||
</header>
|
|
||||||
</div>
|
</div>
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
|
|
20
src/components/Router.jsx
Normal file
20
src/components/Router.jsx
Normal file
|
@ -0,0 +1,20 @@
|
||||||
|
import React from 'react'
|
||||||
|
import { Router as ReactRouter, Route, Switch } from 'react-router-dom'
|
||||||
|
import history from '../history.js'
|
||||||
|
import ArtistSearch from '../views/ArtistSearch'
|
||||||
|
import Login from '../views/Login'
|
||||||
|
|
||||||
|
history.listen(() => {
|
||||||
|
window.scrollTo(0, 0)
|
||||||
|
})
|
||||||
|
|
||||||
|
export default function Router() {
|
||||||
|
return (
|
||||||
|
<ReactRouter history={history}>
|
||||||
|
<Switch>
|
||||||
|
<Route exact path="/" render={() => <Login />} />
|
||||||
|
<Route exact path="/artist-search" render={() => <ArtistSearch />} />
|
||||||
|
</Switch>
|
||||||
|
</ReactRouter>
|
||||||
|
)
|
||||||
|
}
|
3
src/history.js
Normal file
3
src/history.js
Normal file
|
@ -0,0 +1,3 @@
|
||||||
|
import { createBrowserHistory } from 'history'
|
||||||
|
|
||||||
|
export default createBrowserHistory()
|
|
@ -2,6 +2,7 @@ import React, { useState, useEffect } from 'react'
|
||||||
|
|
||||||
function ArtistSearch() {
|
function ArtistSearch() {
|
||||||
let [token, setToken] = useState(null)
|
let [token, setToken] = useState(null)
|
||||||
|
let [search, setSearch] = useState(null)
|
||||||
|
|
||||||
useEffect(() => {
|
useEffect(() => {
|
||||||
const search = window.location.search
|
const search = window.location.search
|
||||||
|
@ -9,11 +10,19 @@ function ArtistSearch() {
|
||||||
setToken(params.get('access_token'))
|
setToken(params.get('access_token'))
|
||||||
}, [])
|
}, [])
|
||||||
|
|
||||||
|
useEffect(() => {
|
||||||
|
console.log(search)
|
||||||
|
}, [search])
|
||||||
|
|
||||||
|
const handleChange = e => {
|
||||||
|
setSearch(e.currentTarget.value)
|
||||||
|
}
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<div className="artist-search">
|
<div className="artist-search">
|
||||||
<h1>Artist search</h1>
|
<h1>Artist search</h1>
|
||||||
|
|
||||||
<p>{token}</p>
|
<input placeholder='Search for an artist' onChange={handleChange} />
|
||||||
</div>
|
</div>
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
|
|
13
src/views/Login.jsx
Normal file
13
src/views/Login.jsx
Normal file
|
@ -0,0 +1,13 @@
|
||||||
|
import React from 'react'
|
||||||
|
|
||||||
|
function Login() {
|
||||||
|
return (
|
||||||
|
<div className="artist-search">
|
||||||
|
<h1>Touch Tunes</h1>
|
||||||
|
|
||||||
|
<a href='http://localhost:8888/login' className='App-link'> Login to Spotify </a>
|
||||||
|
</div>
|
||||||
|
)
|
||||||
|
}
|
||||||
|
|
||||||
|
export default Login
|
Loading…
Add table
Add a link
Reference in a new issue