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.

Commita456568

Browse files
committed
fix(repoViewer): add sync from github repo,closes#498
1 parent8e54f8f commita456568

File tree

11 files changed

+167
-63
lines changed

11 files changed

+167
-63
lines changed

‎components/ArticleActionsPanel/EditOption.js‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ const EditOption = ({ thread, onEdit }) => (
1212
<OptiononClick={onEdit.bind(this,thread)}>
1313
<OptionIconsrc={`${ICON_CMD}/edit.svg`}/>
1414
{thread===THREAD.REPO ?(
15-
<OptionTitle>更新 README.md</OptionTitle>
15+
<OptionTitle>同步仓库信息</OptionTitle>
1616
) :(
1717
<OptionTitle>编辑</OptionTitle>
1818
)}

‎containers/ArticleBodyHeader/logic.js‎

Lines changed: 12 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -39,8 +39,7 @@ export const onEdit = thread => {
3939
break
4040

4141
caseTHREAD.REPO:
42-
type=TYPE.PREVIEW_REPO_EDIT
43-
break
42+
returndispatchEvent(EVENT.SYNC_REPO)
4443

4544
default:{
4645
type=TYPE.PREVIEW_POST_EDIT
@@ -268,18 +267,15 @@ const ErrSolver = [
268267
// init & uninit
269268
// ###############################
270269
exportconstuseInit=_store=>{
271-
useEffect(
272-
()=>{
273-
store=_store
274-
// log('effect init')
275-
sub$=sr71$.data().subscribe($solver(DataSolver,ErrSolver))
276-
277-
return()=>{
278-
// log('effect uninit')
279-
sr71$.stop()
280-
sub$.unsubscribe()
281-
}
282-
},
283-
[_store]
284-
)
270+
useEffect(()=>{
271+
store=_store
272+
// log('effect init')
273+
sub$=sr71$.data().subscribe($solver(DataSolver,ErrSolver))
274+
275+
return()=>{
276+
// log('effect uninit')
277+
sr71$.stop()
278+
sub$.unsubscribe()
279+
}
280+
},[_store])
285281
}

‎containers/ArticleViewerHeader/LastSyncInfo.js‎

Lines changed: 27 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -14,29 +14,33 @@ import {
1414
Divider,
1515
}from'./styles/reaction'
1616

17-
constLastSyncInfo=({ show, data})=>(
18-
<Maybetest={show}>
19-
<Popover
20-
placement="bottomLeft"
21-
trigger="hover"
22-
content={<PopInfo>上次与该 Github repo 同步的时间</PopInfo>}
23-
>
24-
<Reaction>
25-
<Divider/>
26-
<PlainAction>
27-
<ReactionName>同步于:</ReactionName>
28-
</PlainAction>
29-
<SyncTime>
30-
{data.lastSync ?(
31-
<TimeAgodatetime={data.lastSync}locale="zh_CN"/>
32-
) :(
33-
'--'
34-
)}
35-
</SyncTime>
36-
</Reaction>
37-
</Popover>
38-
</Maybe>
39-
)
17+
constLastSyncInfo=({ show, data})=>{
18+
constlastSyncTime=data.lastSync||data.updatedAt||null
19+
20+
return(
21+
<Maybetest={show}>
22+
<Popover
23+
placement="bottomLeft"
24+
trigger="hover"
25+
content={<PopInfo>上次与该 Github repo 同步的时间</PopInfo>}
26+
>
27+
<Reaction>
28+
<Divider/>
29+
<PlainAction>
30+
<ReactionName>同步于:</ReactionName>
31+
</PlainAction>
32+
<SyncTime>
33+
{lastSyncTime ?(
34+
<TimeAgodatetime={lastSyncTime}locale="zh_CN"/>
35+
) :(
36+
'--'
37+
)}
38+
</SyncTime>
39+
</Reaction>
40+
</Popover>
41+
</Maybe>
42+
)
43+
}
4044

4145
LastSyncInfo.propTypes={
4246
data:T.shape({

‎containers/Preview/Viewer.js‎

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -70,9 +70,6 @@ const Viewer = ({ type, root, attachment, attUser }) => {
7070
caseTYPE.PREVIEW_REPO_CREATE:
7171
return<DynamicRepoEditor/>
7272

73-
caseTYPE.PREVIEW_REPO_EDIT:
74-
return<DynamicRepoEditor/>
75-
7673
// video
7774
caseTYPE.PREVIEW_VIDEO_EDIT:
7875
return<DynamicVideoEditorattachment={attachment}/>

‎containers/Preview/store.js‎

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,6 @@ const THREAD_CONTENT_CURD_TYPES = [
3232
// repo
3333
TYPE.PREVIEW_REPO_VIEW,
3434
TYPE.PREVIEW_REPO_CREATE,
35-
TYPE.PREVIEW_REPO_EDIT,
3635
// video
3736
TYPE.PREVIEW_VIDEO_VIEW,
3837
TYPE.PREVIEW_VIDEO_CREATE,

‎containers/RepoEditor/store.js‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -64,7 +64,7 @@ const RepoEditor = t
6464
caseERR.AUTH:
6565
returnself.changesetErr({
6666
title:'Github 鉴权出错',
67-
msg:'token 可能过期,请尝试重新登录',
67+
msg:'Githubtoken 可能过期,请重试或重新设置 Github Token',
6868
})
6969

7070
caseERR.TIMEOUT:

‎containers/RepoViewer/index.js‎

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@ const log = buildLog('C:RepoViewer')
2323
constRepoViewerContainer=({ repoViewer, attachment})=>{
2424
useInit(repoViewer,attachment)
2525

26-
const{ curCommunity, viewingData}=repoViewer
26+
const{ curCommunity, viewingData, loading}=repoViewer
2727

2828
return(
2929
<React.Fragment>
@@ -47,6 +47,7 @@ const RepoViewerContainer = ({ repoViewer, attachment }) => {
4747
middle="labeler"
4848
/>
4949
}
50+
updating={loading}
5051
/>
5152
<CommentsWrapper>
5253
<Comments/>

‎containers/RepoViewer/logic.js‎

Lines changed: 35 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -10,13 +10,14 @@ import {
1010
TYPE,
1111
EVENT,
1212
errRescue,
13+
githubApi,
1314
}from'@utils'
1415

1516
importSR71from'@utils/async/sr71'
1617
importSfrom'./schema'
1718

1819
constsr71$=newSR71({
19-
resv_event:[EVENT.PREVIEW_CLOSED],
20+
resv_event:[EVENT.PREVIEW_CLOSED,EVENT.SYNC_REPO],
2021
})
2122

2223
letsub$=null
@@ -55,6 +56,28 @@ const DataSolver = [
5556
store.setViewing({repo:R.merge(store.viewingData,repo)})
5657
},
5758
},
59+
{
60+
match:asyncRes('updateRepo'),
61+
action:({ updateRepo})=>{
62+
markLoading(false)
63+
store.setViewing({repo:R.merge(store.viewingData,updateRepo)})
64+
},
65+
},
66+
{
67+
match:asyncRes(EVENT.SYNC_REPO),
68+
action:()=>{
69+
markLoading(true)
70+
log('should sync repo: ',store.viewingData)
71+
const{ id, ownerName, title}=store.viewingData
72+
73+
githubApi
74+
.searchRepo(ownerName,title)
75+
.then(res=>
76+
sr71$.mutate(S.updateRepo,{ id, ...githubApi.transformRepo(res)})
77+
)
78+
.catch(e=>store.handleError(githubApi.parseError(e)))
79+
},
80+
},
5881
]
5982
constErrSolver=[
6083
{
@@ -82,19 +105,16 @@ export const holder = 1
82105
// init & uninit
83106
// ###############################
84107
exportconstuseInit=(_store,attachment)=>{
85-
useEffect(
86-
()=>{
87-
store=_store
88-
// log('effect init')
89-
sub$=sr71$.data().subscribe($solver(DataSolver,ErrSolver))
90-
openAttachment(attachment)
108+
useEffect(()=>{
109+
store=_store
110+
// log('effect init')
111+
sub$=sr71$.data().subscribe($solver(DataSolver,ErrSolver))
112+
openAttachment(attachment)
91113

92-
return()=>{
93-
// log('effect uninit')
94-
sr71$.stop()
95-
sub$.unsubscribe()
96-
}
97-
},
98-
[_store,attachment]
99-
)
114+
return()=>{
115+
// log('effect uninit')
116+
sr71$.stop()
117+
sub$.unsubscribe()
118+
}
119+
},[_store,attachment])
100120
}

‎containers/RepoViewer/schema.js‎

Lines changed: 56 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,12 +25,68 @@ const repo = gql`
2525
author {
2626
${F.author}
2727
}
28+
updatedAt
29+
}
30+
}
31+
`
32+
33+
constupdateRepo=gql`
34+
mutation(
35+
$id: ID!
36+
$title: String
37+
$ownerName: String
38+
$ownerUrl: String
39+
$repoUrl: String
40+
$desc: String
41+
$homepageUrl: String
42+
$readme: String
43+
$starCount: Int
44+
$issuesCount: Int
45+
$prsCount: Int
46+
$forkCount: Int
47+
$watchCount: Int
48+
$license: String
49+
$releaseTag: String
50+
$primaryLanguage: RepoLangInput
51+
$contributors: [RepoContributorInput]
52+
) {
53+
updateRepo(
54+
id: $id
55+
title: $title
56+
ownerName: $ownerName
57+
ownerUrl: $ownerUrl
58+
repoUrl: $repoUrl
59+
desc: $desc
60+
homepageUrl: $homepageUrl
61+
readme: $readme
62+
starCount: $starCount
63+
issuesCount: $issuesCount
64+
prsCount: $prsCount
65+
forkCount: $forkCount
66+
watchCount: $watchCount
67+
primaryLanguage: $primaryLanguage
68+
license: $license
69+
releaseTag: $releaseTag
70+
contributors: $contributors
71+
) {
72+
${F.repo}
73+
watchCount
74+
ownerUrl
75+
repoUrl
76+
homepageUrl
77+
readme
78+
issuesCount
79+
releaseTag
80+
lastSync
81+
favoritedCount
82+
updatedAt
2883
}
2984
}
3085
`
3186

3287
constschema={
3388
repo,
89+
updateRepo,
3490
}
3591

3692
exportdefaultschema

‎containers/RepoViewer/store.js‎

Lines changed: 31 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66
import{typesast,getParent}from'mobx-state-tree'
77
// import R from 'ramda'
88

9-
import{markStates,buildLog,stripMobx}from'@utils'
9+
import{markStates,buildLog,stripMobx,ERR}from'@utils'
1010
/* eslint-disable-next-line */
1111
constlog=buildLog('S:RepoViewer')
1212

@@ -32,6 +32,36 @@ const RepoViewer = t
3232
setViewing(sobj){
3333
self.root.setViewing(sobj)
3434
},
35+
changesetErr(options){
36+
self.root.changesetErr(options)
37+
},
38+
handleError(errorType){
39+
log(errorType)
40+
self.markState({ errorType,loading:false})
41+
switch(errorType){
42+
caseERR.NOT_FOUND:
43+
returnself.changesetErr({
44+
title:'仓库未找到',
45+
msg:'请确认输入的仓库地址',
46+
})
47+
48+
caseERR.AUTH:
49+
returnself.changesetErr({
50+
title:'Github 鉴权出错',
51+
msg:'Github token 可能过期,请重试或重新设置 Github Token',
52+
})
53+
54+
caseERR.TIMEOUT:
55+
returnself.changesetErr({
56+
title:'Github 超时',
57+
msg:'特殊国情,请稍后重试',
58+
})
59+
60+
default:{
61+
returnself.changesetErr({title:'未知错误',msg:'...'})
62+
}
63+
}
64+
},
3565
markState(sobj){
3666
markStates(sobj,self)
3767
},

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp