Skip to content
This repository was archived by the owner on Nov 1, 2021. It is now read-only.

Commit b1e5eac

Browse files
committed
refactor: later
1 parent 410ff7e commit b1e5eac

File tree

31 files changed

+757
-115
lines changed

31 files changed

+757
-115
lines changed

.eslintrc.js

Lines changed: 16 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
module.exports = {
22
extends: ['airbnb', 'plugin:react/recommended', 'prettier', 'prettier/react'],
3-
plugins: ['prettier', 'react'],
3+
plugins: ['prettier', 'react', 'cypress'],
44
parser: 'babel-eslint',
55
parserOptions: {
66
ecmaVersion: 2016,
@@ -13,26 +13,34 @@ module.exports = {
1313
es6: true,
1414
node: true,
1515
jest: true,
16+
'cypress/globals': true,
1617
},
1718
rules: {
1819
'arrow-body-style': 0,
19-
'no-param-reassign': 0, // heavilly used in store.actions
20-
'no-use-before-define': 0, // heavilly used in store.views
20+
// need for _store init
21+
'no-underscore-dangle': 0,
22+
// heavilly used in store.actions
23+
'no-param-reassign': 0,
24+
// heavilly used in store.views
25+
'no-use-before-define': 0,
26+
// force-return is unneeded
2127
'consistent-return': 0,
22-
'no-nested-ternary': 0, // TODO
23-
'no-shadow': 0, //TODO: currently just for entry
24-
'no-return-assign': 0, //TODO currently only for BookStore
28+
'no-shadow': 0,
29+
// error could be object for parse by upfloor
2530
'prefer-promise-reject-errors': 0,
2631
'react/jsx-no-bind': 0,
32+
// allow JSX in js files
2733
'react/jsx-filename-extension': [1, { extensions: ['.js', '.jsx'] }],
2834
'react/forbid-prop-types': 0,
35+
// no need sort
2936
'react/sort-comp': 0,
3037
'react/prop-types': [1, { skipUndeclared: true }],
3138
'jsx-a11y/href-no-hash': 'off',
3239
'jsx-a11y/no-static-element-interactions': 0,
3340
'jsx-a11y/click-events-have-key-events': 0,
34-
'import/no-named-as-default': 0,
35-
'import/no-named-as-default-member': 0,
41+
42+
// for cypress test usage
43+
'no-unused-expressions': 0,
3644

3745
'prettier/prettier': [
3846
'error',

components/MarkDownRender/index.js

Lines changed: 89 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,89 @@
1+
/*
2+
*
3+
* MarkDownRender
4+
*
5+
*/
6+
import React from 'react'
7+
import R from 'ramda'
8+
import PropTypes from 'prop-types'
9+
10+
import Remarkable from 'remarkable'
11+
import remarkableemoj from 'remarkable-emoji'
12+
import mentionsPlugin from 'remarkable-mentions'
13+
import Prism from 'mastani-codehighlight'
14+
15+
import { MENTION_USER_ADDR } from '../../config'
16+
import MarkDownStyle from '../../containers/ThemeWrapper/MarkDownStyle'
17+
import { PreviewerContainer } from './styles'
18+
19+
import { makeDebugger } from '../../utils'
20+
21+
const md = new Remarkable('full', {
22+
html: true,
23+
breaks: false,
24+
})
25+
md.use(mentionsPlugin({ url: MENTION_USER_ADDR }))
26+
md.use(remarkableemoj)
27+
28+
/* eslint-disable no-unused-vars */
29+
const debug = makeDebugger('c:MarkDownRender:index')
30+
/* eslint-enable no-unused-vars */
31+
32+
class MarkDownRender extends React.Component {
33+
state = {
34+
body: '',
35+
}
36+
37+
componentDidMount() {
38+
Prism.highlightAll()
39+
setTimeout(() => Prism.highlightAll(), 1000)
40+
}
41+
42+
componentWillReceiveProps(nextProps) {
43+
const { body } = this.state
44+
45+
if (nextProps.body !== body) {
46+
this.setState({ body: nextProps.body })
47+
setTimeout(() => Prism.highlightAll(), 1000)
48+
}
49+
}
50+
51+
render() {
52+
const { body } = this.props
53+
/*
54+
NOTE: the '---' in normal markdown will break the render process
55+
this is the most mother fucking disgusting bug i ever seen
56+
*/
57+
const safeBody = R.replace(/---(\r\n|\r|\n)/g, '----', body || '')
58+
59+
return (
60+
<PreviewerContainer>
61+
<MarkDownStyle>
62+
<div className="markdown-body">
63+
{/* eslint-disable react/no-danger */}
64+
<div
65+
id="typewriter-preview-container"
66+
dangerouslySetInnerHTML={{
67+
__html: md.render(safeBody),
68+
}}
69+
/>
70+
{/* eslint-enable react/no-danger */}
71+
</div>
72+
</MarkDownStyle>
73+
</PreviewerContainer>
74+
)
75+
}
76+
}
77+
78+
// TODO default props check
79+
80+
MarkDownRender.propTypes = {
81+
// https://www.npmjs.com/package/prop-types
82+
body: PropTypes.string,
83+
}
84+
85+
MarkDownRender.defaultProps = {
86+
body: '',
87+
}
88+
89+
export default MarkDownRender
Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
import styled from 'styled-components'
2+
// bbst
3+
4+
export const PreviewerContainer = styled.div``
5+
6+
export const holder = 1
Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
// import React from 'react'
2+
// import { shallow } from 'enzyme'
3+
4+
// import MarkDownRender from '../index'
5+
6+
describe('TODO <MarkDownRender />', () => {
7+
it('Expect to have unit tests specified', () => {
8+
expect(true).toEqual(true)
9+
})
10+
})

components/index.js

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@ export { default as BannerCountBrief } from './BannerCountBrief'
1111
export { default as MarkDownPreviewer } from './MarkDownPreviewer'
1212
export { default as ContentFilter } from './ContentFilter'
1313
export { default as FileUploader } from './FileUploader'
14+
export { default as MarkDownRender } from './MarkDownRender'
1415

1516
export { default as StateTree } from './StateTree'
1617
export { default as StatusBox } from './StatusBox'

containers/Comments/CommentsList.js

Lines changed: 30 additions & 49 deletions
Original file line numberDiff line numberDiff line change
@@ -3,16 +3,19 @@ import React from 'react'
33
import TimeAgo from 'timeago-react'
44

55
import { ICON_CMD } from '../../config'
6+
/* import { fakeUsers, getRandomInt, Global, prettyNum } from '../../utils' */
7+
import { Global, prettyNum, uid } from '../../utils'
68

79
import {
810
AvatarsRow,
911
Button,
1012
SpaceGrow,
1113
Pagi,
1214
CommentLoading,
13-
MarkDownPreviewer,
15+
MarkDownRender,
1416
} from '../../components'
1517

18+
import * as logic from './logic'
1619
import CommentsFilter from './CommentsFilter'
1720

1821
import {
@@ -49,17 +52,10 @@ import {
4952
ReplyToFloor,
5053
} from './styles/comments_list'
5154

52-
import * as logic from './logic'
53-
import { uid, Global, prettyNum, makeDebugger } from '../../utils'
54-
55-
/* eslint-disable no-unused-vars */
56-
const debug = makeDebugger('C:CommentsList')
57-
/* eslint-enable no-unused-vars */
58-
5955
const getSelection = () => {
6056
const selectText = Global.getSelection().toString()
6157
if (!R.isEmpty(selectText)) {
62-
debug('getSelection', selectText)
58+
/* console.log('getSelection', selectText) */
6359
// TODO: then use window.getSelection().getRangeAt(0).getBoundingClientRect() to draw a button
6460
}
6561
}
@@ -107,9 +103,11 @@ const ActionBottom = ({ data, accountInfo }) => {
107103
}
108104

109105
const getAuthors = comment => {
106+
/* eslint-disable no-return-assign */
110107
const replies = R.forEach(reply => {
111108
return (reply.author.extra_id = reply.id)
112109
}, R.clone(comment.replies))
110+
/* eslint-enable */
113111

114112
return R.pluck('author', replies)
115113
}
@@ -138,9 +136,7 @@ const Comment = ({ data, tobeDeleteId, accountInfo }) => (
138136
total={data.repliesCount}
139137
/>
140138
</ReplyUsers>
141-
) : (
142-
<div />
143-
)}
139+
) : null}
144140
</CommentHeaderFirst>
145141
<TimeStamps>
146142
<TimeAgo datetime={data.insertedAt} locale="zh_CN" />
@@ -154,10 +150,8 @@ const Comment = ({ data, tobeDeleteId, accountInfo }) => (
154150
<ReplyToBody>{data.replyTo.body}</ReplyToBody>
155151
<ReplyToFloor>#{data.replyTo.floor}</ReplyToFloor>
156152
</ReplyBar>
157-
) : (
158-
<div />
159-
)}
160-
<MarkDownPreviewer body={data.body} />
153+
) : null}
154+
<MarkDownRender body={data.body} />
161155
</CommentContent>
162156
<CommentFooter>
163157
<Actions>
@@ -190,7 +184,7 @@ const Comment = ({ data, tobeDeleteId, accountInfo }) => (
190184
)
191185

192186
const Lists = ({ entries, tobeDeleteId, accountInfo }) => (
193-
<div>
187+
<React.Fragment>
194188
{entries.map(c => (
195189
<div key={uid.gen()}>
196190
<Comment
@@ -200,48 +194,33 @@ const Lists = ({ entries, tobeDeleteId, accountInfo }) => (
200194
/>
201195
</div>
202196
))}
203-
</div>
197+
</React.Fragment>
204198
)
205199

206-
const TotalCountText = ({ count }) => {
207-
return (
208-
<TotalCountWrapper>
209-
{count > 0 ? (
210-
<ListTitle id="lists-info">
211-
收到 <TotalNum>{count}</TotalNum> 条评论:
212-
</ListTitle>
213-
) : (
214-
<div />
215-
)}
216-
</TotalCountWrapper>
217-
)
218-
}
200+
const TotalCountText = ({ count }) => (
201+
<TotalCountWrapper>
202+
{count > 0 ? (
203+
<ListTitle id="lists-info">
204+
共收到 <TotalNum>{count}</TotalNum> 条评论:
205+
</ListTitle>
206+
) : null}
207+
</TotalCountWrapper>
208+
)
219209

220210
const CommentsList = ({
221-
entries,
222211
accountInfo,
223-
restProps: {
224-
totalCount,
225-
pageSize,
226-
pageNumber,
227-
loading,
228-
loadingFresh,
229-
tobeDeleteId,
230-
filterType,
231-
},
212+
pagedComments: { entries, totalCount, pageSize, pageNumber },
213+
restProps: { loading, loadingFresh, tobeDeleteId, filterType },
232214
}) => (
233-
<div>
215+
<React.Fragment>
234216
<TotalHeader>
235217
<TotalCountText count={totalCount} />
236-
<CommentsFilter filterType={filterType} />
218+
<CommentsFilter filterType={filterType} show={totalCount >= 2} />
237219
</TotalHeader>
238-
239-
{loadingFresh ? (
220+
{!loadingFresh ? null : (
240221
<CommentBlock>
241222
<CommentLoading />
242223
</CommentBlock>
243-
) : (
244-
<div />
245224
)}
246225
<ListsContainer>
247226
{loading ? (
@@ -258,15 +237,17 @@ const CommentsList = ({
258237
/>
259238
)}
260239
</ListsContainer>
261-
262240
<Pagi
263241
left="-10px"
264242
pageNumber={pageNumber}
265243
pageSize={pageSize}
266244
totalCount={totalCount}
267245
onChange={logic.pageChange}
246+
showBottomMsg
247+
noMoreMsg="没有更多的评论了"
248+
emptyMsg="目前还没有评论"
268249
/>
269-
</div>
250+
</React.Fragment>
270251
)
271252

272253
export default CommentsList

containers/CommunitiesBanner/logic.js

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -48,7 +48,6 @@ export const loadCategories = () =>
4848
sr71$.query(S.pagedCategories, { filter: {} })
4949

5050
export function onAdd(thread) {
51-
console.log('thread: ', thread)
5251
switch (thread) {
5352
case 'tags': {
5453
return dispatchEvent(EVENT.NAV_CREATE_TAG, {

containers/Header/schema.js

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -21,8 +21,6 @@ const user = gql`
2121
avatar
2222
bio
2323
fromGithub
24-
company
25-
education
2624
location
2725
qq
2826
weibo

containers/Preview/index.js

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@ import ArticleViwer from '../ArticleViwer'
1717
import AccountViewer from '../AccountViewer'
1818
import AccountEditor from '../AccountEditor'
1919
import CommunityEditor from '../CommunityEditor'
20+
import ThreadEditor from '../ThreadEditor'
2021
import TagEditor from '../TagEditor'
2122
import CategoryEditor from '../CategoryEditor'
2223
import CategorySetter from '../CategorySetter'
@@ -102,7 +103,7 @@ const Viewer = ({
102103
return <CategorySetter editData={editCommunityData} />
103104
}
104105
case TYPE.PREVIEW_CREATE_THREAD: {
105-
return <h3>PREVIEW_CREATE_THREAD</h3>
106+
return <ThreadEditor />
106107
}
107108
case TYPE.PREVIEW_SET_THREAD: {
108109
return <ThreadSetter editData={editCommunityData} />

containers/Preview/logic.js

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -178,6 +178,7 @@ const DataResolver = [
178178
match: asyncRes(EVENT.NAV_CREATE_THREAD),
179179
action: res => {
180180
const event = res[EVENT.NAV_CREATE_THREAD]
181+
console.log('NAV_CREATE_THREAD data: ', event.data)
181182

182183
store.markState({ editCommunity: event.data })
183184
store.open(event.type)

0 commit comments

Comments
 (0)