@@ -10,13 +10,14 @@ import {
1010 TYPE ,
1111 EVENT ,
1212 errRescue ,
13+ githubApi ,
1314} from '@utils'
1415
1516import SR71 from '@utils/async/sr71'
1617import S from './schema'
1718
1819const sr71$ = new SR71 ( {
19- resv_event : [ EVENT . PREVIEW_CLOSED ] ,
20+ resv_event : [ EVENT . PREVIEW_CLOSED , EVENT . SYNC_REPO ] ,
2021} )
2122
2223let sub$ = 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]
5982const ErrSolver = [
6083 {
@@ -82,19 +105,16 @@ export const holder = 1
82105// init & uninit
83106// ###############################
84107export 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 )
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}
0 commit comments