11import React , { Component } from "react" ;
22import "./DiscussionContent.scss" ;
3- import { Button , Container , Row , Col , Image , ListGroup } from "react-bootstrap" ;
3+ import { Button , Badge , Image , ListGroup } from "react-bootstrap" ;
44import DiscussionComments from "./DiscussionComments/DiscussionComments" ;
55import eventImg from "../../../../svgs/event-img-1.svg" ;
66import userIcon2 from "../../../../images/userIcon2.jpg" ;
77import RequestChanges from "../DiscussionPopups/RequestChanges" ;
8- import { withRouter } from "react-router-dom" ;
9- import { Remarkable } from "remarkable" ;
10- import parse from "html-react-parser" ;
8+ import { withRouter , Link } from "react-router-dom" ;
119import { Editor } from "@tinymce/tinymce-react" ;
12-
13- const md = new Remarkable ( {
14- html : true , // Enable HTML tags in source
15- xhtmlOut : false , // Use '/' to close single tags (<br />)
16- breaks : false , // Convert '\n' in paragraphs into <br>
17- langPrefix : "language-" , // CSS language prefix for fenced blocks
18-
19- // Enable some language-neutral replacement + quotes beautification
20- typographer : false ,
21-
22- // Double + single quotes replacement pairs, when typographer enabled,
23- // and smartquotes on. Set doubles to '«»' for Russian, '„“' for German.
24- quotes : "“”‘’" ,
25-
26- // Highlighter function. Should return escaped HTML,
27- // or '' if the source string is not changed
28- highlight : function ( /*str, lang*/ ) {
29- return "" ;
30- } ,
31- } ) ;
10+ import Carousel , { Modal , ModalGateway } from "react-images" ;
3211
3312class DiscussionContent extends Component {
3413 constructor ( props ) {
@@ -43,6 +22,11 @@ class DiscussionContent extends Component {
4322 markdownString : "" ,
4423 proposalDescription : "" ,
4524 commentList : [ ] ,
25+ author : "" ,
26+ images : [ { source : "../../../../images/userIcon2.jpg" } ] ,
27+ imageModalOpen : false ,
28+ proposalState : "" ,
29+ variant : "danger" ,
4630 } ;
4731 }
4832
@@ -77,13 +61,32 @@ class DiscussionContent extends Component {
7761 return res . json ( ) ;
7862 } )
7963 . then ( ( resData ) => {
80- console . log ( resData ) ;
64+ const images = [ ] ;
65+ resData . proposal . attachments . forEach ( ( item , index ) => {
66+ images . push ( { source : item . fileLink } ) ;
67+ } ) ;
68+
69+ let variant ;
70+
71+ switch ( resData . proposal . proposalStatus ) {
72+ case "DRAFT" :
73+ variant = "danger" ;
74+ break ;
75+ case "SUBMITTED" :
76+ variant = "secondary" ;
77+ break ;
78+ }
79+
8180 this . setState (
8281 {
8382 proposalTitle : resData . proposal . title ,
8483 markdownString : resData . proposal . content ,
8584 proposalDescription : resData . proposal . proposalDescription ,
8685 commentList : resData . proposal . comments ,
86+ author : resData . proposal . creator ,
87+ proposalState : resData . proposal . proposalStatus ,
88+ variant : variant ,
89+ images : images ,
8790 } ,
8891 ( ) => {
8992 this . processComments ( ) ;
@@ -120,7 +123,12 @@ class DiscussionContent extends Component {
120123 } ) ;
121124 } ;
122125
126+ toggleModal = ( ) => {
127+ this . setState ( ( state ) => ( { imageModalOpen : ! state . imageModalOpen } ) ) ;
128+ } ;
129+
123130 handleTextSelction = ( ) => {
131+ console . log ( "text selection called" ) ;
124132 if ( window . getSelection ( ) . toString ( ) . length > 0 ) {
125133 this . setState (
126134 {
@@ -166,28 +174,44 @@ class DiscussionContent extends Component {
166174 } ;
167175
168176 render ( ) {
177+ const { imageModalOpen, images } = this . state ;
169178 return (
170179 < div className = "discussion-content" >
171180 < div className = "discussion-toppanel" >
172181 < div className = "discussion-title" >
173- < span className = "title-text" > { this . state . proposalTitle } </ span >
182+ < span className = "title-text" >
183+ { this . state . proposalTitle } { " " }
184+ < h5 >
185+ < Badge variant = { this . state . variant } >
186+ { this . state . proposalState }
187+ </ Badge >
188+ </ h5 >
189+ </ span >
174190 </ div >
191+ < div > </ div >
175192 < div className = "discussion-desc" > </ div >
176193 < div className = "discussion-buttons" >
177- < Button variant = "primary" className = "option-btn" size = "sm" active >
178- < span className = "option-text" > Edit</ span >
179- </ Button >
194+ < Link
195+ to = { {
196+ pathname : "/proposaleditor" ,
197+ state : {
198+ proposalId : this . state . proposalId ,
199+ } ,
200+ } }
201+ >
202+ < Button variant = "primary" className = "option-btn" size = "sm" active >
203+ < span className = "option-text" > Edit</ span >
204+ </ Button >
205+ </ Link >
180206 </ div >
181207 </ div >
182208 < div className = "discussion-bottompanel" >
183209 < div className = "proposal-preview" >
184210 < div className = "proposal-text" onMouseUp = { this . handleTextSelction } >
185- { /* <p>{parse(md.render(this.state.markdownString))}</p> */ }
186211 < Editor
187212 value = { this . state . markdownString }
188213 disabled = { true }
189214 apiKey = "lvp9xf6bvvm3nkaupm67ffzf50ve8femuaztgg7rkgkmsws3"
190- initialValue = "<p>This is the initial content of the editor</p>"
191215 init = { {
192216 height : "100%" ,
193217 width : "100%" ,
@@ -204,10 +228,48 @@ class DiscussionContent extends Component {
204228 </ div >
205229 < div className = "attached-images" >
206230 < div className = "images-title" > Attached Images</ div >
207- < Row >
208- < Image src = { eventImg } rounded className = "image-item" />
209- < Image src = { eventImg } rounded className = "image-item" />
210- </ Row >
231+ < div
232+ style = { {
233+ overflow : "hidden" ,
234+ marginLeft : "2" ,
235+ marginRight : "2" ,
236+ } }
237+ >
238+ { images . map ( ( item , index ) => {
239+ return (
240+ < div
241+ style = { {
242+ boxSizing : "border-box" ,
243+ float : "left" ,
244+ margin : "2px" ,
245+ marginRight : "10px" ,
246+ overflow : "hidden" ,
247+ paddingBottom : "16%" ,
248+ position : "relative" ,
249+ width : `calc(25% - ${ 2 * 2 } px)` ,
250+
251+ "&:hover" : {
252+ opacity : 0.9 ,
253+ } ,
254+ } }
255+ >
256+ < img
257+ onClick = { this . toggleModal }
258+ src = { item . source }
259+ style = { { maxWidth : "100%" , position : "absolute" } }
260+ />
261+ </ div >
262+ ) ;
263+ } ) }
264+ </ div >
265+
266+ < ModalGateway >
267+ { imageModalOpen ? (
268+ < Modal onClose = { this . toggleModal } >
269+ < Carousel views = { this . state . images } />
270+ </ Modal >
271+ ) : null }
272+ </ ModalGateway >
211273 </ div >
212274 </ div >
213275 < div className = "comments" >
@@ -217,6 +279,9 @@ class DiscussionContent extends Component {
217279 userId = { this . state . userId }
218280 token = { this . state . token }
219281 getData = { this . getData }
282+ isAuthor = { this . state . author === this . state . userId }
283+ author = { this . state . author }
284+ handleComment = { this . handleComment }
220285 />
221286 </ div >
222287 < RequestChanges
0 commit comments