@@ -4,7 +4,7 @@ import { visitUrl, setUrlParams } from '~/lib/utils/url_utility';
4
4
import { __ } from '~/locale' ;
5
5
import { GROUPS_LOCAL_STORAGE_KEY , PROJECTS_LOCAL_STORAGE_KEY } from './constants' ;
6
6
import * as types from './mutation_types' ;
7
- import { loadDataFromLS , setFrequentItemToLS } from './utils' ;
7
+ import { loadDataFromLS , setFrequentItemToLS , mergeById } from './utils' ;
8
8
9
9
export const fetchGroups = ( { commit } , search ) => {
10
10
commit ( types . REQUEST_GROUPS ) ;
@@ -41,14 +41,30 @@ export const fetchProjects = ({ commit, state }, search) => {
41
41
}
42
42
} ;
43
43
44
- export const loadFrequentGroups = ( { commit } ) => {
44
+ export const loadFrequentGroups = async ( { commit } ) => {
45
45
const data = loadDataFromLS ( GROUPS_LOCAL_STORAGE_KEY ) ;
46
46
commit ( types . LOAD_FREQUENT_ITEMS , { key : GROUPS_LOCAL_STORAGE_KEY , data } ) ;
47
+
48
+ const promises = data . map ( ( d ) => Api . group ( d . id ) ) ;
49
+ try {
50
+ const inflatedData = mergeById ( await Promise . all ( promises ) , data ) ;
51
+ commit ( types . LOAD_FREQUENT_ITEMS , { key : GROUPS_LOCAL_STORAGE_KEY , data : inflatedData } ) ;
52
+ } catch {
53
+ createFlash ( { message : __ ( 'There was a problem fetching recent groups.' ) } ) ;
54
+ }
47
55
} ;
48
56
49
- export const loadFrequentProjects = ( { commit } ) => {
57
+ export const loadFrequentProjects = async ( { commit } ) => {
50
58
const data = loadDataFromLS ( PROJECTS_LOCAL_STORAGE_KEY ) ;
51
59
commit ( types . LOAD_FREQUENT_ITEMS , { key : PROJECTS_LOCAL_STORAGE_KEY , data } ) ;
60
+
61
+ const promises = data . map ( ( d ) => Api . project ( d . id ) . then ( ( res ) => res . data ) ) ;
62
+ try {
63
+ const inflatedData = mergeById ( await Promise . all ( promises ) , data ) ;
64
+ commit ( types . LOAD_FREQUENT_ITEMS , { key : PROJECTS_LOCAL_STORAGE_KEY , data : inflatedData } ) ;
65
+ } catch {
66
+ createFlash ( { message : __ ( 'There was a problem fetching recent projects.' ) } ) ;
67
+ }
52
68
} ;
53
69
54
70
export const setFrequentGroup = ( { state } , item ) => {
0 commit comments