import NewsService from "@/services/NewsService"; export const state = () => ({ newsItem: {}, categoryNewsList: [], indexNewsList: {}, categoriesList: [], newsFeedList: [], stories: [] }); export const mutations = { SET_NEWS_ITEM(state, newsItem) { state.newsItem = newsItem; }, SET_CATEGORY_NEWS_LIST(state, categoryNewsList) { state.categoryNewsList = categoryNewsList; }, SET_INDEX_NEWS_LIST(state, indexNewsList) { state.indexNewsList = indexNewsList }, SET_CATEGORIES_LIST(state, categoriesList) { state.categoriesList = categoriesList }, LOAD_NEWS(state, newsList) { const oldNewsList = state.categoryNewsList.news const newCategoryNewsList = oldNewsList.concat(newsList.news) state.categoryNewsList.news = newCategoryNewsList }, SET_STORIES(state, stories) { state.stories = stories }, SET_NEWS_FEED_LIST(state, stories) { state.newsFeedList = stories } }; export const actions = { loadCategoryNews({commit}, params,) { return NewsService.getCategoryNewsList(params) .then((categoryNewsList) => { commit("LOAD_NEWS", categoryNewsList) }) }, setCategoriesList({commit}) { return NewsService.getCategoriesList().then(list => { commit("SET_CATEGORIES_LIST", list) }) }, setNewsItem({commit}, params) { return NewsService.getNewsItem(params) .then((newsItem) => { commit("SET_NEWS_ITEM", newsItem) }) }, setCategoryNewsList({commit}, params) { return NewsService.getCategoryNewsList(params) .then((categoryNewsList) => { commit("SET_CATEGORY_NEWS_LIST", categoryNewsList) //console.log(categoryNewsList) return categoryNewsList }) }, setIndexNewsList({commit}) { return NewsService.getIndexNewsList() .then((indexNewsList) => { commit("SET_INDEX_NEWS_LIST", indexNewsList) }) }, setStories({commit, $axios}) { return NewsService.getStories().then(res => { commit("SET_STORIES", res) return res }) }, getNewsFeedList({ commit }) { return NewsService.getNewsFeedList() .then((newsFeedList) => { commit("SET_NEWS_FEED_LIST", newsFeedList) return newsFeedList }) }, }; export const getters = { newsItem: state => state.newsItem, indexNewsList: state => state.indexNewsList, categoryNewsList: state => state.categoryNewsList, categoriesList: state => state.categoriesList, stories: state => state.stories, newsFeedList: state => state.newsFeedList }; export default { namespaced: true, state, getters, actions, mutations }