Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fixed the file not clear issue #195

Open
wants to merge 1 commit into
base: PART_1_and_2
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
fix selected file not clearing bug
greedybrute committed May 17, 2024
commit 3acf07cbbf788c5fb8778bf0a7180bbbfe953733
4 changes: 3 additions & 1 deletion client/src/components/Form/Form.js
Original file line number Diff line number Diff line change
@@ -8,6 +8,7 @@ import { createPost, updatePost } from '../../actions/posts';

const Form = ({ currentId, setCurrentId }) => {
const [postData, setPostData] = useState({ creator: '', title: '', message: '', tags: '', selectedFile: '' });
const [fileInputKey,setFileInputKey]=useState(Math.random());
const post = useSelector((state) => (currentId ? state.posts.find((message) => message._id === currentId) : null));
const dispatch = useDispatch();
const classes = useStyles();
@@ -19,6 +20,7 @@ const Form = ({ currentId, setCurrentId }) => {
const clear = () => {
setCurrentId(0);
setPostData({ creator: '', title: '', message: '', tags: '', selectedFile: '' });
setFileInputKey(Math.random());
};

const handleSubmit = async (e) => {
@@ -41,7 +43,7 @@ const Form = ({ currentId, setCurrentId }) => {
<TextField name="title" variant="outlined" label="Title" fullWidth value={postData.title} onChange={(e) => setPostData({ ...postData, title: e.target.value })} />
<TextField name="message" variant="outlined" label="Message" fullWidth multiline rows={4} value={postData.message} onChange={(e) => setPostData({ ...postData, message: e.target.value })} />
<TextField name="tags" variant="outlined" label="Tags (coma separated)" fullWidth value={postData.tags} onChange={(e) => setPostData({ ...postData, tags: e.target.value.split(',') })} />
<div className={classes.fileInput}><FileBase type="file" multiple={false} onDone={({ base64 }) => setPostData({ ...postData, selectedFile: base64 })} /></div>
<div className={classes.fileInput}><FileBase type="file" key={fileInputKey} multiple={false} onDone={({ base64 }) => setPostData({ ...postData, selectedFile: base64 })} /></div>
<Button className={classes.buttonSubmit} variant="contained" color="primary" size="large" type="submit" fullWidth>Submit</Button>
<Button variant="contained" color="secondary" size="small" onClick={clear} fullWidth>Clear</Button>
</form>