File tree Expand file tree Collapse file tree 5 files changed +137
-4
lines changed Expand file tree Collapse file tree 5 files changed +137
-4
lines changed Original file line number Diff line number Diff line change @@ -68,4 +68,9 @@ export const PostComment = styled.div`
6868export const LikeNumber = styled . div `
6969 display: flex;
7070 justify-content: center;
71- ` ;
71+ ` ;
72+
73+
74+ export const Comments = styled . div `
75+ color: #757575;
76+ ` ;
Original file line number Diff line number Diff line change 1+ import React , { useState } from 'react' ;
2+ import Axios from 'axios' ;
3+
4+ import {
5+ Container ,
6+ Form ,
7+ Button ,
8+ InputTitle ,
9+ InputText ,
10+
11+ } from './CreatePostStyle'
12+
13+
14+
15+ const baseUrl = 'https://us-central1-labenu-apis.cloudfunctions.net/labEddit/posts'
16+
17+ export default props => {
18+ const { token, getAllPost} = props ;
19+ const [ title , setTitle ] = useState ( '' ) ;
20+ const [ text , setText ] = useState ( '' ) ;
21+
22+ const onChange = event => {
23+ const { name, value} = event . target ;
24+ switch ( name ) {
25+ case 'titulo' :
26+ setTitle ( value ) ;
27+ break ;
28+ case 'text' :
29+ setText ( value ) ;
30+ break ;
31+ }
32+ }
33+
34+ const criarPost = event => {
35+ event . preventDefault ( ) ;
36+ const auth = {
37+ headers :{
38+ Authorization : token
39+ }
40+ }
41+
42+ const body = { title, text, }
43+
44+ Axios . post ( baseUrl , body , auth )
45+ . then ( response => {
46+ setTitle ( '' ) ;
47+ setText ( '' ) ;
48+ getAllPost ( token ) ;
49+ } )
50+ . catch ( err => console . log ( err . menssage ) )
51+ }
52+
53+
54+ return (
55+ < Container >
56+ < Form onSubmit = { criarPost } >
57+ < InputTitle
58+ placeholder = { 'Titulo do Post' }
59+ value = { title }
60+ onChange = { onChange }
61+ name = { 'titulo' }
62+ required = { true }
63+ />
64+ < InputText
65+ placeholder = { 'Post' }
66+ onChange = { onChange }
67+ value = { text }
68+ name = { 'text' }
69+ cols = "40"
70+ rows = "5"
71+ required = { true }
72+ />
73+ < Button > Criar Post</ Button >
74+ </ Form >
75+ </ Container >
76+ ) ;
77+ }
Original file line number Diff line number Diff line change 1+ import styled from 'styled-components' ;
2+
3+
4+ export const Container = styled . div `
5+ height: fit-content;
6+ width: fit-content;
7+ display: flex;
8+ flex-direction: column;
9+ ` ;
10+
11+ export const Form = styled . form `
12+ height: fit-content;
13+ display: flex;
14+ width: fit-content;
15+ flex-direction: column;
16+ width: fit-content;
17+ ` ;
18+
19+ export const Button = styled . button `
20+ align-self: center;
21+ margin: 1vh;
22+ `
23+
24+ export const InputTitle = styled . input `
25+ font-weight: 700;
26+ height: 20%;
27+ margin: 0.5vh;
28+ ` ;
29+
30+
31+ export const InputText = styled . textarea `
32+ resize: none;
33+ ` ;
Original file line number Diff line number Diff line change 11import React from 'react' ;
2+ import { useHistory } from 'react-router-dom' ;
23
34import {
45 Card ,
@@ -10,6 +11,7 @@ import {
1011 PostTitle ,
1112 PostText ,
1213 PostComment ,
14+ Comments ,
1315 } from './CardPostStyles' ;
1416
1517
@@ -41,8 +43,8 @@ const useStyles = makeStyles({
4143
4244export default props => {
4345 const { post, vote} = props || { }
46+ const history = useHistory ( ) ;
4447 const classes = useStyles ( props ) ;
45-
4648
4749 return < Card >
4850 < CardContent >
@@ -66,9 +68,10 @@ export default props =>{
6668 { post . text }
6769 </ PostText >
6870 < PostComment >
69- < IconButton >
70- < CommentIcon />
71+ < IconButton onClick = { ( ) => history . push ( `/PostDetails/ ${ post . id } ` ) } >
72+ < CommentIcon />
7173 </ IconButton >
74+ < Comments > { post . commentsCount } </ Comments >
7275 </ PostComment >
7376 </ PostContent >
7477 </ CardContent >
Original file line number Diff line number Diff line change @@ -9,6 +9,7 @@ import styled from 'styled-components';
99
1010import Post from '../components/Post' ;
1111import { ListItemText } from '@material-ui/core' ;
12+ import CreatePost from '../components/CreatePost' ;
1213
1314const Container = styled . div `
1415 height: fit-content;
@@ -20,6 +21,11 @@ const Container = styled.div`
2021 background-color: #DAE0E6;
2122` ;
2223
24+ const LogOut = styled . button `
25+ align-self: flex-end;
26+
27+ `
28+
2329
2430
2531
@@ -29,6 +35,13 @@ export default props =>{
2935 const [ post , setPost ] = useState ( [ ] ) ;
3036 const [ token , setToken ] = useState ( '' ) ;
3137 const [ like , setLike ] = useState ( '' ) ;
38+ const history = useHistory ( ) ;
39+
40+
41+ const doLogOut = ( ) => {
42+ localStorage . removeItem ( 'token' ) ;
43+ history . push ( '/' )
44+ }
3245
3346 const getAllPost = ( token ) => {
3447 const auth = {
@@ -79,6 +92,8 @@ export default props =>{
7992 } , [ token , like ] )
8093
8194 return < Container >
95+ < LogOut onClick = { doLogOut } > LogOut</ LogOut >
96+ < CreatePost token = { token } getAllPost = { getAllPost } />
8297 { post && post . map ( post => {
8398 return < Post
8499 key = { post . id }
You can’t perform that action at this time.
0 commit comments