Browse Source

Blah.

webui
Stian Aune 5 years ago
parent
commit
83052a2ab8
  1. 41
      webui/package-lock.json
  2. 10
      webui/src/Actions/authActions.js
  3. 13
      webui/src/Actions/lightActions.js
  4. 57
      webui/src/Helpers/fetcher.js
  5. 21
      webui/src/Reducers/lightReducer.js

41
webui/package-lock.json

@ -5470,7 +5470,8 @@
}, },
"ansi-regex": { "ansi-regex": {
"version": "2.1.1", "version": "2.1.1",
"bundled": true
"bundled": true,
"optional": true
}, },
"aproba": { "aproba": {
"version": "1.2.0", "version": "1.2.0",
@ -5488,11 +5489,13 @@
}, },
"balanced-match": { "balanced-match": {
"version": "1.0.0", "version": "1.0.0",
"bundled": true
"bundled": true,
"optional": true
}, },
"brace-expansion": { "brace-expansion": {
"version": "1.1.11", "version": "1.1.11",
"bundled": true, "bundled": true,
"optional": true,
"requires": { "requires": {
"balanced-match": "^1.0.0", "balanced-match": "^1.0.0",
"concat-map": "0.0.1" "concat-map": "0.0.1"
@ -5505,15 +5508,18 @@
}, },
"code-point-at": { "code-point-at": {
"version": "1.1.0", "version": "1.1.0",
"bundled": true
"bundled": true,
"optional": true
}, },
"concat-map": { "concat-map": {
"version": "0.0.1", "version": "0.0.1",
"bundled": true
"bundled": true,
"optional": true
}, },
"console-control-strings": { "console-control-strings": {
"version": "1.1.0", "version": "1.1.0",
"bundled": true
"bundled": true,
"optional": true
}, },
"core-util-is": { "core-util-is": {
"version": "1.0.2", "version": "1.0.2",
@ -5616,7 +5622,8 @@
}, },
"inherits": { "inherits": {
"version": "2.0.3", "version": "2.0.3",
"bundled": true
"bundled": true,
"optional": true
}, },
"ini": { "ini": {
"version": "1.3.5", "version": "1.3.5",
@ -5626,6 +5633,7 @@
"is-fullwidth-code-point": { "is-fullwidth-code-point": {
"version": "1.0.0", "version": "1.0.0",
"bundled": true, "bundled": true,
"optional": true,
"requires": { "requires": {
"number-is-nan": "^1.0.0" "number-is-nan": "^1.0.0"
} }
@ -5638,17 +5646,20 @@
"minimatch": { "minimatch": {
"version": "3.0.4", "version": "3.0.4",
"bundled": true, "bundled": true,
"optional": true,
"requires": { "requires": {
"brace-expansion": "^1.1.7" "brace-expansion": "^1.1.7"
} }
}, },
"minimist": { "minimist": {
"version": "0.0.8", "version": "0.0.8",
"bundled": true
"bundled": true,
"optional": true
}, },
"minipass": { "minipass": {
"version": "2.2.4", "version": "2.2.4",
"bundled": true, "bundled": true,
"optional": true,
"requires": { "requires": {
"safe-buffer": "^5.1.1", "safe-buffer": "^5.1.1",
"yallist": "^3.0.0" "yallist": "^3.0.0"
@ -5665,6 +5676,7 @@
"mkdirp": { "mkdirp": {
"version": "0.5.1", "version": "0.5.1",
"bundled": true, "bundled": true,
"optional": true,
"requires": { "requires": {
"minimist": "0.0.8" "minimist": "0.0.8"
} }
@ -5737,7 +5749,8 @@
}, },
"number-is-nan": { "number-is-nan": {
"version": "1.0.1", "version": "1.0.1",
"bundled": true
"bundled": true,
"optional": true
}, },
"object-assign": { "object-assign": {
"version": "4.1.1", "version": "4.1.1",
@ -5747,6 +5760,7 @@
"once": { "once": {
"version": "1.4.0", "version": "1.4.0",
"bundled": true, "bundled": true,
"optional": true,
"requires": { "requires": {
"wrappy": "1" "wrappy": "1"
} }
@ -5822,7 +5836,8 @@
}, },
"safe-buffer": { "safe-buffer": {
"version": "5.1.1", "version": "5.1.1",
"bundled": true
"bundled": true,
"optional": true
}, },
"safer-buffer": { "safer-buffer": {
"version": "2.1.2", "version": "2.1.2",
@ -5852,6 +5867,7 @@
"string-width": { "string-width": {
"version": "1.0.2", "version": "1.0.2",
"bundled": true, "bundled": true,
"optional": true,
"requires": { "requires": {
"code-point-at": "^1.0.0", "code-point-at": "^1.0.0",
"is-fullwidth-code-point": "^1.0.0", "is-fullwidth-code-point": "^1.0.0",
@ -5869,6 +5885,7 @@
"strip-ansi": { "strip-ansi": {
"version": "3.0.1", "version": "3.0.1",
"bundled": true, "bundled": true,
"optional": true,
"requires": { "requires": {
"ansi-regex": "^2.0.0" "ansi-regex": "^2.0.0"
} }
@ -5907,11 +5924,13 @@
}, },
"wrappy": { "wrappy": {
"version": "1.0.2", "version": "1.0.2",
"bundled": true
"bundled": true,
"optional": true
}, },
"yallist": { "yallist": {
"version": "3.0.2", "version": "3.0.2",
"bundled": true
"bundled": true,
"optional": true
} }
} }
}, },

10
webui/src/Actions/authActions.js

@ -1,10 +0,0 @@
import store from "../Reducers"
import {verificationStartedEvent} from "../Reducers/authReducer";
const dispatch = store.dispatch;
export const verify = () => {
dispatch(verificationStartedEvent());
};

13
webui/src/Actions/lightActions.js

@ -0,0 +1,13 @@
import store from "../Reducers";
import {fetchGet} from "../Helpers/fetcher";
import {lightsReceivedEvent} from "../Reducers/lightReducer";
const dispatch = store.dispatch;
export function getLights() {
fetchGet("/light/").then(res => {
if (res !== null) {
dispatch(lightsReceivedEvent(res));
}
});
}

57
webui/src/Helpers/fetcher.js

@ -0,0 +1,57 @@
import store from "../Reducers";
import {verificationFailedEvent} from "../Reducers/authReducer";
const PREFIX = "/api";
const dispatch = store.dispatch;
function formatUrl(url, params = {}) {
const urlWithPrefix = PREFIX + url;
const queryString =
Object
.keys(params)
.map(k => encodeURIComponent(k) + '=' + encodeURIComponent(params[k]));
if (queryString.length > 0) {
return urlWithPrefix + "?" + queryString;
}
return urlWithPrefix;
}
/**
* @param {Response} res
*/
function authCheck(res) {
if (res.ok) {
return Promise.resolve(res.json());
} else {
if (res.status === 403) {
dispatch(verificationFailedEvent());
// Allow the promise to sort of fizzle out
return Promise.resolve(null);
}
return Promise.reject({ status: res.status, text: res.statusText });
}
}
export function fetchGet(url, params = {}) {
return fetch(formatUrl(url, params), {
method: "GET",
credentials: "include",
}).then(authCheck);
}
export function fetchPost(url, data) {
return fetch(formatUrl(url), {
method: "POST",
credentials: "include",
headers: {
"Content-Type": "application/json; charset=utf-8",
},
body: JSON.stringify(data),
}).then(authCheck);
}

21
webui/src/Reducers/lightReducer.js

@ -0,0 +1,21 @@
const initialState = {
lights: [],
};
const LIGHTS_RECEIVED = "LightReducer/Received";
const lightReducer = (state = initialState, {type, payload} = {}) => {
switch (type) {
case LIGHTS_RECEIVED:
return {
...state,
lights: payload,
};
default:
return state;
}
};
export const lightsReceivedEvent = (lights) => ({type: LIGHTS_RECEIVED, payload: lights});
export default lightReducer;
Loading…
Cancel
Save