-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
b353c7c
commit 4e6c8fa
Showing
9 changed files
with
160 additions
and
40 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,38 @@ | ||
.editor-page { | ||
margin: 25px 50px; | ||
} | ||
|
||
.editor-main { | ||
height: 500px; | ||
width: 90vw; | ||
display: flex; | ||
flex-direction: column; | ||
justify-content: flex-start; | ||
} | ||
|
||
.editor-content { | ||
margin: 50px auto; | ||
} | ||
|
||
input { | ||
border: none; | ||
width: 100%; | ||
min-height: 60px; | ||
font-size: 25px; | ||
font-family: 'Segoe UI', Tahoma, Geneva, Verdana, sans-serif; | ||
border-bottom: 1px solid lightgrey; | ||
} | ||
|
||
textarea { | ||
border: none; | ||
width: 100%; | ||
min-height: 200px; | ||
} | ||
|
||
.greybackground { | ||
min-height: 100px; | ||
background: rgb(247, 247, 247); | ||
display: flex; | ||
flex-direction: column; | ||
justify-content: center; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,101 @@ | ||
import React, { Component, Fragment } from "react"; | ||
import { graphql } from 'react-apollo'; | ||
import gql from 'graphql-tag'; | ||
|
||
import { Col, Row, Button } from "antd"; | ||
|
||
import "./Editor.css"; | ||
|
||
class Editor extends Component { | ||
constructor(props) { | ||
super(props); | ||
this.state = { | ||
title: "Enter your title", | ||
content: "Enter your post here!" | ||
}; | ||
} | ||
|
||
onChange = e => { | ||
switch (e.target.name) { | ||
case "title": | ||
this.setState({ title: e.target.value }); | ||
break; | ||
case "content": | ||
this.setState({ content: e.target.value }); | ||
break; | ||
default: | ||
break; | ||
} | ||
}; | ||
|
||
publishPost = async (e) => { | ||
e.preventDefault(); | ||
const { title, content } = this.state; | ||
const { userid } = this.props; | ||
|
||
const resp = await this.props.mutate({ | ||
variables: { | ||
title, | ||
userid, | ||
content | ||
} | ||
}) | ||
|
||
if (resp.data.addPost._id) { | ||
this.props.history.push('/account'); | ||
} | ||
} | ||
|
||
render() { | ||
const { title, content } = this.state; | ||
return ( | ||
<div className="editor-page"> | ||
<h1> Add new post </h1> | ||
<form className="editor-main" onSubmit={this.publishPost}> | ||
<Row gutter={24} className="editor-title"> | ||
<Col span={12}> | ||
<input | ||
type="text" | ||
name="title" | ||
placeholder="Enter your title" | ||
onChange={this.onChange} | ||
/> | ||
</Col> | ||
<Col span={12}> | ||
<h1>{title}</h1> | ||
</Col> | ||
</Row> | ||
<Row gutter={24} className="editor-content"> | ||
<Col span={12}> | ||
<textarea | ||
name="content" | ||
cols="30" | ||
rows="10" | ||
onChange={this.onChange} | ||
placeholder="Enter your post here!" | ||
/> | ||
</Col> | ||
<Col span={12}>{content}</Col> | ||
</Row> | ||
<Row gutter={24} className="greybackground"> | ||
<Col span={2} offset={22}> | ||
<Button type="primary" htmlType="submit" className="login-form-button"> | ||
Publish | ||
</Button> | ||
</Col> | ||
</Row> | ||
</form> | ||
</div> | ||
); | ||
} | ||
} | ||
|
||
const submitPost = gql` | ||
mutation addPost($title: String!, $userid: String!, $content: String!){ | ||
addPost(title: $title, userid: $userid, content: $content) { | ||
_id | ||
} | ||
} | ||
`; | ||
|
||
export default graphql(submitPost)(Editor); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
import Editor from './Editor.jsx'; | ||
|
||
export default Editor; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters