Skip to content

Commit 2fb9eed

Browse files
author
Parth Shah
committed
more fixes
1 parent 9b28460 commit 2fb9eed

File tree

22 files changed

+372
-204
lines changed

22 files changed

+372
-204
lines changed

package.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,7 @@
3535
"classnames": "^2.2.3",
3636
"draft-js": "^0.7.0",
3737
"draft-js-export-html": "^0.4.0",
38+
"draft-js-export-markdown": "^0.2.1",
3839
"fbemitter": "^2.1.1",
3940
"filepicker-js": "^2.4.17",
4041
"filesize": "^3.3.0",

src/components/ActionCard/AddComment.jsx

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@ export default class AddComment extends React.Component {
2222
this.props.onAdd(this.props.content)
2323
this.refs.input.focus()
2424
}
25-
25+
2626
render() {
2727
const { className, avatarUrl, authorName, onChange, content, placeholder, isAdding } = this.props
2828
const { isFocused } = this.state
@@ -63,4 +63,4 @@ AddComment.propTypes = {
6363
className: PropTypes.string,
6464
content: PropTypes.string,
6565
avatarUrl: PropTypes.string
66-
}
66+
}

src/components/Feed/FeedComments.jsx

Lines changed: 35 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@ import Panel from '../Panel/Panel'
44
import AddComment from '../ActionCard/AddComment'
55
import Comment from '../ActionCard/Comment'
66
import cn from 'classnames'
7+
import { THREAD_MESSAGES_PAGE_SIZE } from '../../config/constants'
78

89
const getCommentCount = (totalComments) => {
910
if (!totalComments) {
@@ -15,21 +16,38 @@ const getCommentCount = (totalComments) => {
1516
return `${totalComments} comments`
1617
}
1718

18-
const FeedComments = (props) => {
19-
const {
20-
comments, currentUser, totalComments, onLoadMoreComments, isLoadingComments, hasMoreComments, onAdd,
21-
onChange, content, avatarUrl, isAddingComment
22-
} = props
23-
let authorName = currentUser.firstName
24-
if (authorName && currentUser.lastName) {
25-
authorName += ' ' + currentUser.lastName
19+
class FeedComments extends React.Component {
20+
constructor(props) {
21+
super(props)
22+
this.state = { showAll: false }
2623
}
27-
const handleLoadMoreClick = () => {
28-
if (!isLoadingComments) {
29-
onLoadMoreComments()
24+
25+
render() {
26+
const {
27+
comments, currentUser, totalComments, /*onLoadMoreComments,*/ isLoadingComments, hasMoreComments, onAdd,
28+
onChange, content, avatarUrl, isAddingComment
29+
} = this.props
30+
let authorName = currentUser.firstName
31+
if (authorName && currentUser.lastName) {
32+
authorName += ' ' + currentUser.lastName
3033
}
31-
}
32-
return (
34+
const handleLoadMoreClick = () => {
35+
this.setState({showAll: true})
36+
// TODO - handle the case when a topic has more than 20 comments
37+
// since those will have to retrieved from the server
38+
// if (!isLoadingComments) {
39+
// onLoadMoreComments()
40+
// }
41+
}
42+
43+
let _comments = comments
44+
let _hasMoreComments = hasMoreComments
45+
if (!this.state.showAll && _comments.length > THREAD_MESSAGES_PAGE_SIZE) {
46+
_comments = _comments.slice(-THREAD_MESSAGES_PAGE_SIZE)
47+
_hasMoreComments = true
48+
}
49+
50+
return (
3351
<div>
3452
<Panel.Body className="comment-count-container">
3553
<div className="portrait" />
@@ -39,17 +57,17 @@ const FeedComments = (props) => {
3957
{getCommentCount(totalComments)}
4058
</div>
4159
<hr className={cn({'no-margin': !comments.length})} />
42-
{hasMoreComments && <div className={cn('comment-collapse', {'loading-comments': isLoadingComments})}>
60+
{_hasMoreComments && <div className={cn('comment-collapse', {'loading-comments': isLoadingComments})}>
4361
<a href="javascript:" onClick={ handleLoadMoreClick } className="comment-collapse-button">
4462
{isLoadingComments ? 'Loading...' : 'View older comments'}
4563
</a>
4664
</div>}
4765
</div>
4866
</div>
4967
</Panel.Body>
50-
{comments.map((item) =>
68+
{_comments.map((item, idx) =>
5169
<Comment
52-
key={item.id}
70+
key={idx}
5371
avatarUrl={item.author.photoURL}
5472
authorName={item.author.firstName + ' ' + item.author.lastName}
5573
date={moment(item.date).fromNow()}
@@ -70,8 +88,8 @@ const FeedComments = (props) => {
7088
/>
7189
</div>
7290
)
91+
}
7392
}
74-
7593
FeedComments.propTypes = {
7694
comments: PropTypes.array.isRequired
7795
}

src/components/Feed/NewPost.jsx

Lines changed: 31 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,14 @@
11
import React, {PropTypes} from 'react'
22
import {Editor, EditorState, RichUtils} from 'draft-js'
3-
import {stateToHTML} from 'draft-js-export-html'
3+
import {stateToMarkdown} from 'draft-js-export-markdown'
44
import cn from 'classnames'
55
import './draftjs.scss'
66
import { Avatar } from 'appirio-tech-react-components'
7-
// import { Icons } from 'appirio-tech-react-components'
87

98
const styles = [
109
{className: 'bold', style: 'BOLD'},
11-
{className: 'italic', style: 'ITALIC'},
12-
{className: 'underline', style: 'UNDERLINE'}
10+
{className: 'italic', style: 'ITALIC'}
11+
// {className: 'underline', style: 'UNDERLINE'}
1312
]
1413

1514
const blocks = [
@@ -41,13 +40,13 @@ class NewPost extends React.Component {
4140

4241
constructor(props) {
4342
super(props)
44-
this.state = {editorState: EditorState.createEmpty(), expandedEditor: false}
45-
this.onChange = (editorState) => this.setState({editorState})
46-
43+
this.state = {editorState: EditorState.createEmpty(), expandedEditor: false, canSubmit: false}
44+
this.onEditorChange = this.onEditorChange.bind(this)
4745
this.handleKeyCommand = this.handleKeyCommand.bind(this)
4846
this.toggleBlockType = this.toggleBlockType.bind(this)
4947
this.toggleInlineStyle = this.toggleInlineStyle.bind(this)
5048
this.onClickOutside = this.onClickOutside.bind(this)
49+
this.onNewPostChange = this.onNewPostChange.bind(this)
5150
}
5251

5352
componentDidMount() {
@@ -64,7 +63,7 @@ class NewPost extends React.Component {
6463
let isEditor = false
6564
let isCloseButton = false
6665
const title = this.refs.title.value
67-
const content = stateToHTML(this.state.editorState.getCurrentContent())
66+
const hasContent = this.state.editorState.getCurrentContent().hasText()
6867

6968
do {
7069
if(currNode.className
@@ -87,7 +86,7 @@ class NewPost extends React.Component {
8786
// if any of title and content, is non empty, do not proceed
8887
if (!isEditor
8988
&& !isCloseButton
90-
&& ((title && title.length > 0) || (content && content !== '<p><br></p>'))) {
89+
&& ((title && title.trim().length > 0) || hasContent)) {
9190
return
9291
}
9392

@@ -102,23 +101,34 @@ class NewPost extends React.Component {
102101
const {editorState} = this.state
103102
const newState = RichUtils.handleKeyCommand(editorState, command)
104103
if (newState) {
105-
this.onChange(newState)
104+
this.onEditorChange(newState)
106105
return true
107106
}
108107
return false
109108
}
110109

111110
toggleBlockType(blockType) {
112-
this.onChange(RichUtils.toggleBlockType(this.state.editorState, blockType))
111+
this.onEditorChange(RichUtils.toggleBlockType(this.state.editorState, blockType))
113112
}
114113

115114
toggleInlineStyle(inlineStyle) {
116-
this.onChange(RichUtils.toggleInlineStyle(this.state.editorState, inlineStyle))
115+
this.onEditorChange(RichUtils.toggleInlineStyle(this.state.editorState, inlineStyle))
116+
}
117+
118+
onEditorChange(editorState) {
119+
this.setState({editorState})
120+
this.onNewPostChange()
121+
}
122+
123+
onNewPostChange() {
124+
this.setState({
125+
canSubmit: !!this.refs.title.value.trim().length && this.state.editorState.getCurrentContent().hasText()
126+
})
117127
}
118128

119129
render() {
120-
const {currentUser, heading, titlePlaceholder} = this.props
121-
const {editorState} = this.state
130+
const {currentUser, titlePlaceholder, isCreating} = this.props
131+
const {editorState, canSubmit} = this.state
122132
const currentStyle = editorState.getCurrentInlineStyle()
123133
const selection = editorState.getSelection()
124134
let authorName = currentUser.firstName
@@ -137,7 +147,7 @@ class NewPost extends React.Component {
137147
return
138148
}
139149
const title = this.refs.title.value
140-
const content = stateToHTML(editorState.getCurrentContent())
150+
const content = stateToMarkdown(editorState.getCurrentContent())
141151
if (title && content) {
142152
this.props.onPost({title, content})
143153
this.setState({editorState: EditorState.createEmpty()})
@@ -159,9 +169,11 @@ class NewPost extends React.Component {
159169
{/* No need to handle click event of the close button as its already
160170
handled in onClickOutside handler */}
161171
<a href="javascript:" className="btn-close" />
172+
{/*
162173
<div className="modal-title title-muted">
163-
{ heading || 'NEW STATUS POST' }
174+
{ heading || 'NEW STATUS POST' }
164175
</div>
176+
*/}
165177
<div className="modal-row">
166178
<div className="portrait">
167179
<Avatar avatarUrl={ currentUser.photoURL } userName={ authorName } />
@@ -171,13 +183,14 @@ class NewPost extends React.Component {
171183
ref="title"
172184
className="new-post-title"
173185
type="text"
186+
onChange={this.onNewPostChange}
174187
placeholder={ titlePlaceholder || 'Title of the post'}
175188
/>
176189
<div className="draftjs-editor tc-textarea">
177190
<Editor
178191
ref="editor"
179192
editorState={editorState}
180-
onChange={this.onChange}
193+
onChange={this.onEditorChange}
181194
handleKeyCommand={this.handleKeyCommand}
182195
/>
183196
<div className="textarea-footer">
@@ -206,7 +219,7 @@ class NewPost extends React.Component {
206219
{/*<div className="separator"/>
207220
<button className="attach"/>*/}
208221
</div>
209-
<button className="tc-btn tc-btn-primary tc-btn-sm" onClick={onPost} disabled={ this.props.isCreating }>
222+
<button className="tc-btn tc-btn-primary tc-btn-sm" onClick={onPost} disabled={isCreating || !canSubmit }>
210223
{ this.props.isCreating ? 'Posting...' : 'Post' }
211224
</button>
212225
</div>

src/components/Feed/draftjs.scss

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -51,7 +51,7 @@
5151
}
5252

5353
.public-DraftStyleDefault-ul,
54-
.public-DraftStyleDefault-ol {
54+
.public-DraftStyleDefault-ol {
5555
margin: $base-unit*2 0 $base-unit*2 $base-unit*6
5656
}
5757

@@ -75,7 +75,7 @@
7575
list-style-type: disc;
7676
}
7777
ol {
78-
list-style-type: disc;
78+
list-style-type: decimal;
7979
}
8080
blockquote {
8181
@include roboto-medium;
@@ -95,4 +95,4 @@
9595
em {
9696
font-style: italic;
9797
}
98-
}
98+
}

src/components/FileList/FileIcons.jsx

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -24,9 +24,15 @@ const Gzip = ({ width = '42px', height = '42px' }) => {
2424
</svg>
2525
)
2626
}
27-
27+
const Default = ({width = '42px', height = '42px'}) => (
28+
<svg xmlns="http://www.w3.org/2000/svg" x="0px" y="0px" width={width} height={height} viewBox="0 0 48 48"><g >
29+
<path fill="#E6E6E6" d="M41,47H7c-1.105,0-2-0.895-2-2V3c0-1.105,0.895-2,2-2l24,0l12,12v32C43,46.105,42.105,47,41,47z"/>
30+
<path fill="#B3B3B3" d="M31,1v10c0,1.105,0.895,2,2,2h10L31,1z"/>
31+
</g></svg>
32+
)
2833
const FileIcons = {
29-
Gzip
34+
Gzip,
35+
Default
3036
}
3137

3238
export default FileIcons

src/components/FileList/FileListItem.jsx

Lines changed: 4 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -49,7 +49,7 @@ export default class FileListItem extends React.Component {
4949
<a href="javascript:" className="icon-close" onClick={onExitEdit}><CloseIcon /></a>
5050
</div>
5151
</div>
52-
<textarea defaultValue={description} ref="desc" className="tc-textarea" />
52+
<textarea defaultValue={description} ref="desc" maxLength={250} className="tc-textarea" />
5353
</div>
5454
)
5555
}
@@ -72,24 +72,15 @@ export default class FileListItem extends React.Component {
7272
</div>
7373
)
7474
}
75-
76-
getFileIcon(type) {
77-
switch (type) {
78-
case 'application/zip':
79-
case 'applicatin/archive':
80-
return <FileIcons.Gzip />
81-
default:
82-
return <FileIcons.Gzip /> // TODO add more
83-
}
84-
}
75+
8576
render() {
8677
const {isEditing} = this.state
87-
const icon = this.getFileIcon(this.props.contentType)
78+
// const Icon = this.getFileIcon(this.props.contentType)
8879

8980
return (
9081
<div className="file-list-item">
9182
<div className="icon-col">
92-
{icon}
83+
<FileIcons.Default width={42} height={42}/>
9384
</div>
9485
<div className="content-col">
9586
{isEditing ? this.renderEditing() : this.renderReadOnly()}
Lines changed: 4 additions & 0 deletions
Loading
Lines changed: 19 additions & 0 deletions
Loading
Lines changed: 21 additions & 0 deletions
Loading

0 commit comments

Comments
 (0)