fix: add some catches to stats just in case

This commit is contained in:
David Ralph
2024-05-31 20:06:42 +01:00
parent 5bb71fc45c
commit 65fb556eda

View File

@@ -28,7 +28,7 @@ export default class Stats {
static async postEvent(type, name) {
const value = name.toLowerCase().replaceAll(' ', '-');
const data = JSON.parse(localStorage.getItem('statsData'));
const data = JSON.parse(localStorage.getItem('statsData')) || {};
// tl;dr this creates the objects if they don't exist
// this really needs a cleanup at some point
if (!data[type] || !data[type][value]) {
@@ -50,7 +50,7 @@ export default class Stats {
* It increments the value of the key 'tabs-opened' in the object stored in localStorage by 1.
*/
static async tabLoad() {
const data = JSON.parse(localStorage.getItem('statsData'));
const data = JSON.parse(localStorage.getItem('statsData')) || {};
data['tabs-opened'] = data['tabs-opened'] + 1 || 1;
localStorage.setItem('statsData', JSON.stringify(data));
this.achievementTrigger(data);