diff --git a/community-website/pages/learn-git-and-github.tsx b/community-website/pages/learn-git-and-github.tsx index 2863539..5237259 100644 --- a/community-website/pages/learn-git-and-github.tsx +++ b/community-website/pages/learn-git-and-github.tsx @@ -1,6 +1,6 @@ /* eslint-disable @next/next/no-img-element */ import type { NextPage } from "next"; -import { useEffect, useRef } from "react"; +import { useEffect, useRef, useReducer } from "react"; import Head from "next/head"; import Link from "next/link"; import ConfettiGenerator from "confetti-js"; @@ -12,28 +12,66 @@ import specificStyles from "../styles/LearnGitAndGitHub.module.css"; const LearnGitAndGitHub: NextPage = () => { const currentSlide = useRef(0); const slidesRef = useRef>(); + const renderSlideIndicators = () => { + if (!slidesRef.current) return null; + const totalSlides = slidesRef.current.length; + + return ( +
+ {Array.from({ length: totalSlides }, (_, index) => ( + + ))} +
+ ); + }; + const renderButtonsComponent = () => { + if (!slidesRef.current) return null; + const totalSlides = slidesRef.current.length; + const isLastSlide = currentSlide.current === totalSlides - 1; + return ( -
- - -
+ + {!isLastSlide && ( + + )} + + {renderSlideIndicators()} + ); }; // Show slide + const [, forceUpdate] = useReducer((x: number) => x + 1, 0); + const showSlide = (n: number) => { if (!slidesRef.current) return; const slides = slidesRef.current; @@ -41,20 +79,20 @@ const LearnGitAndGitHub: NextPage = () => { slides[currentSlide.current].classList.remove(specificStyles.active); - currentSlide.current = n; - if (currentSlide.current >= totalSlides) currentSlide.current = 0; - if (currentSlide.current < 0) currentSlide.current = totalSlides - 1; + // Ensure slide number stays within bounds without wrapping + currentSlide.current = Math.min(Math.max(0, n), totalSlides - 1); slides[currentSlide.current].classList.add(specificStyles.active); const slideNumberEl = document.getElementById("slide-number"); const prevBtn = document.getElementById("prev-btn") as HTMLButtonElement; - const nextBtn = document.getElementById("next-btn") as HTMLButtonElement; if (slideNumberEl) slideNumberEl.textContent = String(currentSlide.current + 1); if (prevBtn) prevBtn.disabled = currentSlide.current === 0; - if (nextBtn) nextBtn.disabled = currentSlide.current === totalSlides - 1; + + // Force re-render to update navigation buttons + forceUpdate(); }; const nextSlide = () => showSlide(currentSlide.current + 1); @@ -73,7 +111,9 @@ const LearnGitAndGitHub: NextPage = () => { const handleKeyDown = (e: KeyboardEvent) => { if (e.key === "ArrowRight" || e.key === " ") { e.preventDefault(); - nextSlide(); + if (currentSlide.current < (slidesRef.current?.length || 0) - 1) { + nextSlide(); + } } else if (e.key === "ArrowLeft") { e.preventDefault(); previousSlide(); diff --git a/community-website/styles/LearnGitAndGitHub.module.css b/community-website/styles/LearnGitAndGitHub.module.css index e968752..1c7ead9 100644 --- a/community-website/styles/LearnGitAndGitHub.module.css +++ b/community-website/styles/LearnGitAndGitHub.module.css @@ -111,6 +111,48 @@ margin-top: 30px; } +.slideIndicators { + display: flex; + justify-content: center; + align-items: center; + gap: 8px; + margin-top: 24px; + flex-wrap: wrap; + padding: 0 20px; +} + +.slideIndicator { + width: 24px; + height: 24px; + border-radius: 12px; + background: white; + cursor: pointer; + transition: all 0.3s ease; + border: 1px solid #e2e8f0; + padding: 0; + display: flex; + align-items: center; + justify-content: center; + font-size: 12px; + font-weight: 500; + color: #4a5568; + box-shadow: 0 1px 3px rgba(0, 0, 0, 0.1); +} + +.slideIndicator:hover { + transform: translateY(-2px); + box-shadow: 0 4px 6px rgba(0, 0, 0, 0.1); + border-color: #cbd5e0; +} + +.slideIndicator.active { + background: #2d3748; + color: white; + border-color: #2d3748; + transform: translateY(-1px); + box-shadow: 0 4px 6px rgba(45, 55, 72, 0.3); +} + .navBtn { background: rgba(255, 255, 255, 0.2); border: 2px solid black; @@ -268,4 +310,4 @@ :global(.dark) .slide-counter { background: rgba(0, 0, 0, 0.2); -} +} \ No newline at end of file