From 2c19e8968efb42bdc699fc9b760ba4f88157a3e0 Mon Sep 17 00:00:00 2001 From: Marco Beretta <81851188+berry-13@users.noreply.github.com> Date: Fri, 15 Aug 2025 00:09:06 +0200 Subject: [PATCH] =?UTF-8?q?=F0=9F=9A=9B=20feat:=20add=20Daimler=20Truck=20?= =?UTF-8?q?logos=20and=20Optimize=20Companies=20component=20(#394)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- components/home/Companies.tsx | 164 ++++++++++++--------- components/home/companies.module.css | 18 ++- public/images/logos/DaimlerTruck_dark.svg | 35 +++++ public/images/logos/DaimlerTruck_light.svg | 34 +++++ 4 files changed, 172 insertions(+), 79 deletions(-) create mode 100644 public/images/logos/DaimlerTruck_dark.svg create mode 100644 public/images/logos/DaimlerTruck_light.svg diff --git a/components/home/Companies.tsx b/components/home/Companies.tsx index 7b22a8f..cb5493e 100644 --- a/components/home/Companies.tsx +++ b/components/home/Companies.tsx @@ -1,4 +1,4 @@ -import React from 'react' +import React, { useMemo } from 'react' import Image from 'next/image' import styles from './companies.module.css' @@ -27,23 +27,38 @@ const companies: Company[] = [ logoDark: '/images/logos/BostonUniversity_dark.png', logoColor: '/images/logos/BostonUniversity_color.png', }, + { + name: 'Daimler Truck', + logo: '/images/logos/DaimlerTruck_light.svg', + logoDark: '/images/logos/DaimlerTruck_dark.svg', + }, ] -export const Companies = () => { - const minLogos = 15 - const duplicateCount = Math.ceil(minLogos / companies.length) - const duplicatedCompanies = Array(duplicateCount * 2) - .fill(companies) - .flat() +export const Companies: React.FC = React.memo(() => { + const minLogos = 8 // Reduced minimum for better performance + + const displayCount = Math.max(minLogos, companies.length) + + const logosToShow = useMemo( + () => Array.from({ length: displayCount }, (_, i) => companies[i % companies.length]), + [displayCount], + ) + + // Create duplicated array for seamless infinite scroll + const duplicatedLogos = useMemo(() => [...logosToShow, ...logosToShow], [logosToShow]) const baseSpeed = 2 - const duration = Math.max(70, companies.length * baseSpeed) - const mobileDuration = Math.max(15, companies.length * 1.5) + const duration = useMemo(() => Math.max(40, logosToShow.length * baseSpeed), [logosToShow.length]) + const mobileDuration = useMemo(() => Math.max(30, logosToShow.length * 1.5), [logosToShow.length]) - const containerStyle = { - '--scroll-duration': `${duration}s`, - '--scroll-duration-mobile': `${mobileDuration}s`, - } as React.CSSProperties + const containerStyle = useMemo( + () => + ({ + '--scroll-duration': `${duration}s`, + '--scroll-duration-mobile': `${mobileDuration}s`, + }) as React.CSSProperties, + [duration, mobileDuration], + ) return (
@@ -58,76 +73,79 @@ export const Companies = () => {
- {duplicatedCompanies.map((company, index) => ( -
- {company.logoColor ? ( -
- {/* Light logo */} - {`${company.name} - {/* Dark logo */} - - {/* Color logo */} - {`${company.name} -
- ) : ( - <> - {/* Light logo */} - {`${company.name} - {company.logoDark && ( + {duplicatedLogos.map((company, index) => { + const isFirstFewLogos = index < Math.min(4, logosToShow.length) + const key = `${company.name}-${index}` + + return ( +
+ {company.logoColor ? ( +
- )} - - )} -
- ))} + + {`${company.name} +
+ ) : ( + <> + {`${company.name} + {company.logoDark && ( + + )} + + )} +
+ ) + })}
) -} +}) export default Companies diff --git a/components/home/companies.module.css b/components/home/companies.module.css index bcdaab8..9178816 100644 --- a/components/home/companies.module.css +++ b/components/home/companies.module.css @@ -4,7 +4,13 @@ position: relative; width: 100%; mask-image: linear-gradient(to right, transparent 0%, black 5%, black 95%, transparent 100%); - -webkit-mask-image: linear-gradient(to right, transparent 0%, black 5%, black 95%, transparent 100%); + -webkit-mask-image: linear-gradient( + to right, + transparent 0%, + black 5%, + black 95%, + transparent 100% + ); } .scrollContent { @@ -57,7 +63,7 @@ .logo { filter: grayscale(100%) opacity(0.4) brightness(1.3); } - + .logo:hover { filter: grayscale(0%) opacity(0.8) brightness(1); transform: scale(1.05); @@ -70,12 +76,12 @@ gap: 2.5rem; animation: scroll var(--scroll-duration-mobile, 35s) linear infinite; } - + .logoItem { min-width: 120px; height: 80px; } - + .logo { max-height: 60px; max-width: 120px; @@ -86,12 +92,12 @@ .scrollContent { gap: 2rem; } - + .logoItem { min-width: 100px; height: 70px; } - + .logo { max-height: 50px; max-width: 100px; diff --git a/public/images/logos/DaimlerTruck_dark.svg b/public/images/logos/DaimlerTruck_dark.svg new file mode 100644 index 0000000..c731d7b --- /dev/null +++ b/public/images/logos/DaimlerTruck_dark.svg @@ -0,0 +1,35 @@ + + + + + + + + + + + + + + + + + + \ No newline at end of file diff --git a/public/images/logos/DaimlerTruck_light.svg b/public/images/logos/DaimlerTruck_light.svg new file mode 100644 index 0000000..389545a --- /dev/null +++ b/public/images/logos/DaimlerTruck_light.svg @@ -0,0 +1,34 @@ + + + + + + + + + + + + + + + + + + \ No newline at end of file