|
@@ -6,9 +6,8 @@ import * as Sidebar from './components/Sidebar'
|
|
import * as Page from './components/Page'
|
|
import * as Page from './components/Page'
|
|
|
|
|
|
import thunk from 'redux-thunk';
|
|
import thunk from 'redux-thunk';
|
|
-import { useEffect, useState } from 'react';
|
|
|
|
import { createStore, combineReducers, applyMiddleware } from 'redux';
|
|
import { createStore, combineReducers, applyMiddleware } from 'redux';
|
|
-import { Provider, connect } from 'react-redux';
|
|
|
|
|
|
+import { Provider } from 'react-redux';
|
|
import { Link, Route, Router, Switch } from 'react-router-dom';
|
|
import { Link, Route, Router, Switch } from 'react-router-dom';
|
|
import createHistory from 'history/createBrowserHistory'
|
|
import createHistory from 'history/createBrowserHistory'
|
|
|
|
|
|
@@ -19,7 +18,7 @@ export function jwtDecode(token) {
|
|
decoded = atob(decoded)
|
|
decoded = atob(decoded)
|
|
decoded = JSON.parse(decoded)
|
|
decoded = JSON.parse(decoded)
|
|
return decoded
|
|
return decoded
|
|
- }
|
|
|
|
|
|
+ }
|
|
catch (e) {
|
|
catch (e) {
|
|
return;
|
|
return;
|
|
}
|
|
}
|
|
@@ -56,7 +55,7 @@ const store = createStore(
|
|
)
|
|
)
|
|
store.subscribe(() => console.log(store.getState()))
|
|
store.subscribe(() => console.log(store.getState()))
|
|
//works only once on start of page
|
|
//works only once on start of page
|
|
-if(store.getState().auth?.token) {
|
|
|
|
|
|
+if (store.getState().auth?.token) {
|
|
history.push('/player')
|
|
history.push('/player')
|
|
store.dispatch(action.actionGetUserData())
|
|
store.dispatch(action.actionGetUserData())
|
|
store.dispatch(action.actionGetUserPlaylists())
|
|
store.dispatch(action.actionGetUserPlaylists())
|
|
@@ -64,62 +63,24 @@ if(store.getState().auth?.token) {
|
|
history.push('/login')
|
|
history.push('/login')
|
|
}
|
|
}
|
|
|
|
|
|
-const ProfileWindow = ({user, onLogout}) => {
|
|
|
|
- let [userInfo, setUserInfo] = useState(user.payload)
|
|
|
|
-
|
|
|
|
- useEffect(()=> {
|
|
|
|
- setUserInfo(user.payload)
|
|
|
|
- },[user, userInfo])
|
|
|
|
-
|
|
|
|
- return(
|
|
|
|
- <section>
|
|
|
|
- <div
|
|
|
|
- style={{ border: '1px solid black', backgroundColor: 'red', color: 'white' }}
|
|
|
|
- onClick={() => { onLogout(); history.push('/login') }}
|
|
|
|
- >log-out[X]</div>
|
|
|
|
- <div style={{border:'1px solid chartreuse'}}>
|
|
|
|
- <h3>{userInfo?.login || 'user'}</h3>
|
|
|
|
- <img
|
|
|
|
- width={100}
|
|
|
|
- height={100}
|
|
|
|
- style={{ border: '1px solid black', display:'block', margin:'5% auto', marginBottom:'2px'}}
|
|
|
|
- src={ userInfo?.avatar?.url ? backendURL + '/' + userInfo?.avatar?.url : ''}
|
|
|
|
- alt='avatar'
|
|
|
|
- />
|
|
|
|
- <small>change avavtar</small>
|
|
|
|
- </div>
|
|
|
|
- <Link
|
|
|
|
- to={`/player/tracks/:${userInfo?._id}`}
|
|
|
|
- style={{
|
|
|
|
- display:'block',
|
|
|
|
- backgroundColor: 'purple',
|
|
|
|
- color: 'white',
|
|
|
|
- margin: '5px',
|
|
|
|
- padding:'5px'
|
|
|
|
- }}
|
|
|
|
- >My tracks</Link>
|
|
|
|
- </section>
|
|
|
|
- )
|
|
|
|
-}
|
|
|
|
-const ProfileWindowConnect = connect(state => ({ user: state.promise.userData || {} }),{ onLogout: action.actionAuthLogout })(ProfileWindow)
|
|
|
|
-
|
|
|
|
-
|
|
|
|
-const Player = () =>
|
|
|
|
|
|
+const Player = () =>
|
|
<>
|
|
<>
|
|
- <header>Player</header>
|
|
|
|
|
|
+ <header><Link to="/player">Player</Link></header>
|
|
<div style={{ display: 'flex' }}>
|
|
<div style={{ display: 'flex' }}>
|
|
<aside style={{ border: '1px solid black', width: '30%' }}>
|
|
<aside style={{ border: '1px solid black', width: '30%' }}>
|
|
- <ProfileWindowConnect />
|
|
|
|
|
|
+ <Sidebar.LogoutBtnConnect />
|
|
|
|
+ <Sidebar.ProfileWindowDropzoneConnect />
|
|
|
|
+ <Sidebar.UserTracksBtnConnect />
|
|
<Sidebar.PlaylistsConnect />
|
|
<Sidebar.PlaylistsConnect />
|
|
</aside>
|
|
</aside>
|
|
<main style={{ border: '1px solid black', width: '80%' }}>
|
|
<main style={{ border: '1px solid black', width: '80%' }}>
|
|
<Switch>
|
|
<Switch>
|
|
- <Route path="/player/playlist/:_id" component={Page.PlaylistPageConnect} exact/>
|
|
|
|
- <Route path="/player/tracks/:_id" component={Page.UserTrackDropzoneConnect} exact/>
|
|
|
|
|
|
+ <Route path="/player/playlist/:_id" component={Page.PlaylistPageConnect} exact />
|
|
|
|
+ <Route path="/player/tracks/:_id" component={Page.UserTracksPageConnect} exact />
|
|
<>
|
|
<>
|
|
<h2>Welcome to online Player!</h2>
|
|
<h2>Welcome to online Player!</h2>
|
|
- <div style={{width:'50%',margin: '0 auto'}}>
|
|
|
|
- <ul style={{textAlign:'start'}}>
|
|
|
|
|
|
+ <div style={{ width: '50%', margin: '0 auto' }}>
|
|
|
|
+ <ul style={{ textAlign: 'start' }}>
|
|
<li><strong>To create playlist: </strong>click "NEW PLAYLIST"</li>
|
|
<li><strong>To create playlist: </strong>click "NEW PLAYLIST"</li>
|
|
<li><strong>To upload track: </strong>drag and drop it to playlist area</li>
|
|
<li><strong>To upload track: </strong>drag and drop it to playlist area</li>
|
|
<li><strong>To see list of all your tracks: </strong>click "My tracks"</li>
|
|
<li><strong>To see list of all your tracks: </strong>click "My tracks"</li>
|
|
@@ -132,11 +93,6 @@ const Player = () =>
|
|
<footer> back stop forw</footer>
|
|
<footer> back stop forw</footer>
|
|
</>
|
|
</>
|
|
|
|
|
|
-// const PlayerConnect = connect(
|
|
|
|
-// state => ({ user: state.promise.userData || {} }),{ onLogout: action.actionAuthLogout}
|
|
|
|
-// )(Player)
|
|
|
|
-
|
|
|
|
-
|
|
|
|
function App() {
|
|
function App() {
|
|
return (
|
|
return (
|
|
<Router history={history}>
|
|
<Router history={history}>
|