|
@@ -2,6 +2,8 @@ import { useDropzone } from 'react-dropzone';
|
|
|
import {arrayMoveImmutable} from 'array-move';
|
|
|
import {sortableContainer, sortableElement} from 'react-sortable-hoc';
|
|
|
import { useState } from 'react';
|
|
|
+import { actionPostUpsert } from '../../actions';
|
|
|
+import { connect } from 'react-redux';
|
|
|
|
|
|
const backendURL = 'http://hipstagram.asmer.fs.a-level.com.ua';
|
|
|
|
|
@@ -10,54 +12,20 @@ const backendURL = 'http://hipstagram.asmer.fs.a-level.com.ua';
|
|
|
|
|
|
|
|
|
|
|
|
-function MyDropZone({props, onLoad}) {
|
|
|
- const {acceptedFiles, getRootProps, getInputProps} = useDropzone();
|
|
|
- /* useEffect(() => {
|
|
|
- if(acceptedFiles[0]){
|
|
|
- onLoad(acceptedFiles[0])
|
|
|
- }
|
|
|
- },[acceptedFiles[0]]) */
|
|
|
- const files = acceptedFiles.map(file => (
|
|
|
- <li key={file.path}>
|
|
|
- {file.path} - {file.size} bytes
|
|
|
- </li>
|
|
|
- ));
|
|
|
-
|
|
|
- return (
|
|
|
- <section className="container">
|
|
|
- <div {...getRootProps({className: 'dropzone'})}>
|
|
|
- <input {...getInputProps()} />
|
|
|
- <p>Drag 'n' drop some files here, or click to select files</p>
|
|
|
- </div>
|
|
|
- <aside>
|
|
|
- <h4>Files</h4>
|
|
|
- <ul>{files}</ul>
|
|
|
- </aside>
|
|
|
- </section>
|
|
|
- );
|
|
|
- }
|
|
|
-
|
|
|
-
|
|
|
-
|
|
|
-let defaultPost = [{
|
|
|
- "_id": "5d6d9aa25bc6e90a3ba1afe2",
|
|
|
- "title": null,
|
|
|
- "text": "aaa",
|
|
|
- "images": [
|
|
|
- "images/1f8973225107076a4e2f2e4ac5e35e74"
|
|
|
- ,
|
|
|
- "images/d766a6cb2d3c232f3e9241abf0751cbc"
|
|
|
- ,
|
|
|
- "images/b3def30bab7249af56ef341536327fd3"
|
|
|
-
|
|
|
- ],
|
|
|
- "owner": {
|
|
|
- "_id": "5d66e01dc6a7071408ac1e1c",
|
|
|
- "nick": null
|
|
|
- }
|
|
|
-}]
|
|
|
-
|
|
|
-const defImg = {images:[{url:"images/b3def30bab7249af56ef341536327fd3"},{url:"images/d766a6cb2d3c232f3e9241abf0751cbc"},{url:"images/1f8973225107076a4e2f2e4ac5e35e74"}]}
|
|
|
+
|
|
|
+
|
|
|
+let defaultPost = {
|
|
|
+ "_id":"620bb700ad55d22f3e2fb320",
|
|
|
+ "title": null,
|
|
|
+ "text": "aaa",
|
|
|
+ "images": [
|
|
|
+ {"_id":"620bb640ad55d22f3e2fb31d","url":"images/52f69596333a282940913b2f2e157fb7"},
|
|
|
+ {"_id":"620bb66ead55d22f3e2fb31e","url":"images/b10fc2417bfe942a6e56d16d073af186"},
|
|
|
+ {"_id":"620bb6a5ad55d22f3e2fb31f","url":"images/9111d163d7fbc66ad9ce1c170bd7002e"}
|
|
|
+ ]
|
|
|
+ }
|
|
|
+
|
|
|
+
|
|
|
|
|
|
const Photo = ({photo}) => {
|
|
|
return (
|
|
@@ -65,16 +33,20 @@ const Photo = ({photo}) => {
|
|
|
)
|
|
|
}
|
|
|
|
|
|
+const SortableItem = sortableElement(({image}) =>
|
|
|
+<li>
|
|
|
+ {image._id}
|
|
|
+ <img src={`${backendURL}/${image.url}`}/>
|
|
|
+ </li>);
|
|
|
|
|
|
+const SortableContainer = sortableContainer(({children}) => {
|
|
|
+ return <div>{children}</div>;
|
|
|
+});
|
|
|
|
|
|
|
|
|
|
|
|
- const defitems = {items:['Item 1', 'Item 2', 'Item 3', 'Item 4', 'Item 5', 'Item 6']};
|
|
|
-
|
|
|
-
|
|
|
-
|
|
|
- const EntityEditor = ({entity={images: []}, onSave, onFileDrop, fileStatus}) => {
|
|
|
- const [state,setState] = useState(entity)
|
|
|
+ const PostEditor = ({post=defaultPost, onSave, onFileDrop, fileStatus}) => {
|
|
|
+ const [state,setState] = useState(post)
|
|
|
//по файлу в дропзоне:
|
|
|
//дергать onFileDrop
|
|
|
//fileStatus - информация о заливке файла из redux
|
|
@@ -86,40 +58,30 @@ const Photo = ({photo}) => {
|
|
|
//где-то рядом остальные поля из state типа title name text
|
|
|
//но это вы уже знаете
|
|
|
|
|
|
- const SortableItem = sortableElement(({value}) => <div>
|
|
|
- {/* <img src={`${backendURL}+"/"${value.images[0]}`} alt="photo"/> */}
|
|
|
- <h2>{value._id}</h2>
|
|
|
- <p>{value.text}</p>
|
|
|
-</div>);
|
|
|
-
|
|
|
- const SortableContainer = sortableContainer(({children}) => {
|
|
|
- return <div>{children}</div>;
|
|
|
-});
|
|
|
+
|
|
|
|
|
|
|
|
|
const onSortEnd = ({oldIndex, newIndex}) => {
|
|
|
- console.log(state, oldIndex, newIndex, arrayMoveImmutable(state.images, oldIndex, newIndex));
|
|
|
- setState((state) => {
|
|
|
- return {images: arrayMoveImmutable(state.images, oldIndex, newIndex)}
|
|
|
- })
|
|
|
- /* setState((state) => ({
|
|
|
- items: arrayMoveImmutable(state.items, oldIndex, newIndex),
|
|
|
- })); */
|
|
|
+ setState({...state,images: arrayMoveImmutable(state.images,oldIndex,newIndex)})
|
|
|
+
|
|
|
}
|
|
|
- // console.log(state)
|
|
|
+ console.log(state)
|
|
|
|
|
|
return(
|
|
|
- <SortableContainer onSortEnd={onSortEnd}>
|
|
|
- {state.images.map((value, index) => (
|
|
|
- <SortableItem key={`item-${value}`} index={index} value={value} />
|
|
|
+ <>
|
|
|
+ <SortableContainer onSortEnd={onSortEnd}>
|
|
|
+ {state.images.map((image, index) => (
|
|
|
+ <SortableItem key={`item-${image._id}`} index={index} image={image} />
|
|
|
))}
|
|
|
</SortableContainer>
|
|
|
+ <button onClick={() => onSave(state)}>Save</button>
|
|
|
+ </>
|
|
|
)
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
-
|
|
|
+const CPostEditor = connect(null,{onSave: actionPostUpsert})(PostEditor)
|
|
|
|
|
|
|
|
|
const UpsertPost = () => {
|
|
@@ -137,7 +99,7 @@ const Photo = ({photo}) => {
|
|
|
<SortableItem key={`item-${value}`} index={index} value={value} />
|
|
|
))}
|
|
|
</SortableContainer> */
|
|
|
- <EntityEditor entity={defaultPost}/>
|
|
|
+ <CPostEditor/>
|
|
|
)
|
|
|
}
|
|
|
|