|
@@ -1,71 +1,64 @@
|
|
|
-// import {sortableContainer, sortableElement} from 'react-sortable-hoc';
|
|
|
import {SortableContainer,SortableElement} from "react-sortable-hoc";
|
|
|
-
|
|
|
import {arrayMoveImmutable} from 'array-move';
|
|
|
import {useState,useEffect} from "react";
|
|
|
-
|
|
|
import {connect} from "react-redux";
|
|
|
import {CTrack} from "../track";
|
|
|
import {CPlaylistDropZone} from "../tools";
|
|
|
import {CPreloaded} from "../preloader";
|
|
|
-
|
|
|
+import {actionFullUploadPlaylists} from "../../actions";
|
|
|
|
|
|
const SortableItem = SortableElement(CTrack);
|
|
|
|
|
|
-const MyTracks = ( {children}) =>
|
|
|
- <div className='Category'>
|
|
|
- {children}
|
|
|
- </div>
|
|
|
-
|
|
|
-
|
|
|
-
|
|
|
-const SortableList = SortableContainer(({children, tracks}) => {
|
|
|
|
|
|
+const SortableList = SortableContainer(({items}) => {
|
|
|
return (
|
|
|
- <div tracks={tracks}>
|
|
|
- {children}
|
|
|
+ <div>
|
|
|
+ {items.map((value, index) =>
|
|
|
+ <SortableItem key={`item-${value}`} index={index} trackIndex={index} track={value}/>)}
|
|
|
</div>
|
|
|
)
|
|
|
});
|
|
|
|
|
|
+function SortableComponent({playlist:{name, tracks=[]}={},onLoad}) {
|
|
|
|
|
|
-export const MyPlaylistTracks = ({match:{params:{_id}}}) =>
|
|
|
- <>
|
|
|
- <CPlaylistDropZone >
|
|
|
- <CPreloaded promiseName='playlistById'>
|
|
|
- <CSortableComponent />
|
|
|
- </CPreloaded>
|
|
|
- </CPlaylistDropZone >
|
|
|
- </>
|
|
|
-
|
|
|
+ const [state, setState] = useState(tracks || [])
|
|
|
|
|
|
-function SortableComponent({playlist=[]}) {
|
|
|
- const{name, tracks} = playlist
|
|
|
- const [state, setState] = useState(tracks)
|
|
|
useEffect(() => {
|
|
|
- setState (tracks)
|
|
|
+ setState (tracks || [])
|
|
|
},[tracks])
|
|
|
const onSortEnd = ({oldIndex, newIndex}) => {
|
|
|
setState((state) => (arrayMoveImmutable(state, oldIndex, newIndex)));
|
|
|
};
|
|
|
+ onLoad(state)
|
|
|
+
|
|
|
return (
|
|
|
<div>
|
|
|
<h2>{name}</h2>
|
|
|
- <SortableList axis={'xy'} tracks={tracks} onSortEnd={onSortEnd}>
|
|
|
- {state.map((value, index) =>
|
|
|
- <SortableItem key={`item-${value}`} trackIndex={index} track={value}/>)}
|
|
|
- </SortableList>
|
|
|
+ <SortableList axis={'y'} items={state} onSortEnd={onSortEnd}/>
|
|
|
</div>
|
|
|
)
|
|
|
}
|
|
|
|
|
|
-const CSortableComponent = connect(state => ({ playlist: state.promise.playlistById?.payload || []}))(SortableComponent)
|
|
|
|
|
|
|
|
|
+const CSortableComponent = connect(state => ({ playlist: state?.promise?.playlistById?.payload || {}}),
|
|
|
+ {onLoad:actionFullUploadPlaylists})
|
|
|
+(SortableComponent)
|
|
|
|
|
|
|
|
|
+export const MyPlaylistTracks = ({match:{params:{_id}}}) =>
|
|
|
+ <>
|
|
|
+ <CPlaylistDropZone >
|
|
|
+ <CPreloaded promiseName='playlistById'>
|
|
|
+ <CSortableComponent />
|
|
|
+ </CPreloaded>
|
|
|
+ </CPlaylistDropZone >
|
|
|
+ </>
|
|
|
+
|
|
|
+
|
|
|
+//
|
|
|
// const MyTracks = ({playlist={}}) => {
|
|
|
-// const{name, tracks} = playlist
|
|
|
+// const{name, tracks=[]} = playlist
|
|
|
// return (
|
|
|
// <div className='Category'>
|
|
|
// <h2>{name}</h2>
|
|
@@ -76,7 +69,7 @@ const CSortableComponent = connect(state => ({ playlist: state.promise.playlistB
|
|
|
// )
|
|
|
// }
|
|
|
//
|
|
|
-// const CMyTracks = connect(state => ({playlist: state.promise.playlistById?.payload || []}),)(MyTracks)
|
|
|
+// const CMyTracks = connect(state => ({playlist: state.promise.playlistById?.payload || {}}),)(MyTracks)
|
|
|
//
|
|
|
//
|
|
|
// export const MyPlaylistTracks = ({match:{params:{_id}}}) =>
|
|
@@ -85,6 +78,5 @@ const CSortableComponent = connect(state => ({ playlist: state.promise.playlistB
|
|
|
// <CMyTracks />
|
|
|
// </CPlaylistDropZone >
|
|
|
// </>
|
|
|
-
|
|
|
//
|
|
|
-//
|
|
|
+//
|