diff --git a/src/app.jsx b/src/app.jsx index 84aa0b0..5f689c5 100644 --- a/src/app.jsx +++ b/src/app.jsx @@ -69,19 +69,41 @@ export default class AppComponent extends React.Component { * @returns {JSX.Element} The rendered AppComponent. */ render() { + // Initialize the state variable for the theme toggle + /** + * State variable for the theme toggle. + * It is initialized with the value from localStorage or false. + * @type {boolean} + */ + const [isToggled, setToggle] = React.useState( + JSON.parse(localStorage.getItem('theme')) || false + ); + + // Use effect hook to update the theme in the local storage when the theme toggle state changes + /** + * Use effect hook to update the theme in the local storage when the theme toggle state changes. + */ + React.useEffect(() => { + localStorage.setItem('theme', JSON.stringify(isToggled)); + }, [isToggled]); + // Get the items from the component's state + /** + * Get the items from the component's state. + * @type {Array} + */ const { items } = this.state; return ( // Wrapper div for the AppComponent - /* + /** * The root div for the AppComponent. * This div has a flex layout with a minimum height of 100vh (viewport height). */
{/* Navigation component */} {/* The navigation component at the top of the AppComponent */} - + {/* Container div with a margin-top class */}
{/* Columns div with a centered layout */} @@ -92,9 +114,9 @@ export default class AppComponent extends React.Component { {/* Input component with items and setItems props */} {/* The input component that allows the user to enter UUIDs */} this.setState({items})} />
@@ -104,10 +126,12 @@ export default class AppComponent extends React.Component { {/* History component with items prop */} {/* The history component that displays the past input items */} this.setState({items: []})} + // The theme toggle state + isToggled={isToggled} />
diff --git a/src/history.jsx b/src/history.jsx index 7ba0f44..fc8222b 100644 --- a/src/history.jsx +++ b/src/history.jsx @@ -43,45 +43,56 @@ export default class HistoryComponent extends React.Component { */ render() { // Destructure the props - const { items, clearItems } = this.props; + const { items, clearItems, isToggled } = this.props; return ( // Navigation panel -