From f83e56c9be19ae99b76a66af424a74a27a08caf7 Mon Sep 17 00:00:00 2001 From: DANIEL KATOTO Date: Mon, 29 Dec 2025 20:34:24 +0300 Subject: [PATCH 1/3] fix: slider items to shrink on small devices Signed-off-by: DANIEL KATOTO --- src/sections/Home/So-Special-Section/index.js | 98 ++++++++++--------- 1 file changed, 50 insertions(+), 48 deletions(-) diff --git a/src/sections/Home/So-Special-Section/index.js b/src/sections/Home/So-Special-Section/index.js index d91491f161280..d469b2a8e364e 100644 --- a/src/sections/Home/So-Special-Section/index.js +++ b/src/sections/Home/So-Special-Section/index.js @@ -1,5 +1,5 @@ -import React from "react"; +import React, {useLayoutEffect, useState, useRef} from "react"; import Slider from "react-slick"; import SoSpecialWrapper from "./so-special-style"; @@ -9,6 +9,9 @@ import Image from "../../../components/image"; // import { useStyledDarkMode } from "../../../theme/app/useStyledDarkMode"; const SoSpecial = () => { + const [isClient, setIsClient] = useState(false); + const [slidesToShowState, setSlidesToShowState] = useState(null); + const sliderRef = useRef(null); const data = useStaticQuery( graphql`query newsList { allMdx( @@ -53,56 +56,55 @@ const SoSpecial = () => { }` ); const settings = { - dots: false, + dots: slidesToShowState <= 1, infinite: false, speed: 500, - slidesToShow: 2.5, swipeToSlide: true, - - responsive: [ - { - breakpoint: 1200, - settings: { - slidesToShow: 2.2, - - } - }, - { - breakpoint: 1024, - settings: { - slidesToShow: 2, - - } - }, - { - breakpoint: 800, - settings: { - slidesToShow: 1.5, - slidesToScroll: 1, - initialSlide: 1 - } - }, - { - breakpoint: 600, - settings: { - dots: true, - arrows: false, - slidesToShow: 1, - slidesToScroll: 1, - initialSlide: 1 - } - }, - { - breakpoint: 400, - settings: { - dots: true, - arrows: false, - slidesToShow: 1, - slidesToScroll: 1 - } - } - ] + slidesToScroll: 1, + arrows: slidesToShowState !== 1, + slidesToShow: slidesToShowState ?? 2.5, }; + + const computeSlides = () => { + const w = typeof window !== "undefined" ? (window.innerWidth || document.documentElement.clientWidth) : 1200; + if (w <= 600) return 1; + if (w <= 800) return 1.5; + if (w <= 1024) return 2; + if (w <= 1200) return 2.2; + return 3; + }; + + useLayoutEffect(() => { + + setIsClient(true); + setSlidesToShowState(computeSlides()); + + let resizeTimeout = null; + const onResizeDebounced = () => { + clearTimeout(resizeTimeout); + resizeTimeout = setTimeout(() => { + const slides = computeSlides(); + setSlidesToShowState((prev) => { + if (prev !== slides) return slides; + return prev; + }); + if (sliderRef.current && sliderRef.current.innerSlider && typeof sliderRef.current.innerSlider.onWindowResized === "function") { + sliderRef.current.innerSlider.onWindowResized(); + } + }, 100); + }; + + window.addEventListener("resize", onResizeDebounced); + window.addEventListener("load", onResizeDebounced); + + return () => { + window.removeEventListener("resize", onResizeDebounced); + window.removeEventListener("load", onResizeDebounced); + clearTimeout(resizeTimeout); + }; + }, []); + + if (!isClient || slidesToShowState === null) return null; // const { isDark } = useStyledDarkMode(); @@ -113,7 +115,7 @@ const SoSpecial = () => {

We're making a splash

- + { data.allMdx.nodes.map(({ id, frontmatter, fields }) => (