Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
Vuex Module
import axios from 'axios'
import Ls from '@services/ls'
import router from '@router'
export const sitename_axios = axios.create({
headers: { 'Content-Type': 'application/json'},
timeout: 3000,
keepAlive: true
})
let endpoint = 'http://localhost/api/';
let global_register_clientId= '',
global_register_secret = '',
global_login_clientId = '',
global_login_secret = '';
if(process.env.NODE_ENV === 'development'){
global_register_clientId = "testclient"
global_register_secret = "testsecret"
global_login_clientId = "testclient"
global_login_secret = "testsecret"
}else{
global_register_clientId = "somethingelse"
global_register_secret = "somethingelse"
global_login_clientId = "somethingelse"
global_login_secret = "somethingelse"
}
const state = {
scheduled_posts: ''
}
const mutations = {
SET_SCHEDULED_POSTS (state,data) {
state.scheduled_posts = data
},
RESET(state){
state.scheduled_posts = ''
},
}
const actions = {
reset({commit}){
commit('RESET');
},
get_scheduled_posts({commit, dispatch, getters}) {
// Call reset messages from root
dispatch('auth/clear_errors', {}, {root:true})
let current_api = endpoint+ 'me/scheduled-sharing'
let current_user_access_token = getSavedState('auth.access_token')
return sitename_axios.get(current_api,
{
headers: {
Authorization: 'Bearer '+current_user_access_token
}
})
.then((response) => {
commit('SET_SCHEDULED_POSTS', response.data);
}).catch((error) => {
// Get current error code
let current_error_code = error.response.data.code
// Check for error translation
dispatch('auth/get_error_handler', error.response.data.code, {root:true})
})
},
get_scheduled_posts_by_language({commit, dispatch}, language) {
// Call reset messages from root
dispatch('auth/clear_errors', {}, {root:true})
let current_api = endpoint+ 'me/scheduled-sharing?lang='+ language
let current_user_access_token = getSavedState('auth.access_token')
return sitename_axios.get(current_api+'',
{
headers: {
Authorization: 'Bearer '+current_user_access_token
}
})
.then((response) => {
commit('SET_SCHEDULED_POSTS', response.data);
}).catch((error) => {
// Get current error code
let current_error_code = error.response.data.code
// Check for error translation
dispatch('auth/get_error_handler', error.response.data.code, {root:true})
})
},
get_scheduled_posts_by_page({commit, dispatch}, pageNumb) {
console.log(pageNumb)
// Call reset messages from root
dispatch('auth/clear_errors', {}, {root:true})
let current_api = endpoint+ 'me/scheduled-sharing?page='+ pageNumb
let current_user_access_token = getSavedState('auth.access_token')
return sitename_axios.get(current_api+'',
{
headers: {
Authorization: 'Bearer '+current_user_access_token
}
})
.then((response) => {
commit('SET_SCHEDULED_POSTS', response.data);
}).catch((error) => {
// Get current error code
let current_error_code = error.response.data.code
// Check for error translation
dispatch('auth/get_error_handler', error.response.data.code, {root:true})
})
},
}
const getters = {
// This getter is a computed property that is used to get page alerts inside pages.
get_current_scheduled_posts(state){
return JSON.parse(JSON.stringify(state.scheduled_posts))
},
};
// ===
// Private helpers
// ===
function getSavedState(key) {
return Ls.get(key);
}
function saveState(key, state) {
Ls.set(key,state);
}
function removeState(key) {
Ls.remove(key);
}
export default {
namespaced : true,
state, mutations, actions, getters
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.