All files / src/pages Courses.jsx

84.61% Statements 11/13
75% Branches 3/4
71.42% Functions 5/7
90.9% Lines 10/11

Press n or j to go to the next uncovered block, b, p or k for the previous block.

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276                                                                              18x 18x 18x   18x                                                                                                                                                                                                     18x   18x         18x                               54x                                                                           99x                                                                                                                   7x                            
import {useTranslation} from 'react-i18next';
import {Card} from "../components/ui/Card";
import {CardContent} from "../components/ui/CardContent";
import {Disclosure} from '@headlessui/react';
import {ChevronDown} from 'lucide-react';
import {useState} from "react";
import PageSection from "../components/ui/PageSection";
import {ExpandableText} from "../components/ui/ExpandableText";
import {AnimatePresence, motion} from "framer-motion";
import gitPhoto from '../assets/courses/GIT.png';
import cPhoto from '../assets/courses/C.png';
import angularjsPhoto from '../assets/courses/ANGULARJS.png';
import assemblyPhoto from '../assets/courses/ASSEMBLY.png';
import cplusplusPhoto from '../assets/courses/CPLUSPLUS.png';
import html5Photo from '../assets/courses/HTML5.png';
import javaPhoto from '../assets/courses/JAVA.png';
import javascriptPhoto from '../assets/courses/JAVASCRIPT.png';
import jqueryPhoto from '../assets/courses/JQUERY.png';
import phpPhoto from '../assets/courses/PHP.png';
import sqlPhoto from '../assets/courses/SQL.png';
import typescriptPhoto from '../assets/courses/TYPESCRIPT.png';
import SeoHead from "../components/ui/SeoHead";
 
/**
 * Courses component.
 *
 * Displays a paginated list of programming courses, each with title, description,
 * duration, and technologies used.
 *
 * Features:
 * - Uses i18next for translations of titles, descriptions, and UI texts.
 * - Shows 6 courses per page with next/previous pagination buttons.
 * - Each course is displayed inside a Card with expandable technologies section.
 *
 * @component
 * @module pages/Courses
 * @returns {JSX.Element} The rendered Courses page section.
 */
export default function Courses() {
    const {t} = useTranslation();
    const coursesPerPage = 3;
    const [page, setPage] = useState(1);
 
    const courses = [
        {
            nameKey: "courses_page.git.title",
            descKey: "courses_page.git.description",
            durationKey: "courses_page.git.duration",
            tech: "Git",
            link: "https://www.udemy.com/course/corso-git/",
            image: gitPhoto
        },
        {
            nameKey: "courses_page.typescript.title",
            descKey: "courses_page.typescript.description",
            durationKey: "courses_page.typescript.duration",
            tech: "Typescript, data types, module, OOP ...",
            link: "https://www.udemy.com/course/typescript-da-zero/",
            image: typescriptPhoto
        },
        {
            nameKey: "courses_page.jQuery.title",
            descKey: "courses_page.jQuery.description",
            durationKey: "courses_page.jQuery.duration",
            tech: "jQuery, Selectors, Classes management, Traversing, Manipulating CSS, Bind, Events ...",
            link: "https://www.udemy.com/course/corso-jquery/",
            image: jqueryPhoto
        },
        {
            nameKey: "courses_page.php.title",
            descKey: "courses_page.php.description",
            durationKey: "courses_page.php.duration",
            tech: "Php, data types, Control flow statements, iterations, Regular expressions, Arrays, OOP, HTTP calls, File system ...",
            link: "https://www.udemy.com/course/corso-di-programmazione-php/",
            image: phpPhoto
        },
        {
            nameKey: "courses_page.cpp.title",
            descKey: "courses_page.cpp.description",
            durationKey: "courses_page.cpp.duration",
            tech: "C++, data types, control flow statements, iterations, I/O system, arrays and structs, OOP, lambda expressions ...",
            link: "https://www.udemy.com/course/corso-di-programmazione-c-plus-plus/",
            image: cplusplusPhoto
        },
        {
            nameKey: "courses_page.html5.title",
            descKey: "courses_page.html5.description",
            durationKey: "courses_page.html5.duration",
            tech: "HTML5, APIs (WebStorage, Web Workers, Drag & Drop ...), Canvas & Multimedia, Header, Footer, Aside ...",
            link: "https://www.udemy.com/course/corso-html5/",
            image: html5Photo
        },
        {
            nameKey: "courses_page.angularJS.title",
            descKey: "courses_page.angularJS.description",
            durationKey: "courses_page.angularJS.duration",
            tech: "AngularJS, scope (the hierarchy), services ($http), control flow statement, directives (bind, ng-class, ng-repeat...), filters, custom directives ...",
            link: "https://www.udemy.com/course/corso-angularjs/",
            image: angularjsPhoto
        },
        {
            nameKey: "courses_page.java.title",
            descKey: "courses_page.java.description",
            durationKey: "courses_page.java.duration",
            tech: "Java, Control flow statements, iterations, arrays, OOP, File management, Lambda expressions, MySQL, MongoDB  ...",
            link: "https://www.udemy.com/course/corso-di-programmazione-java/",
            image: javaPhoto
        },
        {
            nameKey: "courses_page.javascript.title",
            descKey: "courses_page.javascript.description",
            durationKey: "courses_page.javascript.duration",
            tech: "Javascript, control flow statements, iterations, arrays, DOM, Design patterns, Arrow function ...",
            link: "https://www.udemy.com/course/corso-di-programmazione-javascript/",
            image: javascriptPhoto
        },
        {
            nameKey: "courses_page.c.title",
            descKey: "courses_page.c.description",
            durationKey: "courses_page.c.duration",
            tech: "C, data types, control flow statements, iterations, arrays, structs ...",
            link: "https://www.udemy.com/course/corso-di-programmazione-c/",
            image: cPhoto
        },
        {
            nameKey: "courses_page.assembler.title",
            descKey: "courses_page.assembler.description",
            durationKey: "courses_page.assembler.duration",
            tech: "AssemblerX86, data types, control flow statement, iterations, arrays ...",
            link: "https://www.udemy.com/course/corso-di-programmazione-assembler-8086/",
            image: assemblyPhoto
        },
        {
            nameKey: "courses_page.sql.title",
            descKey: "courses_page.sql.description",
            durationKey: "courses_page.sql.duration",
            tech: "SQL, C, E/R, DB design ...",
            link: "https://www.udemy.com/course/corso-sulle-basi-di-dati-dallo-schema-er-allsql/",
            image: sqlPhoto
        }
    ];
 
    const totalPages = Math.ceil(courses.length / coursesPerPage);
 
    const displayedCourses = courses.slice(
        (page - 1) * coursesPerPage,
        page * coursesPerPage
    );
 
    return (
        <>
            <SeoHead pageKey="courses" path="/courses"/>
 
            <PageSection title={t("courses_page.title")}>
 
                <AnimatePresence mode="wait">
                    <motion.div
                        key={`page-${page}`}
                        initial={{opacity: 0, y: 40}}
                        animate={{opacity: 1, y: 0}}
                        exit={{opacity: 0, y: -40}}
                        transition={{duration: 0.4}}
                        className="flex flex-wrap gap-6"
                    >
                        {displayedCourses.map((course, idx) => (
                            <Card key={idx} className="flex flex-col md:flex-row items-start gap-4 p-4 sm:p-6">
                                <CardContent className="p-0 flex-1">
 
                                    {/* Title + small image on mobile */}
                                    <div className="flex items-center justify-between">
                                        <h3 className="text-lg font-semibold">
                                            {t(course.nameKey)}
                                        </h3>
 
                                        {/* Mobile small image */}
                                        <a
                                            href={course.link}
                                            target="_blank"
                                            rel="noopener noreferrer"
                                            className="block md:hidden shrink-0 ml-4"
                                        >
                                            <img
                                                src={course.image}
                                                alt={t(course.nameKey)}
                                                className="rounded-full w-16 h-16 object-cover shadow-md hover:scale-105 transition-transform duration-300"
                                                loading="lazy"
                                            />
                                        </a>
                                    </div>
 
                                    {/* Rest of the content takes full width */}
                                    <ExpandableText
                                        value={t(course.descKey)}
                                        maxLines={3}
                                        className="my-2 cursor-default"
                                    />
 
                                    <p className="text-sm text-gray-500 dark:text-gray-400 font-mono mb-2">
                                        {t("courses_page.duration")}: {t(course.durationKey)}
                                    </p>
 
                                    <Disclosure>
                                        {({open}) => (
                                            <>
                                                <Disclosure.Button
                                                    className="flex items-center text-sm text-blue-600 dark:text-blue-400 hover:underline focus:outline-none mt-2"
                                                >
                                                    <span>{t("show_technologies")}</span>
                                                    <ChevronDown
                                                        className={`ml-1 w-4 h-4 transition-transform ${
                                                            open ? "rotate-180" : ""
                                                        }`}
                                                    />
                                                </Disclosure.Button>
                                                <Disclosure.Panel
                                                    className="mt-2 text-sm text-gray-700 dark:text-gray-300">
                                                    {course.tech}
                                                </Disclosure.Panel>
                                            </>
                                        )}
                                    </Disclosure>
                                </CardContent>
 
                                {/* Desktop large image */}
                                <a
                                    href={course.link}
                                    target="_blank"
                                    rel="noopener noreferrer"
                                    className="hidden md:block shrink-0"
                                >
                                    <img
                                        src={course.image}
                                        alt={t(course.nameKey)}
                                        className="rounded-full w-48 h-48 object-cover shadow-md hover:scale-105 transition-transform duration-300"
                                        loading="lazy"
                                    />
                                </a>
                            </Card>
                        ))}
                    </motion.div>
                </AnimatePresence>
 
                {/* Pagination Controls */}
                {totalPages > 1 && (
                    <div className="flex justify-center mt-8 space-x-4">
                        <button
                            onClick={() => setPage(p => Math.max(p - 1, 1))}
                            disabled={page === 1}
                            className="px-4 py-2 border border-gray-300 dark:border-gray-600 rounded-md text-sm font-medium
                               text-gray-800 dark:text-gray-200 bg-white dark:bg-gray-900
                               hover:bg-gray-100 dark:hover:bg-gray-800 disabled:opacity-50 transition"
                        >
                            ← {t("previous")}
                        </button>
 
                        <span data-testid="pagination-info"
                              className="px-4 py-2 text-sm text-gray-600 dark:text-gray-300">
                        {page} / {totalPages}
                    </span>
 
                        <button
                            onClick={() => setPage(p => Math.min(p + 1, totalPages))}
                            disabled={page === totalPages}
                            className="px-4 py-2 border border-gray-300 dark:border-gray-600 rounded-md text-sm font-medium
                               text-gray-800 dark:text-gray-200 bg-white dark:bg-gray-900
                               hover:bg-gray-100 dark:hover:bg-gray-800 disabled:opacity-50 transition"
                        >
                            {t("next")} →
                        </button>
                    </div>
                )}
            </PageSection>
        </>
    );
}