mirror of https://github.com/micromata/borgbackup-butler.git

Kai Reinhard
09.43.2018 1a21e0d3baca3870611a1fe712027a559d9a4b93
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
import {VERSION_RELOAD_FAILED, VERSION_RELOADED, VERSION_REQUEST_RELOAD} from './types';
import {getRestServiceUrl} from '../utilities/global';
 
const requestedVersionReload = () => ({
    type: VERSION_REQUEST_RELOAD
});
 
const reloadedVersion = (json) => ({
    type: VERSION_RELOADED,
    payload: {
        version: json.version,
        language: json.language,
        buildDate: json.buildDate,
        updateVersion: json.updateVersion
    }
});
 
const failedReload = () => ({
    type: VERSION_RELOAD_FAILED
});
 
export const loadVersion = () => (dispatch, getState) => {
    if (getState().version.loading) {
        return;
    }
 
    dispatch(requestedVersionReload());
 
    fetch(getRestServiceUrl('version'), {
        method: 'GET',
        headers: {
            'Content-Type': 'application/json'
        }
    })
        .then(response => response.json())
        .then(json => dispatch(reloadedVersion(json)))
        .catch(() => dispatch(failedReload()));
};