diff --git a/frontend/package.json b/frontend/package.json index e513f1b..c4ad1a6 100644 --- a/frontend/package.json +++ b/frontend/package.json @@ -12,12 +12,14 @@ "@types/jest": "^26.0.15", "@types/node": "^12.0.0", "@types/react": "^17.0.0", + "@types/react-beautiful-dnd": "^13.1.1", "@types/react-dom": "^17.0.0", "@types/react-router-dom": "^5.1.8", "axios": "^0.21.1", "formik": "^2.2.9", "formik-material-ui": "^3.0.1", "react": "^17.0.2", + "react-beautiful-dnd": "^13.1.0", "react-dom": "^17.0.2", "react-router-dom": "^5.2.0", "react-scripts": "4.0.3", diff --git a/frontend/src/components/AccountCard/index.tsx b/frontend/src/components/AccountCard/index.tsx index 44b6144..00f6b3b 100644 --- a/frontend/src/components/AccountCard/index.tsx +++ b/frontend/src/components/AccountCard/index.tsx @@ -18,7 +18,7 @@ const emptyThread = (): Thread => ({ status: ThreadStatus.SCHEDULED, tweets: [ { - id: "", + id: "new", text: "", status: TweetStatus.SCHEDULED, tweet_id: null, diff --git a/frontend/src/components/ThreadFormDialog/index.tsx b/frontend/src/components/ThreadFormDialog/index.tsx index df95ed0..4fc5d58 100644 --- a/frontend/src/components/ThreadFormDialog/index.tsx +++ b/frontend/src/components/ThreadFormDialog/index.tsx @@ -1,4 +1,4 @@ -import {FunctionComponent, useState} from "react"; +import React, {FunctionComponent, useState} from "react"; import { Button, Dialog, @@ -16,6 +16,7 @@ import AddIcon from "@material-ui/icons/Add"; import {TweetStatus} from "../../api/entities/Tweet"; import CustomDate from "../../utils/CustomDate"; import {Alert} from "@material-ui/lab"; +import {DragDropContext, Draggable, Droppable} from "react-beautiful-dnd"; export type ThreadFormProps = { open: boolean @@ -34,9 +35,15 @@ const Index: FunctionComponent = ( onCancel } ) => { + const [_idCounter, _setIdCounter] = useState(0) + const getId = () => { + _setIdCounter(_idCounter + 1) + return _idCounter + } + const [thread, setThread] = useState(initial) - const [error, setError] = useState(null) + const [error, setError] = useState(null) return ( @@ -62,48 +69,83 @@ const Index: FunctionComponent = ( }} /> - { - thread.tweets.map((tweet, index) => ( - <> - - { - thread.tweets[index].text = event.target.value - setThread({ - ...thread - }) - }} - variant="outlined" - fullWidth - /> + { + }}> + + {(provided, snapshot) => ( + + { + thread.tweets.map((tweet, index) => ( + + {(provided, snapshot) => ( + + + 280 + } + id="outlined-multiline-static" + label={"Tweet " + (index + 1)} + multiline + rows={3} + value={tweet.text} + onChange={event => { + thread.tweets[index].text = event.target.value + setThread({ + ...thread + }) + }} + variant="outlined" + fullWidth + /> + + + { + thread.tweets.splice(index, 1) + setThread({ + ...thread + }) + }} + > + + + + + )} + + )) + } + {provided.placeholder} - - { - thread.tweets.splice(index, 1) - setThread({ - ...thread - }) - }} - > - - - - - )) - } + )} + + { thread.tweets.push({ - id: "", + id: "new" + getId(), text: "", status: TweetStatus.SCHEDULED, tweet_id: null, @@ -117,7 +159,7 @@ const Index: FunctionComponent = ( - { error && {error} } + {error && {error}}