diff --git a/src/features/welcome/Welcome.jsx b/src/features/welcome/Welcome.jsx index 13f25642..9e3b16bc 100644 --- a/src/features/welcome/Welcome.jsx +++ b/src/features/welcome/Welcome.jsx @@ -1,4 +1,3 @@ -// Importing necessary libraries and components import { useState, useEffect } from 'react'; import variables from 'config/variables'; import { MdArrowBackIosNew, MdArrowForwardIos, MdOutlinePreview } from 'react-icons/md'; @@ -24,22 +23,18 @@ import { Final, } from './components/Sections'; -// WelcomeModal component function WelcomeModal() { - // State variables const [currentTab, setCurrentTab] = useState(0); const [buttonText, setButtonText] = useState(variables.getMessage('modals.welcome.buttons.next')); const [importedSettings, setImportedSettings] = useState([]); - const [image, setImage] = useState(null); // New state variable for the image - const [credit, setCredit] = useState(''); // New state variable for the credit + const [image, setImage] = useState(null); + const [credit, setCredit] = useState(''); const finalTab = 6; - const [direction, setDirection] = useState(1); // New state variable for the direction - const [firstRender, setFirstRender] = useState(true); // New state variable for the first render - const [quote, setQuote] = useState(''); // New state variable for the quote + const [direction, setDirection] = useState(1); + const [firstRender, setFirstRender] = useState(true); + const [quote, setQuote] = useState(''); - // useEffect hook to handle tab changes and event bus listener useEffect(() => { - // Get the current welcome tab from local storage setFirstRender(false); const welcomeTab = localStorage.getItem('welcomeTab'); const randomQuote = offline_quotes[Math.floor(Math.random() * offline_quotes.length)].quote; @@ -55,14 +50,12 @@ function WelcomeModal() { } let offlineImage = null; - // Fetch the offline image if the current tab is 0 if (offlineImage === null) { offlineImage = getOfflineImage('background'); setImage(offlineImage.url); setCredit(offlineImage.photoInfo.credit); } - // Listener for the 'refresh' event const refreshListener = (data) => { if (data === 'welcomeLanguage') { localStorage.setItem('welcomeTab', currentTab); @@ -71,16 +64,13 @@ function WelcomeModal() { } }; - // Subscribe to the 'refresh' event EventBus.on('refresh', refreshListener); - // Cleanup function to unsubscribe from the 'refresh' event return () => { EventBus.off('refresh', refreshListener); }; }, [currentTab, finalTab]); - // Function to update the current tab and button text const updateTabAndButtonText = (newTab) => { setCurrentTab(newTab); setButtonText( @@ -93,9 +83,8 @@ function WelcomeModal() { localStorage.removeItem('welcomeTab'); }; - // Functions to navigate to the previous and next tabs const prevTab = () => { - setDirection(-1); // Update the direction + setDirection(-1); updateTabAndButtonText(currentTab - 1); }; @@ -108,12 +97,11 @@ function WelcomeModal() { updateTabAndButtonText(currentTab + 1); }; - // Function to switch to a specific tab const switchToTab = (tab) => { + setDirection(tab > currentTab ? 1 : -1); updateTabAndButtonText(tab); }; - // Navigation component const Navigation = () => { return (