2021-02-04 19:15:23 +01:00
|
|
|
import localforage from 'localforage';
|
2020-11-24 16:38:04 +01:00
|
|
|
|
|
|
|
export async function getStorageItem(key) {
|
|
|
|
try {
|
2021-02-04 19:15:23 +01:00
|
|
|
const serializedData = await localforage.getItem(key);
|
2020-11-24 16:38:04 +01:00
|
|
|
if (serializedData === null) {
|
2021-02-04 19:15:23 +01:00
|
|
|
return undefined;
|
2020-11-24 16:38:04 +01:00
|
|
|
}
|
|
|
|
|
2021-02-04 19:15:23 +01:00
|
|
|
return JSON.parse(serializedData);
|
2020-11-24 16:38:04 +01:00
|
|
|
} catch (err) {
|
2021-02-04 19:15:23 +01:00
|
|
|
return undefined;
|
2020-11-24 16:38:04 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
export async function setStorageItem(key, value) {
|
|
|
|
try {
|
2021-02-04 19:15:23 +01:00
|
|
|
const serializedData = JSON.stringify(value);
|
|
|
|
await localforage.setItem(key, serializedData);
|
2020-11-24 16:38:04 +01:00
|
|
|
} catch (err) {
|
2021-02-04 19:15:23 +01:00
|
|
|
console.warn(err);
|
2020-11-24 16:38:04 +01:00
|
|
|
}
|
|
|
|
}
|