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-21 20:00:37 +02:00
|
|
|
import * as constants from '@/constants';
|
2018-07-10 14:32:48 +02:00
|
|
|
import i18n from '@/i18n';
|
|
|
|
|
|
|
|
import {
|
2018-07-17 16:37:46 +02:00
|
|
|
INTRO_WAS_SEEN,
|
2018-08-01 11:35:49 +02:00
|
|
|
INTRO_WAS_UNSEEN,
|
2018-07-10 14:32:48 +02:00
|
|
|
IS_DONE_LOADING,
|
2018-07-21 20:00:37 +02:00
|
|
|
IS_LOADING,
|
2018-07-10 14:32:48 +02:00
|
|
|
PUSH_REPORT,
|
2018-07-26 09:05:22 +02:00
|
|
|
PUSH_UNSENT_REPORT,
|
2018-07-26 13:55:08 +02:00
|
|
|
REMOVE_UNSENT_REPORT,
|
2018-07-21 20:00:37 +02:00
|
|
|
SET_CURRENT_MAP_CENTER,
|
|
|
|
SET_CURRENT_MAP_ZOOM,
|
|
|
|
SET_CURRENT_POSITION,
|
|
|
|
SET_LOCATION_ERROR,
|
|
|
|
SET_LOCATION_WATCHER_ID,
|
2018-07-10 14:32:48 +02:00
|
|
|
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-08-01 19:29:39 +02:00
|
|
|
.then((reports) => {
|
|
|
|
commit(STORE_REPORTS, { reports });
|
|
|
|
commit(IS_DONE_LOADING);
|
|
|
|
})
|
2018-08-02 10:49:47 +02:00
|
|
|
.catch((exc) => {
|
|
|
|
commit(IS_DONE_LOADING);
|
|
|
|
throw exc;
|
|
|
|
});
|
2018-06-26 11:39:43 +02:00
|
|
|
}
|
|
|
|
|
2018-07-12 17:48:26 +02:00
|
|
|
export function downvote({ commit }, { id }) {
|
2018-07-30 20:35:52 +02:00
|
|
|
// Hide details
|
|
|
|
commit(SHOW_REPORT_DETAILS, { id: null, userAsked: null });
|
2018-07-05 22:40:24 +02:00
|
|
|
return api.downvote(id)
|
|
|
|
.then(report => commit(PUSH_REPORT, { report }));
|
|
|
|
}
|
|
|
|
|
2018-07-12 17:48:26 +02:00
|
|
|
export function upvote({ commit }, { id }) {
|
2018-07-30 20:35:52 +02:00
|
|
|
// Hide details
|
|
|
|
commit(SHOW_REPORT_DETAILS, { id: null, userAsked: null });
|
2018-07-05 22:40:24 +02:00
|
|
|
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-08-01 19:29:39 +02:00
|
|
|
.then((report) => {
|
|
|
|
commit(PUSH_REPORT, { report });
|
|
|
|
commit(IS_DONE_LOADING);
|
|
|
|
})
|
2018-08-02 10:49:47 +02:00
|
|
|
.catch((exc) => {
|
|
|
|
commit(IS_DONE_LOADING);
|
|
|
|
throw exc;
|
|
|
|
});
|
2018-06-26 11:39:43 +02:00
|
|
|
}
|
2018-07-05 22:40:24 +02:00
|
|
|
|
2018-07-26 09:05:22 +02:00
|
|
|
export function saveUnsentReport({ commit }, { report }) {
|
|
|
|
commit(PUSH_UNSENT_REPORT, { report });
|
|
|
|
}
|
|
|
|
|
2018-07-26 13:55:08 +02:00
|
|
|
export function removeUnsentReport({ commit }, { index }) {
|
|
|
|
commit(REMOVE_UNSENT_REPORT, { index });
|
|
|
|
}
|
|
|
|
|
2018-07-12 17:48:26 +02:00
|
|
|
export function hideReportDetails({ commit }) {
|
|
|
|
return commit(SHOW_REPORT_DETAILS, { id: null, userAsked: null });
|
2018-07-05 22:40:24 +02:00
|
|
|
}
|
2018-07-10 14:32:48 +02:00
|
|
|
|
2018-07-12 17:48:26 +02:00
|
|
|
export function showReportDetails({ commit }, { id, userAsked }) {
|
|
|
|
return commit(SHOW_REPORT_DETAILS, { id, userAsked });
|
|
|
|
}
|
|
|
|
|
|
|
|
export function setLocale({ commit }, { locale }) {
|
2018-07-10 14:32:48 +02:00
|
|
|
// 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 });
|
|
|
|
}
|
2018-07-17 16:37:46 +02:00
|
|
|
|
|
|
|
export function markIntroAsSeen({ commit }) {
|
|
|
|
return commit(INTRO_WAS_SEEN);
|
|
|
|
}
|
2018-07-21 20:00:37 +02:00
|
|
|
|
2018-08-01 11:35:49 +02:00
|
|
|
export function unmarkIntroAsSeen({ commit }) {
|
|
|
|
return commit(INTRO_WAS_UNSEEN);
|
|
|
|
}
|
|
|
|
|
2018-07-21 20:00:37 +02:00
|
|
|
export function setCurrentMapCenter({ commit, state }, { center }) {
|
|
|
|
if (state.map.center.some((item, index) => item !== center[index])) {
|
|
|
|
commit(SET_CURRENT_MAP_CENTER, { center });
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
export function setCurrentMapZoom({ commit, state }, { zoom }) {
|
|
|
|
if (state.map.zoom !== zoom) {
|
|
|
|
commit(SET_CURRENT_MAP_ZOOM, { zoom });
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
export function setCurrentPosition(
|
2018-08-05 15:47:28 +02:00
|
|
|
{ commit },
|
2018-08-02 16:58:08 +02:00
|
|
|
{ coords, timestamp },
|
2018-07-21 20:00:37 +02:00
|
|
|
) {
|
2018-08-02 16:58:08 +02:00
|
|
|
const currentLocation = {
|
|
|
|
latitude: coords.latitude,
|
|
|
|
longitude: coords.longitude,
|
|
|
|
hdop: coords.accuracy ? coords.accuracy : null,
|
|
|
|
elevation: coords.elevation ? coords.elevation : null,
|
|
|
|
vdop: coords.altitudeAccuracy ? coords.altitudeAccuracy : null,
|
|
|
|
heading: (
|
2018-08-05 15:47:28 +02:00
|
|
|
(coords.heading !== null && !Number.isNaN(coords.heading))
|
|
|
|
? coords.heading
|
|
|
|
: null
|
2018-08-02 16:58:08 +02:00
|
|
|
),
|
|
|
|
speed: coords.speed ? coords.speed : null,
|
|
|
|
timestamp,
|
|
|
|
};
|
|
|
|
|
|
|
|
commit(SET_CURRENT_POSITION, { currentLocation });
|
2018-07-21 20:00:37 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
export function setLocationWatcherId({ commit }, { id }) {
|
|
|
|
return commit(SET_LOCATION_WATCHER_ID, { id });
|
|
|
|
}
|
|
|
|
|
|
|
|
export function setLocationError({ commit, state }, { error }) {
|
|
|
|
// Unregister location watcher
|
2018-08-05 15:47:28 +02:00
|
|
|
const { watcherID } = state.location;
|
2018-07-21 20:00:37 +02:00
|
|
|
if (watcherID !== null) {
|
|
|
|
if (constants.MOCK_LOCATION) {
|
|
|
|
clearInterval(watcherID);
|
|
|
|
} else {
|
|
|
|
navigator.geolocation.clearWatch(watcherID);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
commit(SET_LOCATION_WATCHER_ID, { id: null });
|
|
|
|
commit(SET_LOCATION_ERROR, { error });
|
|
|
|
}
|