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 8, 2022. It is now read-only.

Commitbfb001d

Browse files
committed
refactor(wiki): support realdata
1. github api2. add contributor3. sync readme.4.md hignlight fix5.model field fix6.importfetch fix
1 parent8040da6 commitbfb001d

File tree

22 files changed

+269
-110
lines changed

22 files changed

+269
-110
lines changed

‎components/MarkDownRender/index.js‎

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -30,8 +30,22 @@ const debug = makeDebugger('c:MarkDownRender:index')
3030
/* eslint-enable no-unused-vars */
3131

3232
classMarkDownRenderextendsReact.Component{
33+
state={
34+
body:'',
35+
}
36+
3337
componentDidMount(){
3438
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+
}
3549
}
3650

3751
render(){

‎containers/AvatarAdder/AdderPanel.js‎

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@ import SearchLoing from './SearchLoading'
2121

2222
import*aslogicfrom'./logic'
2323

24-
constAdderPanel=({ user, searchValue, searching})=>(
24+
constAdderPanel=({ user, searchValue, searching, onConfirm})=>(
2525
<Wrapper>
2626
<Header>
2727
<LabelIconsrc={`${ICON_CMD}/github.svg`}/>
@@ -46,7 +46,7 @@ const AdderPanel = ({ user, searchValue, searching }) => (
4646
<GithubUserCarduser={user}/>
4747
<Divider/>
4848
<Footer>
49-
<AddBtnonClick={logic.onConfirm}>
49+
<AddBtnonClick={onConfirm}>
5050
<AdderIconsrc={`${ICON_CMD}/add.svg`}/>
5151
<div>添加</div>
5252
</AddBtn>

‎containers/AvatarAdder/index.js‎

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@
66

77
importReactfrom'react'
88
import{inject,observer}from'mobx-react'
9+
importPropTypesfrom'prop-types'
910

1011
import{Popover}from'../../components'
1112

@@ -26,6 +27,12 @@ class AvatarAdderContainer extends React.Component {
2627
logic.init(avatarAdder)
2728
}
2829

30+
onConfirm(user){
31+
const{ onConfirm}=this.props
32+
logic.onConfirm()
33+
onConfirm(user)
34+
}
35+
2936
render(){
3037
const{ avatarAdder}=this.props
3138
const{
@@ -43,6 +50,7 @@ class AvatarAdderContainer extends React.Component {
4350
user={githubUserData}
4451
searchValue={searchValue}
4552
searching={searching}
53+
onConfirm={this.onConfirm.bind(this,githubUserData)}
4654
/>
4755
}
4856
placement="bottom"
@@ -57,4 +65,13 @@ class AvatarAdderContainer extends React.Component {
5765
}
5866
}
5967

68+
AvatarAdderContainer.propTypes={
69+
avatarAdder:PropTypes.object.isRequired,
70+
onConfirm:PropTypes.func,
71+
}
72+
73+
AvatarAdderContainer.defaultProps={
74+
onConfirm:debug,
75+
}
76+
6077
exportdefaultinject(storePlug('avatarAdder'))(observer(AvatarAdderContainer))

‎containers/AvatarAdder/logic.js‎

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,11 @@ export function onSearch(e) {
3030
}
3131

3232
exportfunctiononConfirm(){
33-
debug('onConfirm: ',store.githubUserData)
33+
store.markState({
34+
searching:false,
35+
githubUser:null,
36+
popoverVisiable:false,
37+
})
3438
}
3539

3640
exportconstinputOnChange=e=>

‎containers/UsersThread/geo_data.js‎

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
//
2-
import{fetch}from'whatwg-fetch'
2+
/* import { fetch } from 'whatwg-fetch' */
3+
importfetchfrom'isomorphic-fetch'
34
import{BStore}from'../../utils'
45

56
constendpoint=

‎containers/WikiThread/AvatarList.js‎

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -5,12 +5,11 @@ import { Popover, GithubUserCard } from '../../components'
55

66
import{Wrapper,AvatarLink,Avatar,CardWrapper}from'./styles/avatar_list'
77

8-
importfakeUserfrom'./fakeUser'
98
import{uid}from'../../utils'
109

11-
constAvatarList=()=>(
10+
constAvatarList=({ users, addContributor})=>(
1211
<Wrapper>
13-
{fakeUser.map(user=>(
12+
{users.map(user=>(
1413
<Popover
1514
content={
1615
<CardWrapper>
@@ -26,7 +25,7 @@ const AvatarList = () => (
2625
</AvatarLink>
2726
</Popover>
2827
))}
29-
<AvatarAdder/>
28+
<AvatarAdderonConfirm={addContributor}/>
3029
</Wrapper>
3130
)
3231

‎containers/WikiThread/Contributors.js‎

Lines changed: 18 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
importReactfrom'react'
2+
importTimeAgofrom'timeago-react'
23

3-
import{DotDivider}from'../../components'
4+
import{DotDivider,Button}from'../../components'
45

56
import{
67
Wrapper,
@@ -14,6 +15,8 @@ import {
1415

1516
importAvatarListfrom'./AvatarList'
1617

18+
import*aslogicfrom'./logic'
19+
1720
constNote=()=>(
1821
<NoteWrapper>
1922
<NoteTitle>本页贡献者</NoteTitle>
@@ -22,17 +25,27 @@ const Note = () => (
2225
</NoteWrapper>
2326
)
2427

25-
constContributors=()=>(
28+
constContributors=({ users, views, lastSync})=>(
2629
<Wrapper>
2730
<Note/>
28-
<AvatarList/>
31+
<AvatarListusers={users}addContributor={logic.addContributor}/>
2932

3033
<FootNote>
3134
<SycNote>
32-
浏览:228
35+
浏览:{views}
3336
<DotDivider/>
34-
最后同步: 3天前
37+
最后同步:&nbsp;
38+
<TimeAgodatetime={lastSync||''}locale="zh_CN"/>
3539
</SycNote>
40+
<br/>
41+
<Button
42+
size="small"
43+
type="primary"
44+
ghost
45+
onClick={logic.syncWikiFromGithub}
46+
>
47+
同步 wiki
48+
</Button>
3649
</FootNote>
3750
</Wrapper>
3851
)

‎containers/WikiThread/fakeUser.js‎

Lines changed: 0 additions & 65 deletions
This file was deleted.

‎containers/WikiThread/index.js‎

Lines changed: 12 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@ import { PublishLabel, MarkDownRender } from '../../components'
1414
import{
1515
Wrapper,
1616
LeftPart,
17+
WikiWrapper,
1718
LeftPadding,
1819
RightPart,
1920
RightPadding,
@@ -36,11 +37,16 @@ class WikiThreadContainer extends React.Component {
3637
}
3738

3839
render(){
40+
const{ wikiThread}=this.props
41+
const{ wikiData}=wikiThread
42+
3943
return(
4044
<Wrapper>
4145
<LeftPadding/>
4246
<LeftPart>
43-
<MarkDownRenderbody="## this is a wiki demo"/>
47+
<WikiWrapper>
48+
<MarkDownRenderbody={wikiData.readme}/>
49+
</WikiWrapper>
4450
</LeftPart>
4551
<RightPart>
4652
<React.Fragment>
@@ -50,7 +56,11 @@ class WikiThreadContainer extends React.Component {
5056
iconSrc={`${ICON_CMD}/github.svg`}
5157
/>
5258
</PublishBtn>
53-
<Contributors/>
59+
<Contributors
60+
users={wikiData.contributors}
61+
views={wikiData.views}
62+
lastSync={wikiData.lastSync}
63+
/>
5464
</React.Fragment>
5565
</RightPart>
5666
<RightPadding/>

‎containers/WikiThread/logic.js‎

Lines changed: 63 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,16 @@
11
// import R from 'ramda'
22

3-
import{makeDebugger,$solver,asyncErr,ERR}from'../../utils'
3+
import{
4+
makeDebugger,
5+
$solver,
6+
asyncRes,
7+
asyncErr,
8+
ERR,
9+
githubApi,
10+
}from'../../utils'
411
importSR71from'../../utils/network/sr71'
512

6-
//import S from './schema'
13+
importSfrom'./schema'
714

815
constsr71$=newSR71()
916
letsub$=null
@@ -14,13 +21,59 @@ const debug = makeDebugger('L:WikiThread')
1421

1522
letstore=null
1623

17-
exportfunctionsomeMethod(){}
24+
constgetWiki=()=>{
25+
constcommunity=store.curCommunity.raw
26+
27+
sr71$.query(S.wiki,{ community})
28+
}
29+
30+
constsyncWiki=readme=>{
31+
constargs={
32+
readme,
33+
lastSync:newDate().toISOString(),
34+
communityId:store.curCommunity.id,
35+
}
36+
37+
sr71$.mutate(S.syncWiki,args)
38+
}
39+
40+
exportfunctionsyncWikiFromGithub(){
41+
githubApi
42+
.searchWiki('javascript')
43+
.then(res=>{
44+
syncWiki(res)
45+
})
46+
.catch(e=>{
47+
store.handleError(githubApi.parseError(e))
48+
})
49+
}
50+
51+
exportfunctionaddContributor(user){
52+
constargs={
53+
id:store.wikiData.id,
54+
contributor:user,
55+
}
56+
sr71$.mutate(S.addWikiContributor,args)
57+
}
1858

1959
// ###############################
2060
// Data & Error handlers
2161
// ###############################
2262

23-
constDataSolver=[]
63+
constDataSolver=[
64+
{
65+
match:asyncRes('wiki'),
66+
action:({ wiki})=>store.markState({ wiki}),
67+
},
68+
{
69+
match:asyncRes('syncWiki'),
70+
action:()=>getWiki(),
71+
},
72+
{
73+
match:asyncRes('addWikiContributor'),
74+
action:()=>getWiki(),
75+
},
76+
]
2477
constErrSolver=[
2578
{
2679
match:asyncErr(ERR.CRAPHQL),
@@ -43,10 +96,15 @@ const ErrSolver = [
4396
]
4497

4598
exportfunctioninit(_store){
46-
if(store)returnfalse
99+
if(store){
100+
returngetWiki()
101+
}
102+
47103
store=_store
48104

49105
debug(store)
50106
if(sub$)sub$.unsubscribe()
51107
sub$=sr71$.data().subscribe($solver(DataSolver,ErrSolver))
108+
109+
getWiki()
52110
}

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp