Skip to content

Commit 0b8eaaf

Browse files
committed
v2.0
1 parent b5e4698 commit 0b8eaaf

2 files changed

Lines changed: 68 additions & 3 deletions

File tree

495 KB
Loading

src/Page/ResoucesHub/Courseslist.jsx

Lines changed: 68 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import React, { useState } from 'react';
1+
import React, { useState, useEffect } from 'react';
22
import styled from 'styled-components';
33
import { FontAwesomeIcon } from '@fortawesome/react-fontawesome';
44
import { faGraduationCap, faUser, faClock, faShareAlt } from '@fortawesome/free-solid-svg-icons';
@@ -161,6 +161,18 @@ const courses = [
161161
courseLink: 'https://youtu.be/ZxKM3DCV2kE?si=kF4sGU0z-RREMgps',
162162
shareLink: '#fullstackbymehul',
163163
},
164+
{
165+
platform: 'Udemy',
166+
title: 'Complete Full-Stack Web Development - English',
167+
instructor: 'Dr. Angela Yu',
168+
duration: '61 hours',
169+
level: 'Intermediate',
170+
domain: ['Web Development', 'Full Stack', 'Backend', 'Frontend', 'Database', 'Paid'],
171+
poster: '/assets/Courses/AngelaFullStackDev.png',
172+
courseLink:
173+
'https://www.udemy.com/share/1013gG3@EyR3Dc5QwlywZjfRg5cHgciPWEKlVbAonImXoDW1aBzlAAnzWsIzUNDkI4O0oY07PA==/',
174+
shareLink: '#fullstackbyangela',
175+
},
164176
// Add more courses similarly...
165177
];
166178

@@ -389,12 +401,41 @@ const FilterContainer = styled.div`
389401
}
390402
`;
391403

404+
const skillFilters = ['HTML', 'CSS', 'JavaScript', 'Python', 'React'];
405+
392406
const CoursesList = () => {
393407
const [platformFilter, setPlatformFilter] = useState('');
394408
const [instructorFilter, setInstructorFilter] = useState('');
395409
const [domainFilter, setDomainFilter] = useState('');
410+
const [skillFilter, setSkillFilter] = useState('');
411+
const [shuffledCourses, setShuffledCourses] = useState([]);
412+
413+
// Function to shuffle the courses array
414+
const shuffleArray = (array) => {
415+
return array
416+
.map((item) => ({ ...item, sortKey: Math.random() }))
417+
.sort((a, b) => a.sortKey - b.sortKey)
418+
.map(({ sortKey, ...item }) => item);
419+
};
396420

397-
const filteredCourses = courses.filter((course) => {
421+
// Shuffle courses on component mount and every 5 seconds if no filter is active
422+
useEffect(() => {
423+
if (!platformFilter && !instructorFilter && !domainFilter && !skillFilter) {
424+
setShuffledCourses(shuffleArray(courses));
425+
426+
const interval = setInterval(() => {
427+
setShuffledCourses(shuffleArray(courses));
428+
}, 9000);
429+
430+
// Cleanup interval on component unmount
431+
return () => clearInterval(interval);
432+
} else {
433+
// If a filter is active, show the original filtered courses
434+
setShuffledCourses(courses);
435+
}
436+
}, [platformFilter, instructorFilter, domainFilter, skillFilter]);
437+
438+
const filteredCourses = shuffledCourses.filter((course) => {
398439
const matchesPlatform = platformFilter
399440
? course.platform.toLowerCase().includes(platformFilter.toLowerCase())
400441
: true;
@@ -407,7 +448,9 @@ const CoursesList = () => {
407448
? course.domain.some((d) => d.toLowerCase().includes(domainFilter.toLowerCase()))
408449
: true;
409450

410-
return matchesPlatform && matchesInstructor && matchesDomain;
451+
const matchesSkill = skillFilter ? course.domain.some((d) => d.toLowerCase() === skillFilter.toLowerCase()) : true;
452+
453+
return matchesPlatform && matchesInstructor && matchesDomain && matchesSkill;
411454
});
412455

413456
return (
@@ -436,6 +479,28 @@ const CoursesList = () => {
436479
/>
437480
</FilterContainer>
438481

482+
<div className="mb-4 flex justify-center gap-2">
483+
{skillFilters.map((skill) => (
484+
<button
485+
key={skill}
486+
onClick={() => setSkillFilter(skill)}
487+
className={`rounded-full border border-[#00a6fb] px-2 py-1 text-xs ${
488+
skillFilter === skill ? 'bg-[#00a6fb] text-white' : 'bg-gray-1000 text-[#00a6fb]'
489+
} transition hover:bg-[#00a6fb] hover:text-white`}
490+
>
491+
{skill}
492+
</button>
493+
))}
494+
{skillFilter && (
495+
<button
496+
onClick={() => setSkillFilter('')}
497+
className="rounded-full border bg-red-500 px-2 py-1 text-xs text-white transition hover:bg-red-600"
498+
>
499+
Clear Filter
500+
</button>
501+
)}
502+
</div>
503+
439504
<CoursesListContainer className="flex flex-wrap justify-center">
440505
{filteredCourses.length > 0 ? (
441506
filteredCourses.map((course, idx) => <CoursesCardComponent key={idx} {...course} />)

0 commit comments

Comments
 (0)