diff --git a/src/components/modals/main/settings/sections/Stats.jsx b/src/components/modals/main/settings/sections/Stats.jsx new file mode 100644 index 00000000..74b904e8 --- /dev/null +++ b/src/components/modals/main/settings/sections/Stats.jsx @@ -0,0 +1,53 @@ +import React from 'react'; + +import Switch from '../Switch'; + +import EventBus from '../../../../../modules/helpers/eventbus'; + +export default class Stats extends React.PureComponent { + constructor() { + super(); + this.state = { + stats: JSON.parse(localStorage.getItem('statsData')) || {} + }; + } + + componentDidMount() { + EventBus.on('refresh', (data) => { + if (data === 'stats') { + if (localStorage.getItem('stats') === 'false') { + localStorage.setItem('statsData', JSON.stringify({})); + return this.setState({ + stats: JSON.parse(localStorage.getItem('statsData')) || {} + }); + } + this.forceUpdate(); + } + }) + } + + render() { + if (localStorage.getItem('stats') === 'false') { + return ( + <> +

Notice

+

You need to enable usage data in order to use this feature

+ + + ); + } + + return ( + <> +

Stats

+

Tabs opened: {this.state.stats['tabs-opened'] || 0}

+

Backgrounds favourited: {this.state.stats.feature ? this.state.stats.feature['background-favourite'] || 0 : 0}

+

Backgrounds downloaded: {this.state.stats.feature ? this.state.stats.feature['background-download'] || 0 : 0}

+

Quotes favourited: {this.state.stats.feature ? this.state.stats.feature['quoted-favourite'] || 0 : 0}

+

Settings changed: {this.state.stats.setting ? Object.keys(this.state.stats.setting).length : 0}

+ +

Turning this off will clear your statistics locally, but will not delete the anonymous data posted to umami.

+ + ); + } +} diff --git a/src/components/modals/main/tabs/Settings.jsx b/src/components/modals/main/tabs/Settings.jsx index 57bdb4da..3aebd92e 100644 --- a/src/components/modals/main/tabs/Settings.jsx +++ b/src/components/modals/main/tabs/Settings.jsx @@ -12,6 +12,7 @@ import Order from '../settings/sections/Order'; import Experimental from '../settings/sections/Experimental'; import QuickLinks from '../settings/sections/QuickLinks'; import Weather from '../settings/sections/Weather'; +import Stats from '../settings/sections/Stats'; import Tabs from './backend/Tabs'; @@ -37,6 +38,7 @@ export default function Settings() {
+
diff --git a/src/components/modals/main/tabs/backend/Tabs.jsx b/src/components/modals/main/tabs/backend/Tabs.jsx index 5aeb5dfe..63e33562 100644 --- a/src/components/modals/main/tabs/backend/Tabs.jsx +++ b/src/components/modals/main/tabs/backend/Tabs.jsx @@ -15,7 +15,7 @@ export default class Tabs extends React.PureComponent { onClick = (tab, name) => { if (name !== this.state.currentName) { - window.stats.postEvent('tab', `Changed ${this.state.currentName} to ${name}`); + window.stats.postEvent('tab', `Opened ${name}`); } this.setState({