Website components. Update chart component.

This commit is contained in:
Mike Cao 2020-07-28 01:17:45 -07:00
parent d81ee3932d
commit bdcdcd9d13
9 changed files with 165 additions and 43 deletions

View file

@ -7,17 +7,20 @@ export const apiRequest = (method, url, body) =>
'Content-Type': 'application/json',
},
body,
}).then(res => (res.ok ? res.json() : null));
}).then(res => {
if (res.ok) {
return res.json();
}
return null;
});
function parseQuery(url, params) {
const query =
params &&
Object.keys(params).reduce((values, key) => {
if (params[key] !== undefined) {
return values.concat(`${key}=${encodeURIComponent(params[key])}`);
}
return values;
}, []);
function parseQuery(url, params = {}) {
const query = Object.keys(params).reduce((values, key) => {
if (params[key] !== undefined) {
return values.concat(`${key}=${encodeURIComponent(params[key])}`);
}
return values;
}, []);
return query.length ? `${url}?${query.join('&')}` : url;
}