-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathUpdatePost.jsx
More file actions
86 lines (73 loc) · 2.4 KB
/
UpdatePost.jsx
File metadata and controls
86 lines (73 loc) · 2.4 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
import React ,{useState,useEffect} from 'react';
import { PageHeader, Input, Button} from 'antd';
import { navigate} from "@reach/router"
import db from '../firebase'
const { TextArea } = Input;
const UpdatePost =(props)=>
{
const[title, setTitle]=useState('')
const[content,setContent]=useState('')
useEffect(()=>{
let postRef=db
.collection('POSTBOX').doc()
postRef
.get()
.then(doc => {
let {title,content}=doc.data()
setTitle(title)
setContent(content)
})
},[]
)
const onMainTitleChange =(event)=>
{
setTitle(event.target.value)
}
const onContentChange =(event)=>
{
setContent(event.target.value)
}
const isEnabled = title.length > 0 && content.length > 0;
const onCreatePost =()=>
{
let postRef=db.collection('POSTBOX')
let payload={title,content}
postRef.add(payload)
.then(function(doc){
console.log("Document saved with id: ", doc.id)
})
setTitle(' ')
setContent('')
navigate(`/posts`)
}
return (
<div className="createPost_container">
<div className="pageHeader_container ">
<PageHeader style ={{ border: '3px solid green' , textAlign: 'center', paddingLeft: '10px'}}
className="site-page-header"
title="Update Post"
/>,
</div>
<div className="post_input_container">
<div className="post_title_container">
Post Main Title
</div>
<div className="input_Title_container">
<Input placeholder="Post Title" value={title} onChange={onMainTitleChange}/>
</div>
</div>
<div className="content_container_creater">
<div >
<div className="post_title_container">
Post Content
</div>
</div>
<TextArea rows={12} cols={4} style={{marginTop: '20px'}} value={content} onChange={onContentChange} />
</div>
<div className="button_container">
<Button type="primary" size ="large" onClick={onCreatePost} disabled={!isEnabled}>UpdatePost</Button>
</div>
</div>
)
}
export default UpdatePost;