From b0b8d5e55f4b483042f7158adc634188b70e14e7 Mon Sep 17 00:00:00 2001 From: MichalC <103170279+wSBMichalee@users.noreply.github.com> Date: Thu, 3 Sep 2026 22:57:37 +0200 Subject: [PATCH] feat(ui): add autoplay to testimonials and display author initials avatar --- src/blocks/Testimonials/Component.tsx | 62 +++++++++++++++++++-------- 1 file changed, 43 insertions(+), 19 deletions(-) diff --git a/src/blocks/Testimonials/Component.tsx b/src/blocks/Testimonials/Component.tsx index ce051fe..41236f4 100644 --- a/src/blocks/Testimonials/Component.tsx +++ b/src/blocks/Testimonials/Component.tsx @@ -1,11 +1,27 @@ 'use client' -import React, { useState } from 'react' +import React, { useState, useEffect } from 'react' import type { Page } from '../../payload-types' type Props = Extract[0], { blockType: 'testimonials' }> export const TestimonialsBlock: React.FC = ({ title, testimonials }) => { const [currentIndex, setCurrentIndex] = useState(0) + const [lastActionTime, setLastActionTime] = useState(Date.now()) + + useEffect(() => { + if (!testimonials || testimonials.length <= 1) return + + const interval = setInterval(() => { + setCurrentIndex((prev) => (prev + 1) % testimonials.length) + }, 7500) + + return () => clearInterval(interval) + }, [testimonials, lastActionTime]) + + const handleDotClick = (index: number) => { + setCurrentIndex(index) + setLastActionTime(Date.now()) + } if (!testimonials || testimonials.length === 0) return null @@ -21,25 +37,33 @@ export const TestimonialsBlock: React.FC = ({ title, testimonials }) => {
- {testimonials.map((t: NonNullable[0], index: number) => ( -
-

- {t.quote} -

- -
-
-

- {t.author} + {testimonials.map((t: NonNullable[0], index: number) => { + const initial = t.author ? t.author.charAt(0).toUpperCase() : '' + return ( +

+

+ {t.quote}

+ +
+
+
+
+ {initial} +
+

+ {t.author} +

+
+
-
- ))} + ) + })}
{testimonials.length > 1 && ( @@ -47,7 +71,7 @@ export const TestimonialsBlock: React.FC = ({ title, testimonials }) => { {testimonials.map((_, index) => (