import './App.css';
import * as action from './actions'
import * as reducer from './reducers'
import * as Logcomp from './components/Login'
import * as Sidebar from './components/Sidebar'
import * as Page from './components/Page'
import {PlayerbarConnect} from './components/Playerbar'
import thunk from 'redux-thunk';
import { createStore, combineReducers, applyMiddleware } from 'redux';
import { Provider } from 'react-redux';
import { Link, Route, Router, Switch } from 'react-router-dom';
import createHistory from 'history/createBrowserHistory'
export function jwtDecode(token) {
try {
let decoded = token.split('.')
decoded = decoded[1]
decoded = atob(decoded)
decoded = JSON.parse(decoded)
return decoded
}
catch (e) {
return;
}
}
export const getGQL = url =>
(query, variables = {}) =>
fetch(url, {
method: 'POST',
headers: {
"Content-Type": "application/json",
...(localStorage.authToken ? { "Authorization": "Bearer " + localStorage.authToken } : {})
},
body: JSON.stringify({ query, variables })
})
.then(res => res.json())
.then(data => {
if (data.errors && !data.data) throw new Error(JSON.stringify(data.errors))
return data.data[Object.keys(data.data)[0]]
})
export const history = createHistory()
export const backendURL = "http://player.asmer.fs.a-level.com.ua"
export const gql = getGQL(backendURL + '/graphql')
const store = createStore(
combineReducers(
{
promise: reducer.promiseReducer,
auth: reducer.authReducer,
player: reducer.playerReducer
//local: localStoreReducer(promiseReducer, 'locale')
}
), applyMiddleware(thunk)
)
store.subscribe(() => console.log(store.getState()))
//works only once on start of page
if (store.getState().auth?.token) {
history.push('/player')
store.dispatch(action.actionGetUserData())
store.dispatch(action.actionGetUserPlaylists())
} else {
history.push('/login')
}
const PlayerBar = () => {
return (
)
}
const Player = () =>
<>
Welcome to online Player!
- Click "NEW PLAYLIST" - To create new playlist.
- Drag 'n' drop track to playlist area - To upload the track and add it to current playlist.
- Drag a track within playlist - To chage the order of playlist tracks.
- Click "MY TRACKS" - To see all of your uploaded tracks.
>
{/*
*/}
function App() {
return (
);
}
export default App;