better async handling for flag unflag

This commit is contained in:
Bachir Soussi Chiadmi 2020-11-24 15:10:35 +01:00
parent 640085c049
commit c12f72e3fe
2 changed files with 35 additions and 28 deletions

File diff suppressed because one or more lines are too long

View File

@ -224,37 +224,44 @@ export default {
}, },
flag({ dispatch, commit, state }, args) { flag({ dispatch, commit, state }, args) {
console.log("user flag", args.uuid, args.collid); console.log("user flag", args.uuid, args.collid);
const params = { return new Promise((resolve, reject) => {
flagid: state.flagcolls[args.collid].flag_id, const params = {
uuid: args.uuid, flagid: state.flagcolls[args.collid].flag_id,
flagcollid: args.collid uuid: args.uuid,
}; flagcollid: args.collid
return MA.post(`materio_flag/flag`, params) };
.then(({ data }) => { return MA.post(`materio_flag/flag`, params)
console.log("user MA flag", data); .then(({ data }) => {
dispatch('getUserFlagColls') console.log("user MA flag", data);
}) dispatch('getUserFlagColls').then(() =>{
.catch(error => { resolve();
console.warn("Issue USER MA flag", error); });
}); })
.catch(error => {
console.warn("Issue USER MA flag", error);
});
});
}, },
unFlag({ dispatch, commit, state }, args) { unFlag({ dispatch, commit, state }, args) {
console.log("user unFlag", args.uuid, args.collid); console.log("user unFlag", args.uuid, args.collid);
const params = { return new Promise((resolve, reject) => {
flagid: state.flagcolls[args.collid].flag_id, const params = {
uuid: args.uuid, flagid: state.flagcolls[args.collid].flag_id,
flagcollid: args.collid uuid: args.uuid,
}; flagcollid: args.collid
return MA.post(`materio_flag/unflag`, params) };
.then(({ data }) => { return MA.post(`materio_flag/unflag`, params)
console.log("user MA unFlag", data); .then(({ data }) => {
dispatch('getUserFlagColls') console.log("user MA unFlag", data);
}) dispatch('getUserFlagColls').then(() =>{
.catch(error => { resolve();
console.warn("Issue USER MA unFlag", error); });
}); })
.catch(error => {
console.warn("Issue USER MA unFlag", error);
});
});
}, },
userLogout({ commit, state }) { userLogout({ commit, state }) {
const credentials = qs.stringify({ const credentials = qs.stringify({