Skip to content

Commit 2159d5c

Browse files
committed
Merge branch 'dev'
2 parents e46e4c5 + dca9246 commit 2159d5c

File tree

6 files changed

+58
-23
lines changed

6 files changed

+58
-23
lines changed

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "cnode-react",
3-
"version": "0.1.0",
3+
"version": "0.1.1",
44
"private": true,
55
"dependencies": {
66
"format-publish-date": "^0.0.3",

public/index.html

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,6 @@
1010
</head>
1111
<body>
1212
<div id="root"></div>
13-
<link rel="stylesheet" type="text/css" href="//at.alicdn.com/t/font_610414_a2rijzwk05yaatt9.css">
13+
<link rel="stylesheet" type="text/css" href="//at.alicdn.com/t/font_610414_otpdqoj9jhrozuxr.css">
1414
</body>
1515
</html>

src/actions/topics.js

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -99,16 +99,17 @@ export const fetchTopicDetail = ({ id, accesstoken }) => dispatch => {
9999
data
100100
})
101101

102-
// highlight code and re-render
102+
// highlight code, add hash to user link and re-render
103103
const _data = Object.assign({}, data)
104104
const worker = new Worker()
105105
worker.onmessage = e => {
106-
_data.content = e.data
106+
console.timeEnd('worker')
107107
dispatch({
108108
type: FETCH_TOPIC_DETAIL,
109-
data: _data
109+
data: e.data
110110
})
111111
}
112-
worker.postMessage({ content: data.content })
112+
console.time('worker')
113+
worker.postMessage(_data)
113114
})
114115
}

src/components/TopicDetail/index.jsx

Lines changed: 19 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -87,6 +87,14 @@ class TopicDetail extends Component {
8787
id
8888
})
8989
}
90+
reply(name) {
91+
const at = `@${name} `
92+
this.refs.textarea.value = at
93+
this.refs.textarea.focus()
94+
this.setState({
95+
reply: at
96+
})
97+
}
9098
handleInput(e) {
9199
this.setState({
92100
reply: e.target.value.trim()
@@ -113,6 +121,7 @@ class TopicDetail extends Component {
113121
this.setState({
114122
reply: ''
115123
})
124+
this.refs.textarea.value = ''
116125
}
117126
})
118127
}
@@ -140,9 +149,15 @@ class TopicDetail extends Component {
140149
<span className="time_stamp">{format(item.create_at)}</span>
141150
<span className="floor">{index + 1}</span>
142151
</div>
143-
<div className={'user_action ' + (item.is_uped ? 'liked' : '')} onClick={this.like.bind(this, item.id, item.author.loginname)}>
144-
<span className="iconfont icon-thumbup"></span>
145-
<span className="up_number">{item.ups.length}</span>
152+
{/*赞*/}
153+
<div className="user_action">
154+
<div className={'action_item' + (item.is_uped ? 'liked' : '')} onClick={this.like.bind(this, item.id, item.author.loginname)}>
155+
<span className="iconfont icon-thumbup"></span>
156+
<span className="up_number">{item.ups.length}</span>
157+
</div>
158+
<div className="action_item" onClick={this.reply.bind(this, item.author.loginname)}>
159+
<span className="iconfont icon-reply"></span>
160+
</div>
146161
</div>
147162
</div>
148163
<div className="comment_content" dangerouslySetInnerHTML={{__html: item.content}} />
@@ -168,7 +183,7 @@ class TopicDetail extends Component {
168183
<div className="topic_reply">
169184
<p>添加评论</p>
170185
<div className="form">
171-
<textarea onChange={this.handleInput.bind(this)}></textarea>
186+
<textarea ref="textarea" onChange={this.handleInput.bind(this)}></textarea>
172187
<div className="button button_info" onClick={this.submit.bind(this)}>提交</div>
173188
</div>
174189
</div>

src/components/TopicDetail/topicDetail.less

Lines changed: 10 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -60,7 +60,16 @@
6060
}
6161
.user_action {
6262
display: flex;
63-
&.liked {
63+
span {
64+
height: 14px;
65+
line-height: 14px;
66+
color: #999;
67+
font-size: 14px;
68+
}
69+
.action_item {
70+
margin-left: 5px;
71+
}
72+
.liked {
6473
.icon-thumbup,
6574
.up_number {
6675
color: #6cf;
@@ -100,13 +109,6 @@
100109
font-size: 10px;
101110
color: #999;
102111
}
103-
.icon-thumbup,
104-
.up_number {
105-
height: 14px;
106-
line-height: 14px;
107-
color: #999;
108-
font-size: 14px;
109-
}
110112
.up_number {
111113
margin-left: 3px;
112114
}

src/hl.worker.js

Lines changed: 22 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,31 @@
11
const hljs = require('highlight.js')
22
const unescape = require('unescape-alltypes-html')
33

4-
onmessage = e => {
5-
const { content } = e.data
6-
const codeRE = /<code>([\s\S]*?)<\/code>/gm
7-
const highlighted = content.replace(codeRE, (...args) => {
4+
const codeRE = /<code>([\s\S]*?)<\/code>/gm
5+
const handleHighlight = raw => {
6+
return raw.replace(codeRE, (...args) => {
87
const raw = args[1]
98
const unescaped = unescape(raw)
109
const { value } = hljs.highlight('js', unescaped)
1110
return `<code>${value}</code>`
1211
})
13-
postMessage(highlighted)
12+
}
13+
14+
const linksRE = /(<a href="\/user)/g
15+
const handleAddHash = raw => raw.replace(linksRE, (...args) => `<a href="#/user`)
16+
17+
const handler = raw => handleAddHash(handleHighlight(raw))
18+
19+
onmessage = e => {
20+
const { content, replies } = e.data
21+
const _content = handler(content)
22+
const _replies = replies.map(reply => {
23+
reply.content = handler(reply.content)
24+
return reply
25+
})
26+
27+
postMessage(Object.assign({}, e.data, {
28+
content: _content,
29+
replies: _replies
30+
}))
1431
}

0 commit comments

Comments
 (0)