@@ -20,33 +20,6 @@ export const notifyIsFetchingCommit = createAction(Actions.IS_FETCHING_COMMIT);
2020export const fetchedAvatar = createAction < Avatar [ ] > ( Actions . FETCHED_AVATARS ) ;
2121export const fetchedAuthors = createAction < ActionedUser [ ] > ( Actions . FETCHED_AUTHORS ) ;
2222
23- // function buildQueryString(settings: ISettings): string {
24- // if (!settings) {
25- // return '/log';
26- // }
27- // const queryArgs = [];
28- // if (settings.searchText && settings.searchText.length > 0) {
29- // queryArgs.push(`searchText=${encodeURIComponent(settings.searchText)}`);
30- // }
31- // if (settings.pageIndex && settings.pageIndex > 0) {
32- // queryArgs.push(`pageIndex=${settings.pageIndex}`);
33- // }
34- // if (settings.selectedBranchType) {
35- // switch (settings.selectedBranchType) {
36- // case Branch.All: {
37- // queryArgs.push(`branchType=ALL`);
38- // break;
39- // }
40- // case Branch.Current: {
41- // queryArgs.push(`branchType=CURRENT`);
42- // break;
43- // }
44- // }
45- // }
46-
47- // return `/log` + (queryArgs.length === 0 ? '' : `?${queryArgs.join('&')}`);
48- // }
49-
5023function getQueryUrl ( store : RootState , baseUrl : string , args : string [ ] = [ ] ) : string {
5124 const id = store . settings . id || '' ;
5225 const queryArgs = args . concat ( [ `id=${ encodeURIComponent ( id ) } ` ] ) ;
@@ -60,54 +33,13 @@ export const actionACommit = (logEntry: LogEntry) => {
6033 return axios . post ( url , logEntry ) ;
6134 } ;
6235} ;
63- export const fetchAvatar = ( user : ActionedUser ) => {
64- // tslint:disable-next-line:no-any
65- return async ( dispatch : Dispatch < any > , getState : ( ) => RootState ) => {
66- const state = getState ( ) ;
67- const url = getQueryUrl ( state , '/avatar' , [ `name=${ encodeURIComponent ( user . name ) } ` , `email=${ encodeURIComponent ( user . email ) } ` ] ) ;
68- axios . get ( url )
69- . then ( result => {
70- dispatch ( fetchedAvatar ( [ result . data as Avatar ] ) ) ;
71- } )
72- . catch ( err => {
73- // tslint:disable-next-line:no-debugger
74- console . error ( 'Git History: Avatar request failed' ) ;
75- console . error ( err ) ;
76- } ) ;
77- } ;
78- } ;
79- // export const fetchAvatars = (users: ActionedUser[]) => {
80- // // tslint:disable-next-line:no-any
81- // return async (dispatch: Dispatch<any>, getState: () => RootState) => {
82- // const state = getState();
83- // const url = getQueryUrl(state, '/avatar', [`name=${encodeURIComponent(user.name)}`, `email=${encodeURIComponent(user.email)}`]);
84- // axios.get(url)
85- // .then(result => {
86- // dispatch(fetchedAvatar(result.data as Avatar));
87- // })
88- // .catch(err => {
89- // // tslint:disable-next-line:no-debugger
90- // console.error('Git History: Avatar request failed');
91- // console.error(err);
92- // });
93- // };
94- // };
36+
9537// tslint:disable-next-line:no-any
96- export const fetchAvatars = async ( users : ActionedUser [ ] , dispatch : Dispatch < any > , getState : ( ) => RootState ) => {
38+ export const fetchAvatars = async ( dispatch : Dispatch < any > , getState : ( ) => RootState ) => {
9739 const state = getState ( ) ;
98- const unidentifiedUsers = users
99- . filter ( a => ! state . avatars . find ( avatar => avatar . name === a . name && avatar . email === a . email ) )
100- . reduce ( ( accumulator , user ) => {
101- if ( accumulator . findIndex ( item => item . email === user . email && item . name === user . name ) === - 1 ) {
102- accumulator . push ( user ) ;
103- }
104- return accumulator ;
105- } , [ ] ) ;
106- if ( unidentifiedUsers . length === 0 ) {
107- return ;
108- }
10940 const url = getQueryUrl ( state , '/avatars' ) ;
110- axios . post ( url , unidentifiedUsers )
41+
42+ axios . post ( url )
11143 . then ( result => {
11244 dispatch ( fetchedAvatar ( result . data as Avatar [ ] ) ) ;
11345 } )
@@ -270,19 +202,10 @@ function fetchCommits(dispatch: Dispatch<any>, store: RootState, pageIndex?: num
270202 if ( Array . isArray ( result . data . items ) ) {
271203 result . data . items . forEach ( item => {
272204 fixDates ( item ) ;
273- /*if (Array.isArray(item.committedFiles)) {
274- item.committedFiles.forEach(f => {
275- fixFileUri(f.oldUri);
276- fixFileUri(f.uri);
277- });
278- }*/
279205 } ) ;
280206 }
281- //fixFileUri(result.data.file);
282207 dispatch ( addResults ( result . data ) ) ;
283- if ( result . data && Array . isArray ( result . data . items ) && result . data . items . length > 0 ) {
284- fetchAvatars ( result . data . items . map ( item => item . author ) , dispatch , ( ) => store ) ;
285- }
208+ fetchAvatars ( dispatch , ( ) => store ) ;
286209 } )
287210 . catch ( err => {
288211 // tslint:disable-next-line:no-debugger
@@ -298,17 +221,9 @@ function fetchCommit(dispatch: Dispatch<any>, store: RootState, hash: string) {
298221 . then ( ( result : { data : LogEntry } ) => {
299222 if ( result . data ) {
300223 fixDates ( result . data ) ;
301- /*if (Array.isArray(result.data.committedFiles)) {
302- result.data.committedFiles.forEach(f => {
303- fixFileUri(f.oldUri);
304- fixFileUri(f.uri);
305- });
306- }*/
307224 }
308225 dispatch ( updateCommit ( result . data ) ) ;
309- if ( result . data && result . data . author ) {
310- fetchAvatars ( [ result . data . author ] , dispatch , ( ) => store ) ;
311- }
226+ fetchAvatars ( dispatch , ( ) => store ) ;
312227 } )
313228 . catch ( err => {
314229 // tslint:disable-next-line:no-debugger
0 commit comments