2018-07-10 14:32:48 +02:00
|
|
|
import moment from 'moment';
|
|
|
|
|
2018-06-26 11:39:43 +02:00
|
|
|
import * as api from '@/api';
|
2018-07-10 14:32:48 +02:00
|
|
|
import i18n from '@/i18n';
|
|
|
|
|
|
|
|
import {
|
|
|
|
IS_LOADING,
|
|
|
|
IS_DONE_LOADING,
|
|
|
|
PUSH_REPORT,
|
|
|
|
SET_SETTING,
|
|
|
|
SHOW_REPORT_DETAILS,
|
|
|
|
STORE_REPORTS,
|
|
|
|
} from './mutations-types';
|
2018-06-26 11:39:43 +02:00
|
|
|
|
|
|
|
export function fetchReports({ commit }) {
|
2018-07-04 18:20:28 +02:00
|
|
|
commit(IS_LOADING);
|
2018-07-10 15:55:45 +02:00
|
|
|
return api.getActiveReports()
|
2018-07-04 18:20:28 +02:00
|
|
|
.then(reports => commit(STORE_REPORTS, { reports }))
|
|
|
|
.finally(() => commit(IS_DONE_LOADING));
|
2018-06-26 11:39:43 +02:00
|
|
|
}
|
|
|
|
|
2018-07-05 22:40:24 +02:00
|
|
|
export function downvote({ commit }, id) {
|
|
|
|
return api.downvote(id)
|
|
|
|
.then(report => commit(PUSH_REPORT, { report }));
|
|
|
|
}
|
|
|
|
|
|
|
|
export function upvote({ commit }, id) {
|
|
|
|
return api.upvote(id)
|
|
|
|
.then(report => commit(PUSH_REPORT, { report }));
|
|
|
|
}
|
|
|
|
|
2018-06-26 11:39:43 +02:00
|
|
|
export function saveReport({ commit }, { type, lat, lng }) {
|
2018-07-04 18:20:28 +02:00
|
|
|
commit(IS_LOADING);
|
2018-06-26 11:39:43 +02:00
|
|
|
return api.saveReport(type, lat, lng)
|
2018-07-04 18:20:28 +02:00
|
|
|
.then(report => commit(PUSH_REPORT, { report }))
|
|
|
|
.finally(() => commit(IS_DONE_LOADING));
|
2018-06-26 11:39:43 +02:00
|
|
|
}
|
2018-07-05 22:40:24 +02:00
|
|
|
|
|
|
|
export function showReportDetails({ commit }, id) {
|
|
|
|
return commit(SHOW_REPORT_DETAILS, { id });
|
|
|
|
}
|
2018-07-10 14:32:48 +02:00
|
|
|
|
|
|
|
export function setLocale({ commit }, locale) {
|
|
|
|
// Set global Vue-i18n locale
|
|
|
|
i18n.locale = locale;
|
|
|
|
// Set moment locale
|
|
|
|
moment.locale(locale);
|
|
|
|
// Commit setting into the store
|
|
|
|
return commit(SET_SETTING, { setting: 'locale', value: locale });
|
|
|
|
}
|
|
|
|
|
|
|
|
export function setSetting({ commit }, { setting, value }) {
|
|
|
|
return commit(SET_SETTING, { setting, value });
|
|
|
|
}
|