mirror of
https://github.com/lingble/chatwoot.git
synced 2025-11-20 21:15:01 +00:00
Fixes https://github.com/chatwoot/chatwoot/issues/8436 Fixes https://github.com/chatwoot/chatwoot/issues/9767 Fixes https://github.com/chatwoot/chatwoot/issues/10156 Fixes https://github.com/chatwoot/chatwoot/issues/6031 Fixes https://github.com/chatwoot/chatwoot/issues/5696 Fixes https://github.com/chatwoot/chatwoot/issues/9250 Fixes https://github.com/chatwoot/chatwoot/issues/9762 --------- Co-authored-by: Pranav <pranavrajs@gmail.com> Co-authored-by: Sivin Varghese <64252451+iamsivin@users.noreply.github.com>
56 lines
1.0 KiB
JavaScript
56 lines
1.0 KiB
JavaScript
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,
|
|
};
|