11import { autoEffect , clearEffect , store } from '@risingstack/react-easy-state' ;
22import { IMRWebViewDetail } from 'src/typings/commonTypes' ;
33import { IActivity , IReviewer , IComment } from 'src/typings/respResult' ;
4- import { getMessageHandler } from 'webviews/utils/message' ;
54import { vscode } from 'webviews/constants/vscode' ;
65import { actions } from 'webviews/store/constants' ;
76import { MERGE_STATUS } from 'webviews/constants/mergeRequest' ;
@@ -31,19 +30,22 @@ const appStore = store({
3130 updateMRComments ( data : IComment [ ] ) {
3231 appStore . comments = data ;
3332 } ,
33+ toggleMRLoading ( ) {
34+ appStore . currentMR . data . loading = ! appStore . currentMR . data . loading ;
35+ } ,
3436 updateMRStatus ( status : MERGE_STATUS ) {
3537 appStore . currentMR . data . merge_request . merge_status = status ;
3638 } ,
3739 async refetchMRActivities ( ) {
38- const result = await messageHandler . postMessage ( {
40+ const result = await vscode . postMessage ( {
3941 command : actions . MR_GET_ACTIVITIES ,
4042 args : appStore . currentMR . iid ,
4143 } ) ;
4244 appStore . activities = result ;
4345 return result ;
4446 } ,
4547 async closeMR ( ) {
46- const result = await messageHandler . postMessage ( {
48+ const result = await vscode . postMessage ( {
4749 command : actions . CLOSE_MR ,
4850 args : appStore . currentMR . iid ,
4951 } ) ;
@@ -52,7 +54,7 @@ const appStore = store({
5254 return result ;
5355 } ,
5456 async approveMR ( ) {
55- const result = await messageHandler . postMessage ( {
57+ const result = await vscode . postMessage ( {
5658 command : actions . MR_APPROVE ,
5759 args : appStore . currentMR . iid ,
5860 } ) ;
@@ -66,7 +68,7 @@ const appStore = store({
6668 return result ;
6769 } ,
6870 async disapproveMR ( ) {
69- const result = await messageHandler . postMessage ( {
71+ const result = await vscode . postMessage ( {
7072 command : actions . MR_DISAPPROVE ,
7173 args : appStore . currentMR . iid ,
7274 } ) ;
@@ -80,7 +82,7 @@ const appStore = store({
8082 return result ;
8183 } ,
8284 async mergeMR ( ) {
83- const result = await messageHandler . postMessage ( {
85+ const result = await vscode . postMessage ( {
8486 command : actions . MR_MERGE ,
8587 args : appStore . currentMR . iid ,
8688 } ) ;
@@ -89,7 +91,7 @@ const appStore = store({
8991 return result ;
9092 } ,
9193 async updateMRTitle ( newTitle : string ) {
92- const result = await messageHandler . postMessage ( {
94+ const result = await vscode . postMessage ( {
9395 command : actions . MR_UPDATE_TITLE ,
9496 args : {
9597 iid : appStore . currentMR . iid ,
@@ -101,7 +103,7 @@ const appStore = store({
101103 return result ;
102104 } ,
103105 async commentMR ( comment : string ) {
104- const result = await messageHandler . postMessage ( {
106+ const result = await vscode . postMessage ( {
105107 command : actions . MR_ADD_COMMENT ,
106108 args : {
107109 id : appStore . currentMR . data . merge_request . id ,
@@ -125,32 +127,4 @@ export const persistData = () =>
125127 } ) ;
126128export const removeDataPersist = ( e : ( ) => void ) => clearEffect ( e ) ;
127129
128- // handle broadcast message
129- export const messageHandler = getMessageHandler ( ( message : any ) => {
130- if ( ! message ) return ;
131- const { updateCurrentMR, updateMRActivities, updateMRReviewers, updateMRComments } = appStore ;
132- const { command, res } = message ;
133-
134- switch ( command ) {
135- case actions . UPDATE_CURRENT_MR : {
136- updateCurrentMR ( res ) ;
137- break ;
138- }
139- case actions . UPDATE_MR_ACTIVITIES : {
140- updateMRActivities ( res ) ;
141- break ;
142- }
143- case actions . UPDATE_MR_REVIEWERS : {
144- updateMRReviewers ( res ) ;
145- break ;
146- }
147- case actions . MR_UPDATE_COMMENTS : {
148- updateMRComments ( res ) ;
149- break ;
150- }
151- default :
152- break ;
153- }
154- } ) ;
155-
156130export default appStore ;
0 commit comments