Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings
This repository was archived by the owner on Nov 1, 2021. It is now read-only.

Commit6e5f1c0

Browse files
committed
refactor: later
1 parent68b44d3 commit6e5f1c0

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+
importReactfrom'react'
7+
importRfrom'ramda'
8+
importPropTypesfrom'prop-types'
9+
10+
importRemarkablefrom'remarkable'
11+
importremarkableemojfrom'remarkable-emoji'
12+
importmentionsPluginfrom'remarkable-mentions'
13+
importPrismfrom'mastani-codehighlight'
14+
15+
import{MENTION_USER_ADDR}from'../../config'
16+
importMarkDownStylefrom'../../containers/ThemeWrapper/MarkDownStyle'
17+
import{PreviewerContainer}from'./styles'
18+
19+
import{makeDebugger}from'../../utils'
20+
21+
constmd=newRemarkable('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+
constdebug=makeDebugger('c:MarkDownRender:index')
30+
/* eslint-enable no-unused-vars */
31+
32+
classMarkDownRenderextendsReact.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+
constsafeBody=R.replace(/---(\r\n|\r|\n)/g,'----',body||'')
58+
59+
return(
60+
<PreviewerContainer>
61+
<MarkDownStyle>
62+
<divclassName="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+
exportdefaultMarkDownRender
Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
importstyledfrom'styled-components'
2+
// bbst
3+
4+
exportconstPreviewerContainer=styled.div``
5+
6+
exportconstholder=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{defaultasMarkDownPreviewer}from'./MarkDownPreviewer'
1212
export{defaultasContentFilter}from'./ContentFilter'
1313
export{defaultasFileUploader}from'./FileUploader'
14+
export{defaultasMarkDownRender}from'./MarkDownRender'
1415

1516
export{defaultasStateTree}from'./StateTree'
1617
export{defaultasStatusBox}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
importTimeAgofrom'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*aslogicfrom'./logic'
1619
importCommentsFilterfrom'./CommentsFilter'
1720

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

52-
import*aslogicfrom'./logic'
53-
import{uid,Global,prettyNum,makeDebugger}from'../../utils'
54-
55-
/* eslint-disable no-unused-vars */
56-
constdebug=makeDebugger('C:CommentsList')
57-
/* eslint-enable no-unused-vars */
58-
5955
constgetSelection=()=>{
6056
constselectText=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
constgetAuthors=comment=>{
106+
/* eslint-disable no-return-assign */
110107
constreplies=R.forEach(reply=>{
111108
return(reply.author.extra_id=reply.id)
112109
},R.clone(comment.replies))
110+
/* eslint-enable */
113111

114112
returnR.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
<TimeAgodatetime={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-
<MarkDownPreviewerbody={data.body}/>
153+
) :null}
154+
<MarkDownRenderbody={data.body}/>
161155
</CommentContent>
162156
<CommentFooter>
163157
<Actions>
@@ -190,7 +184,7 @@ const Comment = ({ data, tobeDeleteId, accountInfo }) => (
190184
)
191185

192186
constLists=({ entries, tobeDeleteId, accountInfo})=>(
193-
<div>
187+
<React.Fragment>
194188
{entries.map(c=>(
195189
<divkey={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-
constTotalCountText=({ count})=>{
207-
return(
208-
<TotalCountWrapper>
209-
{count>0 ?(
210-
<ListTitleid="lists-info">
211-
收到<TotalNum>{count}</TotalNum> 条评论:
212-
</ListTitle>
213-
) :(
214-
<div/>
215-
)}
216-
</TotalCountWrapper>
217-
)
218-
}
200+
constTotalCountText=({ count})=>(
201+
<TotalCountWrapper>
202+
{count>0 ?(
203+
<ListTitleid="lists-info">
204+
共收到<TotalNum>{count}</TotalNum> 条评论:
205+
</ListTitle>
206+
) :null}
207+
</TotalCountWrapper>
208+
)
219209

220210
constCommentsList=({
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
<TotalCountTextcount={totalCount}/>
236-
<CommentsFilterfilterType={filterType}/>
218+
<CommentsFilterfilterType={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
exportdefaultCommentsList

‎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
exportfunctiononAdd(thread){
51-
console.log('thread: ',thread)
5251
switch(thread){
5352
case'tags':{
5453
returndispatchEvent(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
importAccountViewerfrom'../AccountViewer'
1818
importAccountEditorfrom'../AccountEditor'
1919
importCommunityEditorfrom'../CommunityEditor'
20+
importThreadEditorfrom'../ThreadEditor'
2021
importTagEditorfrom'../TagEditor'
2122
importCategoryEditorfrom'../CategoryEditor'
2223
importCategorySetterfrom'../CategorySetter'
@@ -102,7 +103,7 @@ const Viewer = ({
102103
return<CategorySettereditData={editCommunityData}/>
103104
}
104105
caseTYPE.PREVIEW_CREATE_THREAD:{
105-
return<h3>PREVIEW_CREATE_THREAD</h3>
106+
return<ThreadEditor/>
106107
}
107108
caseTYPE.PREVIEW_SET_THREAD:{
108109
return<ThreadSettereditData={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
constevent=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)

[8]ページ先頭

©2009-2025 Movatter.jp