diff --git a/src/components/Elements/MainModal/backend/Tabs.jsx b/src/components/Elements/MainModal/backend/Tabs.jsx index 591a9769..48b6c8a9 100644 --- a/src/components/Elements/MainModal/backend/Tabs.jsx +++ b/src/components/Elements/MainModal/backend/Tabs.jsx @@ -1,5 +1,5 @@ import variables from 'config/variables'; -import { PureComponent } from 'react'; +import React, { useState, useEffect } from 'react'; import { MdSettings, MdOutlineShoppingBasket, @@ -11,111 +11,104 @@ import Tab from './Tab'; import { Button } from 'components/Elements'; import ErrorBoundary from '../../../../features/misc/modals/ErrorBoundary'; -class Tabs extends PureComponent { - constructor(props) { - super(props); +const Tabs = (props) => { + const [currentTab, setCurrentTab] = useState(props.children[0].props.label); + const [currentName, setCurrentName] = useState(props.children[0].props.name); - this.state = { - currentTab: this.props.children[0].props.label, - currentName: this.props.children[0].props.name, - }; - } - - onClick = (tab, name) => { - if (name !== this.state.currentName) { + const onClick = (tab, name) => { + if (name !== currentName) { variables.stats.postEvent('tab', `Opened ${name}`); } - this.setState({ - currentTab: tab, - currentName: name, - }); + setCurrentTab(tab); + setCurrentName(name); }; - hideReminder() { + const hideReminder = () => { localStorage.setItem('showReminder', false); document.querySelector('.reminder-info').style.display = 'none'; - } + }; - render() { - const navbarButtons = [ - { - tab: 'settings', - icon: , - }, - { - tab: 'addons', - icon: , - }, - { - tab: 'marketplace', - icon: , - }, - ]; + const navbarButtons = [ + { + tab: 'settings', + icon: , + }, + { + tab: 'addons', + icon: , + }, + { + tab: 'marketplace', + icon: , + }, + ]; - const reminderInfo = ( -
-
- - {variables.getMessage('modals.main.settings.reminder.title')} - - this.hideReminder()}> - - -
- - {variables.getMessage('modals.main.settings.reminder.message')} + const reminderInfo = ( +
+
+ + {variables.getMessage('modals.main.settings.reminder.title')} + + + -
- ); + + {variables.getMessage('modals.main.settings.reminder.message')} + + +
+ ); - return ( -
-
- {this.props.children.map((tab, index) => ( - this.onClick(nextTab, tab.props.name)} - navbarTab={this.props.navbar || false} + return ( +
+

{currentTab}

+

{currentName}

+

{props.current}

+
+ {props.children.map((tab, index) => ( + onClick(nextTab, tab.props.name)} + navbarTab={props.navbar || false} + /> + ))} + {reminderInfo} +
+
+
+ {navbarButtons.map(({ tab, icon }, index) => ( +
-
-
- {navbarButtons.map(({ tab, icon }, index) => ( -
- {this.props.children.map((tab, index) => { - if (tab.props.label !== this.state.currentTab) { - return undefined; - } + {props.children.map((tab, index) => { + if (tab.props.label !== currentTab) { + return undefined; + } - return ( - {tab.props.children} - ); - })} -
+ return ( + {tab.props.children} + ); + })}
- ); - } -} +
+ ); +}; export default Tabs; diff --git a/src/features/weather/options/WeatherOptions.jsx b/src/features/weather/options/WeatherOptions.jsx index ca4205f6..d657c2fc 100644 --- a/src/features/weather/options/WeatherOptions.jsx +++ b/src/features/weather/options/WeatherOptions.jsx @@ -1,20 +1,11 @@ -import { useState, useEffect, useCallback } from 'react'; +import { useCallback } from 'react'; import { MdAutoAwesome } from 'react-icons/md'; import { Header, Row, Content, Action, PreferencesWrapper } from 'components/Layout/Settings'; +import { useLocalStorageState } from 'utils/useLocalStorageState'; import { Radio, Dropdown, Checkbox } from 'components/Form/Settings'; import { TextField } from '@mui/material'; import variables from 'config/variables'; -const useLocalStorageState = (key, initialValue) => { - const [state, setState] = useState(() => localStorage.getItem(key) || initialValue); - - useEffect(() => { - localStorage.setItem(key, state); - }, [key, state]); - - return [state, setState]; -}; - const useWeatherSettings = () => { const [location, setLocation] = useLocalStorageState('location', ''); const [windSpeed, setWindSpeed] = useLocalStorageState('windspeed', 'true'); diff --git a/src/utils/useLocalStorageState.js b/src/utils/useLocalStorageState.js new file mode 100644 index 00000000..d88af58b --- /dev/null +++ b/src/utils/useLocalStorageState.js @@ -0,0 +1,11 @@ +import { useState, useEffect } from 'react'; + +export const useLocalStorageState = (key, initialValue) => { + const [state, setState] = useState(() => localStorage.getItem(key) || initialValue); + + useEffect(() => { + localStorage.setItem(key, state); + }, [key, state]); + + return [state, setState]; +}; \ No newline at end of file