@@ -10,13 +10,14 @@ import {
10
10
TYPE ,
11
11
EVENT ,
12
12
errRescue ,
13
+ githubApi ,
13
14
} from '@utils'
14
15
15
16
import SR71 from '@utils/async/sr71'
16
17
import S from './schema'
17
18
18
19
const sr71$ = new SR71 ( {
19
- resv_event :[ EVENT . PREVIEW_CLOSED ] ,
20
+ resv_event :[ EVENT . PREVIEW_CLOSED , EVENT . SYNC_REPO ] ,
20
21
} )
21
22
22
23
let sub$ = null
@@ -55,6 +56,28 @@ const DataSolver = [
55
56
store . setViewing ( { repo :R . merge ( store . viewingData , repo ) } )
56
57
} ,
57
58
} ,
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
+ } ,
58
81
]
59
82
const ErrSolver = [
60
83
{
@@ -82,19 +105,16 @@ export const holder = 1
82
105
// init & uninit
83
106
// ###############################
84
107
export const useInit = ( _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 )
91
113
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 ] )
100
120
}