diff --git a/src/components/modals/main/settings/sections/Stats.jsx b/src/components/modals/main/settings/sections/Stats.jsx index fa0da2a4..a00c95da 100644 --- a/src/components/modals/main/settings/sections/Stats.jsx +++ b/src/components/modals/main/settings/sections/Stats.jsx @@ -1,3 +1,4 @@ +/* eslint-disable array-callback-return */ import variables from 'modules/variables'; import { PureComponent } from 'react'; import { MdShowChart } from 'react-icons/md'; @@ -7,15 +8,53 @@ import SettingsItem from '../SettingsItem'; import { FaTrophy } from 'react-icons/fa'; import EventBus from 'modules/helpers/eventbus'; +import achievementsData from 'modules/helpers/settings/achievements.json'; export default class Stats extends PureComponent { constructor() { super(); this.state = { stats: JSON.parse(localStorage.getItem('statsData')) || {}, + achievements: achievementsData.achievements }; } + getAchivements() { + const achievements = this.state.achievements; + achievements.forEach((achievement) => { + switch (achievement.condition.type) { + case 'tabsOpened': + if (this.state.stats['tabs-opened'] >= achievement.condition.amount) { + achievement.achieved = true; + } + break; + case 'addonInstall': + if (this.state.stats.marketplace) { + if (this.state.stats.marketplace['install'] >= achievement.condition.amount) { + achievement.achieved = true; + } + } + break; + default: + break; + } + }); + + this.setState({ + achievements + }); + } + + getUnlockedCount() { + let count = 0; + this.state.achievements.forEach((achievement) => { + if (achievement.achieved) { + count++; + } + }); + return count; + } + componentDidMount() { EventBus.on('refresh', (data) => { if (data === 'stats') { @@ -28,6 +67,8 @@ export default class Stats extends PureComponent { this.forceUpdate(); } }); + + this.getAchivements(); } componentWillUnmount() { @@ -58,7 +99,7 @@ export default class Stats extends PureComponent { ); } - const achievement = (name, description) => ( + const achievementElement = (name, description) => (