Updated profile settings. Refactored locale saving.

This commit is contained in:
Mike Cao 2020-09-17 00:17:11 -07:00
parent 814589f6a5
commit 7f598fa84d
9 changed files with 82 additions and 30 deletions

View file

@ -19,7 +19,7 @@ export const apiRequest = (method, url, body) =>
return null;
});
function parseQuery(url, params = {}) {
const parseQuery = (url, params = {}) => {
const query = Object.keys(params).reduce((values, key) => {
if (params[key] !== undefined) {
return values.concat(`${key}=${encodeURIComponent(params[key])}`);
@ -27,7 +27,7 @@ function parseQuery(url, params = {}) {
return values;
}, []);
return query.length ? `${url}?${query.join('&')}` : url;
}
};
export const get = (url, params) => apiRequest('get', parseQuery(url, params));
@ -62,3 +62,14 @@ export const doNotTrack = () => {
return dnt === true || dnt === 1 || dnt === 'yes' || dnt === '1';
};
export const setItem = (key, data, session) => {
if (typeof window !== 'undefined') {
(session ? sessionStorage : localStorage).setItem(key, JSON.stringify(data));
}
};
export const getItem = (key, session) =>
typeof window !== 'undefined'
? JSON.parse((session ? sessionStorage : localStorage).getItem(key))
: null;