From 2d657165bd5daa6be3abdaf8ecab486ee000e5a6 Mon Sep 17 00:00:00 2001 From: victorAnumudu Date: Fri, 7 Apr 2023 19:29:04 +0100 Subject: [PATCH] added a fxn that changes bg color on page refresh --- src/app/modules/auth/AuthLayout.tsx | 54 ++++++++++++++++++++++++++--- 1 file changed, 49 insertions(+), 5 deletions(-) diff --git a/src/app/modules/auth/AuthLayout.tsx b/src/app/modules/auth/AuthLayout.tsx index 8a5edc9..c49201e 100644 --- a/src/app/modules/auth/AuthLayout.tsx +++ b/src/app/modules/auth/AuthLayout.tsx @@ -1,10 +1,47 @@ /* eslint-disable jsx-a11y/anchor-is-valid */ -import {useEffect} from 'react' +import {useEffect, useState} from 'react' import {Outlet, Link} from 'react-router-dom' import {toAbsoluteUrl} from '../../../_res/helpers' const AuthLayout = () => { + //initial background color + let [bgColor, setBgColor] = useState({ + backgroundImage: 'linear-gradient(70deg, #E6E7F9, #b4caed)' + }) + + // function to determine background color + let changeBgColor = () => { + // let randomNum = Math.round(Math.random() * 3) + let randomNum = Number(localStorage.getItem('bg-num')) + if(randomNum){ + if(randomNum <= 1){ + setBgColor({ + backgroundImage: 'linear-gradient(70deg, #E6E7F9, #b4caed)' + }) + localStorage.setItem('bg-num', '2') + }else if(randomNum <= 2){ + setBgColor({ + backgroundImage: 'linear-gradient(70deg, #eee, #fff)' + }) + localStorage.setItem('bg-num', '3') + }else{ + setBgColor({ + backgroundImage: 'linear-gradient(70deg, #d5e1f5, #75a5f0)' + }) + localStorage.setItem('bg-num', '1') + } + }else{ + setBgColor({ + backgroundImage: 'linear-gradient(70deg, #E6E7F9, #b4caed)' + }) + localStorage.setItem('bg-num', '1') + } + } + useEffect(() => { + + changeBgColor() // calls the change color function after page loads + const root = document.getElementById('root') if (root) { root.style.height = '100%' @@ -65,8 +102,7 @@ const AuthLayout = () => { {/* begin::Aside */}
{/* begin::Content */}
@@ -76,12 +112,20 @@ const AuthLayout = () => { {/* end::Logo */} - + /> */} +
+ +
{/* end::Image */}
{/* begin::Title */}