Skip to content

Commit

Permalink
Restored last year's landing page system and removed last year's land…
Browse files Browse the repository at this point in the history
…ing pages
  • Loading branch information
ashleyleal committed Jun 5, 2024
1 parent 3d2f7b4 commit 876888b
Showing 1 changed file with 15 additions and 46 deletions.
61 changes: 15 additions & 46 deletions client/src/pages/Initial/LandingPage.jsx
Original file line number Diff line number Diff line change
@@ -1,78 +1,47 @@
import React, { useEffect, useState } from 'react';

// F!rosh 2T3 Landing Pages
import { TanuLanding } from './TanuLanding/TanuLanding';
import { UzmaLanding } from './UzmaLanding/UzmaLanding';
import { NatLanding } from './NatLanding/NatLanding';
import { SherryLanding } from './SherryLanding/SherryLanding';

// F!rosh 2T4 Landing Pages
import { AshLanding } from './AshLanding/AshLanding';

const currentYear = '2T4';

const landingPages = [
{
key: 0,
component: <TanuLanding />,
year: '2T3',
component: <AshLanding />,
},
{
key: 1,
component: <UzmaLanding />,
year: '2T3',
},
{
key: 2,
component: <NatLanding />,
year: '2T3',
},
{
key: 3,
component: <SherryLanding />,
year: '2T3',
},
{
key: 4,
component: <AshLanding />,
year: '2T4',
},
];

// Change this logic to determine which landing pages to show
const landingPagesFiltered = landingPages.filter((page) => page.year === currentYear);

function randomNumber(min, max) {
return Math.floor(Math.random() * (max - min + 1) + min);
}

export const LandingPage = () => {
const [pageIndex, setPageIndex] = useState(null);

useEffect(() => {
if (landingPagesFiltered.length !== 1) {
let randIdx = randomNumber(0, landingPagesFiltered.length - 1);
const localIdx = window.localStorage.getItem('landing_page_idx');
let randIdx = randomNumber(0, landingPages.length - 1);
const localIdx = window.localStorage.getItem('landing_page_idx');

if (localIdx !== null) {
while (randIdx === JSON.parse(localIdx)) {
randIdx = randomNumber(0, landingPagesFiltered.length - 1);
}
if (localIdx !== null) {
while (randIdx === JSON.parse(localIdx)) {
randIdx = randomNumber(0, landingPages.length - 1);
}
window.localStorage.setItem('landing_page_idx', JSON.stringify(randIdx));
setPageIndex(JSON.parse(randIdx));
}
window.localStorage.setItem('landing_page_idx', JSON.stringify(randIdx));

setPageIndex(JSON.parse(randIdx));
}, []);

return (
<>
{landingPagesFiltered.length === 1
? landingPagesFiltered[0].component
: landingPagesFiltered.map((item) => {
if (item.key === pageIndex) {
return <div key={item.key}>{item.component}</div>;
}
return null;
})}
{landingPages.map((item) => {
if (item.key == pageIndex) {
return <div key={item.key}>{item.component}</div>;
}
})}
</>
);
};

0 comments on commit 876888b

Please sign in to comment.