|
@@ -1,166 +1,69 @@
|
|
-import { EditOutlined } from "@ant-design/icons"
|
|
|
|
-import { Button, Divider, Input } from "antd"
|
|
|
|
-import TextArea from "antd/lib/input/TextArea"
|
|
|
|
-import Paragraph from "antd/lib/typography/Paragraph"
|
|
|
|
-import Text from "antd/lib/typography/Text"
|
|
|
|
|
|
+import { Button, Divider, message } from "antd"
|
|
import Title from "antd/lib/typography/Title"
|
|
import Title from "antd/lib/typography/Title"
|
|
import { useEffect, useState } from "react"
|
|
import { useEffect, useState } from "react"
|
|
import { connect } from "react-redux"
|
|
import { connect } from "react-redux"
|
|
-import { actionSentPost, actionsentPostAC } from "../actions"
|
|
|
|
-import { EditPhotos } from "../components/uploadPhoto"
|
|
|
|
|
|
+import { actionFindPostOne, actionFullSentPost, actionRemovePostsFeedAC } from "../actions"
|
|
|
|
+import { EditPhotos } from "../components/uploadPhoto/EditPhotos"
|
|
|
|
+import { EditDescriptionPost } from "../components/uploadPhoto/EditDescriptionPost"
|
|
|
|
+import { EditTitlePost } from "../components/uploadPhoto/EditTitlePost"
|
|
|
|
+import { Container } from "./Content"
|
|
|
|
+import { history } from '../App'
|
|
|
|
|
|
|
|
|
|
const ContainEditorPost = ({ children }) =>
|
|
const ContainEditorPost = ({ children }) =>
|
|
- <div className='ContainErditorPost'>{children}</div>
|
|
|
|
-
|
|
|
|
-
|
|
|
|
-const EditTitlePost = ({ titleSend, setTitleSend }) => {
|
|
|
|
- const [title, setTitle] = useState(titleSend || 'Enter title')
|
|
|
|
- const [error, setError] = useState(false)
|
|
|
|
- const [editMode, setEditMode] = useState(false)
|
|
|
|
-
|
|
|
|
- const addTaskHandler = () => {
|
|
|
|
- if (title.trim() !== '') {
|
|
|
|
- setTitleSend(title.trim())
|
|
|
|
- setEditMode(false)
|
|
|
|
- } else {
|
|
|
|
- setError(true)
|
|
|
|
- setTitleSend('')
|
|
|
|
- }
|
|
|
|
- }
|
|
|
|
- const titleInputHandler = () => {
|
|
|
|
- setEditMode(true)
|
|
|
|
- }
|
|
|
|
-
|
|
|
|
- const titleInputHandlerClose = () => {
|
|
|
|
- addTaskHandler()
|
|
|
|
- }
|
|
|
|
-
|
|
|
|
- const onChangeTask = (e) => {
|
|
|
|
- setTitle(e.currentTarget.value)
|
|
|
|
- setError(false)
|
|
|
|
- }
|
|
|
|
-
|
|
|
|
- const onKeyPressAddTask = (e) => {
|
|
|
|
- if (e.charCode === 13) {
|
|
|
|
- addTaskHandler()
|
|
|
|
- }
|
|
|
|
- }
|
|
|
|
- return (
|
|
|
|
- <>
|
|
|
|
- <Divider orientation="left" orientationMargin="0">
|
|
|
|
- <Title level={3}>Title
|
|
|
|
- <Button type="link" onClick={titleInputHandler}><EditOutlined /></Button></Title>
|
|
|
|
- </Divider>
|
|
|
|
- {error && <Text type="danger">Field must not be empty</Text>}
|
|
|
|
- {editMode
|
|
|
|
- ? <Input
|
|
|
|
- value={title}
|
|
|
|
- placeholder="title"
|
|
|
|
- onChange={onChangeTask}
|
|
|
|
- // className={s.input + ' ' + (error && s.error)}
|
|
|
|
- autoFocus onBlur={titleInputHandlerClose}
|
|
|
|
- onKeyPress={onKeyPressAddTask}
|
|
|
|
- />
|
|
|
|
- : <Title level={5} onDoubleClick={titleInputHandler}>
|
|
|
|
- {title}
|
|
|
|
- </Title>
|
|
|
|
- }
|
|
|
|
- </>)
|
|
|
|
-}
|
|
|
|
-
|
|
|
|
-
|
|
|
|
-const EditDescriptionPost = ({ description, setDescription }) => {
|
|
|
|
- const [text, setText] = useState(description || 'Enter descriptin');
|
|
|
|
- const [error, setError] = useState(false)
|
|
|
|
- const [editMode, setEditMode] = useState(false)
|
|
|
|
-
|
|
|
|
-
|
|
|
|
- const addTaskHandler = () => {
|
|
|
|
- if (text.trim() !== '') {
|
|
|
|
- setDescription(text)
|
|
|
|
- setEditMode(false)
|
|
|
|
- } else {
|
|
|
|
- setError(true)
|
|
|
|
- setDescription('')
|
|
|
|
- }
|
|
|
|
- }
|
|
|
|
- const textInputHandler = () => {
|
|
|
|
- setEditMode(true)
|
|
|
|
- }
|
|
|
|
-
|
|
|
|
- const textInputHandlerClose = () => {
|
|
|
|
- addTaskHandler()
|
|
|
|
- }
|
|
|
|
-
|
|
|
|
- const onChangeTask = (e) => {
|
|
|
|
- setText(e.currentTarget.value)
|
|
|
|
- setError(false)
|
|
|
|
- }
|
|
|
|
-
|
|
|
|
- const onKeyPressAddTask = (e) => {
|
|
|
|
- if (e.shiftKey && e.charCode === 13) {
|
|
|
|
- setText(text += `'\n'`)
|
|
|
|
- } else if (e.charCode === 13) {
|
|
|
|
- addTaskHandler()
|
|
|
|
|
|
+ <div className='ContainEditPost ContainerInner'>{children}</div>
|
|
|
|
+
|
|
|
|
+const EntityEditorPost = ({ match: { params: { _id } }, myID, entity, status, onSave, findPostOne, clearState }) => {
|
|
|
|
+
|
|
|
|
+ const [photos, setPhotos] = useState(entity?.images || []);
|
|
|
|
+ const [titleSend, setTitleSend] = useState(entity?.title || '')
|
|
|
|
+ const [description, setDescription] = useState(entity?.text || '');
|
|
|
|
+
|
|
|
|
+ useEffect(() => {
|
|
|
|
+ if (_id !== 'new')
|
|
|
|
+ findPostOne(_id)
|
|
|
|
+ return () => {
|
|
|
|
+ clearState()
|
|
|
|
+ };
|
|
|
|
+ }, []);
|
|
|
|
+
|
|
|
|
+ useEffect(() => {
|
|
|
|
+ setPhotos(entity?.images || [])
|
|
|
|
+ setTitleSend(entity?.title || '')
|
|
|
|
+ setDescription(entity?.text || '')
|
|
|
|
+ }, [entity]);
|
|
|
|
+
|
|
|
|
+ useEffect(() => {
|
|
|
|
+ if (status === "RESOLVED") {
|
|
|
|
+ message.success(`post published, can create a new one`)
|
|
|
|
+ history.push(`/profile/${myID}`)
|
|
}
|
|
}
|
|
- }
|
|
|
|
- return (
|
|
|
|
- <>
|
|
|
|
- <Divider orientation="left" orientationMargin="0">
|
|
|
|
- <Title level={3}>Description
|
|
|
|
- <Button type="link" onClick={textInputHandler}><EditOutlined /></Button></Title>
|
|
|
|
- </Divider>
|
|
|
|
- {error && <Text type="danger">Field must not be empty</Text>}
|
|
|
|
- {editMode
|
|
|
|
- ? <TextArea
|
|
|
|
- placeholder="Description"
|
|
|
|
- autoSize={{ minRows: 3, maxRows: 5 }}
|
|
|
|
- value={text}
|
|
|
|
- onChange={onChangeTask}
|
|
|
|
- autoFocus onBlur={textInputHandlerClose}
|
|
|
|
- onKeyPress={onKeyPressAddTask}
|
|
|
|
- />
|
|
|
|
- : <Paragraph className="description" onDoubleClick={textInputHandler}>
|
|
|
|
- {text}
|
|
|
|
- </Paragraph>
|
|
|
|
- }
|
|
|
|
- </>)
|
|
|
|
-}
|
|
|
|
-
|
|
|
|
-const EntityEditorPost = ({ entity = { array: [] }, onSave }) => {
|
|
|
|
-
|
|
|
|
- const [photos, setPhotos] = useState([]);
|
|
|
|
- const [titleSend, setTitleSend] = useState('')
|
|
|
|
- const [description, setDescription] = useState('');
|
|
|
|
- // photos.length && titleSend && description ? : true
|
|
|
|
- const disabledBtn = false
|
|
|
|
- const sentPost = () => {
|
|
|
|
- const [newphotos ]= photos.map(ph => {
|
|
|
|
- return { _id: ph._id }
|
|
|
|
- })
|
|
|
|
-
|
|
|
|
-
|
|
|
|
- onSave(newphotos, titleSend, description);
|
|
|
|
- }
|
|
|
|
- // const sentPost = () => {
|
|
|
|
- // const newphotos = photos.map(ph => {
|
|
|
|
- // return { _id: ph._id }
|
|
|
|
- // })
|
|
|
|
|
|
+ }, [status])
|
|
|
|
|
|
- // console.log(result)
|
|
|
|
|
|
+ const disabledBtn = photos.length && titleSend && description ? false : true
|
|
|
|
+ const sentPost = () => onSave(photos, titleSend, description)
|
|
|
|
|
|
- // }
|
|
|
|
return (
|
|
return (
|
|
- <ContainEditorPost>
|
|
|
|
- <h1 className="title" level={1}>Create / edit Post</h1>
|
|
|
|
- <Divider orientation="left" orientationMargin="0"><Title level={3}>Photos</Title></Divider>
|
|
|
|
- <EditPhotos photos={photos} setPhotos={setPhotos} />
|
|
|
|
- <EditTitlePost titleSend={titleSend} setTitleSend={setTitleSend} />
|
|
|
|
- <EditDescriptionPost description={description} setDescription={setDescription} />
|
|
|
|
- <Divider orientation="right"> <Button disabled={disabledBtn} type="primary" onClick={sentPost}>Send a Post</Button></Divider>
|
|
|
|
- </ContainEditorPost>
|
|
|
|
|
|
+ <Container>
|
|
|
|
+ <ContainEditorPost >
|
|
|
|
+ <h1 className="title" level={1}>Create / edit Post</h1>
|
|
|
|
+ <Divider orientation="left" orientationMargin="0"><Title level={3}>Photos</Title></Divider>
|
|
|
|
+ <EditPhotos photos={photos} setPhotos={setPhotos} />
|
|
|
|
+ <EditTitlePost titleSend={titleSend} setTitleSend={setTitleSend} />
|
|
|
|
+ <EditDescriptionPost description={description} setDescription={setDescription} />
|
|
|
|
+ <Divider orientation="right"> <Button disabled={disabledBtn} type="primary" onClick={sentPost}>Send a Post</Button></Divider>
|
|
|
|
+ </ContainEditorPost>
|
|
|
|
+ </ Container>
|
|
)
|
|
)
|
|
}
|
|
}
|
|
|
|
|
|
-export const CEntityEditorPost = connect(null, { onSave: actionSentPost })(EntityEditorPost)
|
|
|
|
|
|
+export const CEntityEditorPost = connect(state => ({
|
|
|
|
+ myID: state?.auth?.payload?.sub?.id,
|
|
|
|
+ entity: state?.postsFeed?.posts,
|
|
|
|
+ status: state?.promise?.sentPost?.status
|
|
|
|
+}),
|
|
|
|
+ {
|
|
|
|
+ onSave: actionFullSentPost,
|
|
|
|
+ findPostOne: actionFindPostOne,
|
|
|
|
+ clearState: actionRemovePostsFeedAC,
|
|
|
|
+ })(EntityEditorPost)
|