Migrate widgetPortalArticlesToPinia
This commit is contained in:
@@ -10,7 +10,6 @@ import events from 'widget/store/modules/events';
|
||||
import globalConfig from 'shared/store/globalConfig';
|
||||
import message from 'widget/store/modules/message';
|
||||
import campaign from 'widget/store/modules/campaign';
|
||||
import article from 'widget/store/modules/articles';
|
||||
|
||||
export default createStore({
|
||||
modules: {
|
||||
@@ -24,6 +23,5 @@ export default createStore({
|
||||
globalConfig,
|
||||
message,
|
||||
campaign,
|
||||
article,
|
||||
},
|
||||
});
|
||||
|
||||
@@ -1,55 +0,0 @@
|
||||
import { getMostReadArticles } from 'widget/api/article';
|
||||
|
||||
const state = {
|
||||
records: [],
|
||||
uiFlags: {
|
||||
isError: false,
|
||||
hasFetched: false,
|
||||
isFetching: false,
|
||||
},
|
||||
};
|
||||
|
||||
export const getters = {
|
||||
uiFlags: $state => $state.uiFlags,
|
||||
popularArticles: $state => $state.records,
|
||||
};
|
||||
|
||||
export const actions = {
|
||||
fetch: async ({ commit }, { slug, locale }) => {
|
||||
commit('setIsFetching', true);
|
||||
commit('setError', false);
|
||||
|
||||
try {
|
||||
const { data } = await getMostReadArticles(slug, locale);
|
||||
const { payload = [] } = data;
|
||||
|
||||
if (payload.length) {
|
||||
commit('setArticles', payload);
|
||||
}
|
||||
} catch (error) {
|
||||
commit('setError', true);
|
||||
} finally {
|
||||
commit('setIsFetching', false);
|
||||
}
|
||||
},
|
||||
};
|
||||
|
||||
export const mutations = {
|
||||
setArticles($state, data) {
|
||||
$state.records = data;
|
||||
},
|
||||
setError($state, value) {
|
||||
$state.uiFlags.isError = value;
|
||||
},
|
||||
setIsFetching($state, value) {
|
||||
$state.uiFlags.isFetching = value;
|
||||
},
|
||||
};
|
||||
|
||||
export default {
|
||||
namespaced: true,
|
||||
state,
|
||||
getters,
|
||||
actions,
|
||||
mutations,
|
||||
};
|
||||
Reference in New Issue
Block a user