Skip to content

Implements markdown and priview functionality #513

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

Merged
merged 3 commits into from
Jul 15, 2020
Merged
Show file tree
Hide file tree
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
6 changes: 3 additions & 3 deletions src/css/components/_modals.scss
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
border-radius: 20px;
.modal-content {
border-radius: 10px;
max-height: 70vh;

// width: 66%;
border: 0px;
// overflow-y: scroll;
Expand Down Expand Up @@ -37,7 +37,7 @@
width: 6vw;
height: 5vh;
background: rgb(250, 251, 252);
// border-radius: 100px;
border-radius: 100px;
color: #1A73E8;
padding: 0.3em;
margin-left: 1em;
Expand Down Expand Up @@ -199,7 +199,7 @@

color: #1a73e8;
}
.modal__unFollowText {
.modal__unFollowText {
font-family: $font-family-Inter;
font-style: normal;
font-weight: $font-weight-normal;
Expand Down
3 changes: 2 additions & 1 deletion src/user/dashboard/news-feed/news-feed.js
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@ import { upVotePost } from '../../../actions/postAction'
import profileImg from '../../../svgs/evt-creator.svg';
import eventImg from "../../../svgs/event-img-1.svg";
import eventImg2 from "../../../svgs/event-img-2.svg";
import parse from "html-react-parser";
import { withRouter } from 'react-router-dom'
import { rsvpYes } from '../../../actions/eventAction'

Expand Down Expand Up @@ -182,7 +183,7 @@ function NewsFeed(props) {
<small>{post?.createdAt}</small>
</ListItemText>
</ListItem>
<div className="post-details2">{post?.content}</div>
<div className="post-details2">{parse(post?.content)}</div>
<ListItem>
<IconButton
className={classes.vote}
Expand Down
176 changes: 138 additions & 38 deletions src/user/dashboard/news-feed/popups/AddPostModal.js
Original file line number Diff line number Diff line change
@@ -1,66 +1,166 @@
import React, { useState } from "react";
import { Button, Modal, Form, Col } from "react-bootstrap";
import { Button, Modal, Form, Col, Tabs, Tab } from "react-bootstrap";
import PropTypes from "prop-types";
import { connect } from 'react-redux';
import { createPost } from '../../../../actions/dashboardAction'
import { connect } from "react-redux";
import { createPost } from "../../../../actions/dashboardAction";
import { Editor } from "@tinymce/tinymce-react";
import showdown from "showdown";
import { CREATE_PROPOSAL } from "../../../../actions/types";

const AddPostModal = (props) => {
const [content, setContent] = useState("");
const [editorText, setText] = useState("");

const onChange = (event) => {
setContent(event.target.value);
};

let converter = new showdown.Converter();

const createPostClick = async (content) => {
console.log("Creating the post ", content);
const obj = {
content: content
}
props.createPost(obj)
props.onHide()
content: content,
};
props.createPost(obj);
props.onHide();
};

const handleEditorChange = (content, editor) => {
setContent(content);
};

const handleEditorClose = () => {
setContent("");
props.onHide();
};

return (
<Modal
show={props.show}
onHide={props.onHide}
onHide={handleEditorClose}
animation={true}
className="modal"
centered
size="lg"
>
<Modal.Header
closeButton
className="modal__header"
style={props.borderStyle}
>
<Modal.Header closeButton className="modal__header">
<Modal.Title className="modal__title" style={props.borderStyle}>
<div className="modal__main-title">New Post</div>
<div className="modal__mini-title">POST DETAILS</div>
</Modal.Title>
</Modal.Header>
<Modal.Body className="modal__body" style={props.borderStyle}>
<Form className="modal__form" style={props.borderStyle}>
<Form.Row className="modal__row">
<Form.Group
as={Col}
controlId="formGridEmail"
className="modal__group"
>
<Form.Label className="modal__label">Post Description</Form.Label>
<Form.Control
as="textarea"
className="modal__post"
placeholder="What do you want to tell people about?"
rows={5}
defaultValue={content}
onChange={onChange}
/>
</Form.Group>
</Form.Row>
</Form>
</Modal.Body>
<Tabs defaultActiveKey="write" style={{ marginTop: "10px" }}>
<Tab eventKey="write" title="Write">
<Modal.Body className="modal__body" style={props.borderStyle}>
<Form className="modal__form" style={props.borderStyle}>
<Form.Row className="modal__row">
<Form.Group
as={Col}
controlId="formGridEmail"
className="modal__group"
>
<Editor
apiKey="lvp9xf6bvvm3nkaupm67ffzf50ve8femuaztgg7rkgkmsws3"
initialValue="Write a post..."
init={{
height: 300,
width: "100%",
menubar: false,
plugins: [
"advlist autolink lists link image charmap print preview anchor",
"searchreplace visualblocks code fullscreen",
"insertdatetime media table paste code help wordcount",
"textpattern",
],
textpattern_patterns: [
{ start: "#", format: "h1" },
{ start: "##", format: "h2" },
{ start: "###", format: "h3" },
{ start: "####", format: "h4" },
{ start: "#####", format: "h5" },
{ start: "######", format: "h6" },
{ start: "* ", cmd: "InsertUnorderedList" },
{ start: "- ", cmd: "InsertUnorderedList" },
Comment on lines +76 to +84
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

i am so happy to see this 👍

{
start: "1. ",
cmd: "InsertOrderedList",
value: { "list-style-type": "decimal" },
},
{
start: "1) ",
cmd: "InsertOrderedList",
value: { "list-style-type": "decimal" },
},
{
start: "a. ",
cmd: "InsertOrderedList",
value: { "list-style-type": "lower-alpha" },
},
{
start: "a) ",
cmd: "InsertOrderedList",
value: { "list-style-type": "lower-alpha" },
},
{
start: "i. ",
cmd: "InsertOrderedList",
value: { "list-style-type": "lower-roman" },
},
{
start: "i) ",
cmd: "InsertOrderedList",
value: { "list-style-type": "lower-roman" },
},
],
toolbar:
"undo redo | formatselect | bold italic backcolor | \
alignleft aligncenter alignright alignjustify | \
bullist numlist outdent indent | removeformat | help",
}}
onEditorChange={handleEditorChange}
/>
</Form.Group>
</Form.Row>
</Form>
</Modal.Body>
</Tab>
<Tab eventKey="preview" title="Preview">
<Modal.Body className="modal__body" style={props.borderStyle}>
<Form className="modal__form" style={props.borderStyle}>
<Form.Row className="modal__row">
<Form.Group
as={Col}
controlId="formGridEmail"
className="modal__group"
>
<Editor
disabled={true}
value={converter.makeHtml(content)}
apiKey="lvp9xf6bvvm3nkaupm67ffzf50ve8femuaztgg7rkgkmsws3"
init={{
height: 300,
width: "100%",
menubar: false,
plugins: [
"advlist autolink lists link image charmap print preview anchor",
"searchreplace visualblocks code fullscreen",
"insertdatetime media table paste code help wordcount",
],
toolbar: false,
}}
/>
</Form.Group>
</Form.Row>
</Form>
</Modal.Body>
</Tab>
</Tabs>
<div className="modal__buttons">
<Button onClick = {createPostClick.bind(this, content)} className = "modal__save" >
<Button
onClick={createPostClick.bind(this, content)}
className="modal__save"
>
<span className="modal__buttontext">Post</span>
</Button>
<Button onClick={props.onHide} className="modal__cancel">
Expand All @@ -77,11 +177,11 @@ AddPostModal.propTypes = {
style: PropTypes.object,
};

// map state to props
// map state to props
const mapStateToProps = (state) => ({
auth: state.auth,
error: state.error,
dashboard: state.dashboard
})
dashboard: state.dashboard,
});

export default connect(mapStateToProps, { createPost })(AddPostModal);