From 4584da1199a5eef865afb2031d9bf6acba3131d6 Mon Sep 17 00:00:00 2001 From: sebseb7 Date: Sun, 27 Jul 2025 14:04:36 +0200 Subject: [PATCH] size optimize --- src/components/MainPageLayout.js | 668 ++++++++----------------------- 1 file changed, 165 insertions(+), 503 deletions(-) diff --git a/src/components/MainPageLayout.js b/src/components/MainPageLayout.js index 8ff7baa..90c537b 100644 --- a/src/components/MainPageLayout.js +++ b/src/components/MainPageLayout.js @@ -12,11 +12,112 @@ import SharedCarousel from "./SharedCarousel.js"; import { getCombinedAnimatedBorderStyles } from "../utils/animatedBorderStyles.js"; import { useTranslation } from 'react-i18next'; +const ContentBox = ({ box, index, pageType, starHovered, setStarHovered, opacity, translatedContent }) => ( + + {index === 0 && pageType === "filiale" && ( + + + + + + + + + + +
+ {translatedContent.showUsPhoto} +
+
+ {translatedContent.selectSeedRate} +
+
+ )} + {index === 1 && pageType === "filiale" && ( + + + + + + + + + + +
+ {translatedContent.indoorSeason} +
+
+ )} +
+ setStarHovered(true) : undefined} + onMouseLeave={index === 0 && pageType === "filiale" ? () => setStarHovered(false) : undefined} + > + + {opacity === 1 && ( + {box.title} + )} + + {box.title} + + + +
+
+); + const MainPageLayout = () => { const location = useLocation(); const currentPath = location.pathname; const { t } = useTranslation(); const [starHovered, setStarHovered] = React.useState(false); + const translatedContent = { + showUsPhoto: t('sections.showUsPhoto'), + selectSeedRate: t('sections.selectSeedRate'), + indoorSeason: t('sections.indoorSeason') + }; const isHome = currentPath === "/"; const isAktionen = currentPath === "/aktionen"; @@ -29,98 +130,49 @@ const MainPageLayout = () => { from { transform: rotate(0deg); } to { transform: rotate(360deg); } } - @keyframes rotateCounterClockwise { from { transform: rotate(0deg); } to { transform: rotate(-360deg); } } - .star-rotate-slow-cw { animation: rotateClockwise 60s linear infinite; } - .star-rotate-slow-ccw { animation: rotateCounterClockwise 45s linear infinite; } - .star-rotate-medium-cw { animation: rotateClockwise 30s linear infinite; } `; document.head.appendChild(style); - return () => { - document.head.removeChild(style); - }; + return () => document.head.removeChild(style); }, []); const getNavigationConfig = () => { - if (isHome) { - return { - leftNav: { text: t('navigation.aktionen'), link: "/aktionen" }, - rightNav: { text: t('navigation.filiale'), link: "/filiale" } - }; - } else if (isAktionen) { - return { - leftNav: { text: t('navigation.filiale'), link: "/filiale" }, - rightNav: { text: t('navigation.home'), link: "/" } - }; - } else if (isFiliale) { - return { - leftNav: { text: t('navigation.home'), link: "/" }, - rightNav: { text: t('navigation.aktionen'), link: "/aktionen" } - }; - } + if (isHome) return { leftNav: { text: t('navigation.aktionen'), link: "/aktionen" }, rightNav: { text: t('navigation.filiale'), link: "/filiale" } }; + if (isAktionen) return { leftNav: { text: t('navigation.filiale'), link: "/filiale" }, rightNav: { text: t('navigation.home'), link: "/" } }; + if (isFiliale) return { leftNav: { text: t('navigation.home'), link: "/" }, rightNav: { text: t('navigation.aktionen'), link: "/aktionen" } }; return { leftNav: null, rightNav: null }; }; const allTitles = { home: t('titles.filiale'), - aktionen: t('titles.aktionen'), + aktionen: t('titles.aktionen'), filiale: t('titles.home') }; const allContentBoxes = { home: [ - { - title: t('sections.address1'), - image: "/assets/images/filiale1.jpg", - bgcolor: "#e1f0d3", - link: "/filiale" - }, - { - title: t('sections.address2'), - image: "/assets/images/filiale2.jpg", - bgcolor: "#e8f5d6", - link: "/filiale" - } + { title: t('sections.address1'), image: "/assets/images/filiale1.jpg", bgcolor: "#e1f0d3", link: "/filiale" }, + { title: t('sections.address2'), image: "/assets/images/filiale2.jpg", bgcolor: "#e8f5d6", link: "/filiale" } ], aktionen: [ - { - title: t('sections.oilPress'), - image: "/assets/images/presse.jpg", - bgcolor: "#e1f0d3", - link: "/presseverleih" - }, - { - title: t('sections.thcTest'), - image: "/assets/images/purpl.jpg", - bgcolor: "#e8f5d6", - link: "/thc-test" - } + { title: t('sections.oilPress'), image: "/assets/images/presse.jpg", bgcolor: "#e1f0d3", link: "/presseverleih" }, + { title: t('sections.thcTest'), image: "/assets/images/purpl.jpg", bgcolor: "#e8f5d6", link: "/thc-test" } ], filiale: [ - { - title: t('sections.seeds'), - image: "/assets/images/seeds.jpg", - bgcolor: "#e1f0d3", - link: "/Kategorie/Seeds" - }, - { - title: t('sections.stecklinge'), - image: "/assets/images/cutlings.jpg", - bgcolor: "#e8f5d6", - link: "/Kategorie/Stecklinge" - } + { title: t('sections.seeds'), image: "/assets/images/seeds.jpg", bgcolor: "#e1f0d3", link: "/Kategorie/Seeds" }, + { title: t('sections.stecklinge'), image: "/assets/images/cutlings.jpg", bgcolor: "#e8f5d6", link: "/Kategorie/Stecklinge" } ] }; @@ -132,7 +184,6 @@ const MainPageLayout = () => { }; const navConfig = getNavigationConfig(); - const navTexts = [ { key: 'aktionen', text: t('navigation.aktionen'), link: '/aktionen' }, { key: 'filiale', text: t('navigation.filiale'), link: '/filiale' }, @@ -142,188 +193,61 @@ const MainPageLayout = () => { return ( - - + + {Object.entries(allTitles).map(([pageType, title]) => ( - - {title} - + {title} ))} - - + + {navTexts.map((navItem, index) => { const isActive = navConfig.leftNav && navConfig.leftNav.text === navItem.text; - const link = navItem.link; return ( - + - - {navItem.text} - + {navItem.text} ); })} - + {Object.entries(allTitles).map(([pageType, title]) => ( - - {title} - + {title} ))} - + {navTexts.map((navItem, index) => { const isActive = navConfig.rightNav && navConfig.rightNav.text === navItem.text; - const link = navItem.link; return ( - - - {navItem.text} - + + {navItem.text} ); @@ -333,283 +257,21 @@ const MainPageLayout = () => { {Object.entries(allContentBoxes).map(([pageType, contentBoxes]) => ( - + {contentBoxes.map((box, index) => ( - - {index === 0 && pageType === "filiale" && ( - - - - - - - - - - -
- {t('sections.showUsPhoto')} -
-
- {t('sections.selectSeedRate')} -
-
- )} - {index === 1 && pageType === "filiale" && ( - - - - - - - - - - -
- {t('sections.indoorSeason')} -
-
- )} -
- setStarHovered(true) : undefined} - onMouseLeave={index === 0 && pageType === "filiale" ? () => setStarHovered(false) : undefined} - > - - {getOpacity(pageType) === 1 && ( - {box.title} - )} - - - {box.title} - - - - -
-
+ ))}
))} @@ -619,4 +281,4 @@ const MainPageLayout = () => { ); }; -export default MainPageLayout; \ No newline at end of file +export default MainPageLayout;