diff --git a/src/features/modals/welcome/Welcome.jsx b/src/features/modals/welcome/Welcome.jsx index 0b9b0cf0..70e6e288 100644 --- a/src/features/modals/welcome/Welcome.jsx +++ b/src/features/modals/welcome/Welcome.jsx @@ -1,10 +1,10 @@ +import { useState, useEffect } from 'react'; import variables from 'config/variables'; -import { PureComponent } from 'react'; import { MdArrowBackIosNew, MdArrowForwardIos, MdOutlinePreview } from 'react-icons/md'; import EventBus from 'utils/eventbus'; -import { ProgressBar, AsideImage } from './components/Elements'; +import { ProgressBar, AsideImage, Navigation } from './components/Elements'; import { Button } from 'components/Elements'; import { Wrapper, Panel } from './components/Layout'; @@ -20,90 +20,81 @@ import { Final, } from './Sections'; -class WelcomeModal extends PureComponent { - constructor() { - super(); - this.state = { - currentTab: 0, - finalTab: 5, - buttonText: variables.getMessage('modals.welcome.buttons.next'), - }; - } +function WelcomeModal({ modalClose, modalSkip }) { + const [currentTab, setCurrentTab] = useState(0); + const [buttonText, setButtonText] = useState(variables.getMessage('modals.welcome.buttons.next')); + const finalTab = 6; - changeTab(minus) { + useEffect(() => { + const welcomeTab = localStorage.getItem('welcomeTab'); + if (welcomeTab) { + const tab = Number(welcomeTab); + setCurrentTab(tab); + setButtonText( + tab !== finalTab + 1 + ? variables.getMessage('modals.welcome.buttons.next') + : variables.getMessage('modals.welcome.buttons.finish'), + ); + } + + const refreshListener = (data) => { + if (data === 'welcomeLanguage') { + localStorage.setItem('welcomeTab', currentTab); + localStorage.setItem('bgtransition', false); + window.location.reload(); + } + }; + + EventBus.on('refresh', refreshListener); + + return () => { + EventBus.off('refresh', refreshListener); + }; + }, [currentTab, finalTab]); + + const changeTab = (minus) => { localStorage.setItem('bgtransition', true); localStorage.removeItem('welcomeTab'); if (minus) { - return this.setState({ - currentTab: this.state.currentTab - 1, - buttonText: variables.getMessage('modals.welcome.buttons.next'), - }); + setCurrentTab(currentTab - 1); + setButtonText(variables.getMessage('modals.welcome.buttons.next')); + return; } - if (this.state.buttonText === variables.getMessage('modals.welcome.buttons.finish')) { - return this.props.modalClose(); + if (buttonText === variables.getMessage('modals.welcome.buttons.finish')) { + modalClose(); + return; } - this.setState({ - currentTab: this.state.currentTab + 1, - image: [this.state.currentTab + 1], - buttonText: - this.state.currentTab !== this.state.finalTab - ? variables.getMessage('modals.welcome.buttons.next') - : variables.getMessage('modals.welcome.buttons.finish'), - }); - } + const newTab = currentTab + 1; + setCurrentTab(newTab); + setButtonText( + newTab !== finalTab + ? variables.getMessage('modals.welcome.buttons.next') + : variables.getMessage('modals.welcome.buttons.finish'), + ); + }; - // specific - switchTab(tab) { - this.setState({ - currentTab: tab, - buttonText: - tab !== this.state.finalTab + 1 - ? variables.getMessage('modals.welcome.buttons.next') - : variables.getMessage('modals.welcome.buttons.finish'), - }); + const switchTab = (tab) => { + setCurrentTab(tab); + setButtonText( + tab !== finalTab + 1 + ? variables.getMessage('modals.welcome.buttons.next') + : variables.getMessage('modals.welcome.buttons.finish'), + ); localStorage.setItem('bgtransition', true); localStorage.removeItem('welcomeTab'); - } - - componentDidMount() { - const welcomeTab = localStorage.getItem('welcomeTab'); - if (welcomeTab) { - this.setState({ - currentTab: Number(welcomeTab), - buttonText: - Number(welcomeTab) !== this.state.finalTab + 1 - ? variables.getMessage('modals.welcome.buttons.next') - : variables.getMessage('modals.welcome.buttons.finish'), - }); - } - - EventBus.on('refresh', (data) => { - if (data === 'welcomeLanguage') { - localStorage.setItem('welcomeTab', this.state.currentTab); - localStorage.setItem('bgtransition', false); - window.location.reload(); - } - }); - } - - componentWillUnmount() { - EventBus.off('refresh'); - } - - renderButtons() { - const { currentTab, buttonText } = this.state; - const { modalSkip } = this.props; + }; + const Navigation = () => { return (
{currentTab !== 0 ? (
); - } + }; - render() { - const tabComponents = { - 0: , - 1: , - 2: this.switchTab(tab)} />, - 3: , - 4: , - 5: , - 6: this.switchTab(tab)} />, - }; + const tabComponents = { + 0: , + 1: , + 2: , + 3: , + 4: , + 5: , + 6: , + }; - let CurrentSection = tabComponents[this.state.currentTab] || ; - return ( - - - - this.switchTab(tab)} - /> - - - {CurrentSection} - {this.renderButtons()} - - - ); - } + let CurrentTab = tabComponents[currentTab] || ; + + return ( + + + + + + + {CurrentTab} + + + + ); } export default WelcomeModal; diff --git a/src/features/modals/welcome/components/Elements/Navigation/Navigation.jsx b/src/features/modals/welcome/components/Elements/Navigation/Navigation.jsx new file mode 100644 index 00000000..7b27974f --- /dev/null +++ b/src/features/modals/welcome/components/Elements/Navigation/Navigation.jsx @@ -0,0 +1,34 @@ +import { MdArrowBackIosNew, MdArrowForwardIos, MdOutlinePreview } from 'react-icons/md'; +import { Button } from 'components/Elements'; +import variables from 'config/variables'; + +function Navigation({ currentTab, changeTab, buttonText, modalSkip }) { + return ( +
+ {currentTab !== 0 ? ( +
+ ); +} + +export { Navigation as default, Navigation }; diff --git a/src/features/modals/welcome/components/Elements/Navigation/index.jsx b/src/features/modals/welcome/components/Elements/Navigation/index.jsx new file mode 100644 index 00000000..95e14a93 --- /dev/null +++ b/src/features/modals/welcome/components/Elements/Navigation/index.jsx @@ -0,0 +1 @@ +export * from './Navigation'; diff --git a/src/features/modals/welcome/components/Elements/index.jsx b/src/features/modals/welcome/components/Elements/index.jsx index 5acfbfe6..d5dd5196 100644 --- a/src/features/modals/welcome/components/Elements/index.jsx +++ b/src/features/modals/welcome/components/Elements/index.jsx @@ -1,2 +1,3 @@ export * from './ProgressBar'; export * from './AsideImage'; +export * from './Navigation';