From 4fb258211dcc522e54ee2e1bacc430e974bd8906 Mon Sep 17 00:00:00 2001 From: austinkelsay Date: Tue, 18 Mar 2025 13:41:20 -0500 Subject: [PATCH 1/2] Grid based layout for resource cards using tailwind instead of using primereat carousel component, this fixed the bug --- .../content/carousels/GenericCarousel.js | 96 +++++-------------- 1 file changed, 23 insertions(+), 73 deletions(-) diff --git a/src/components/content/carousels/GenericCarousel.js b/src/components/content/carousels/GenericCarousel.js index e905170..9234a8f 100644 --- a/src/components/content/carousels/GenericCarousel.js +++ b/src/components/content/carousels/GenericCarousel.js @@ -1,34 +1,14 @@ -import React, { useState, useEffect, useCallback, useMemo } from 'react'; +import React, { useState, useEffect } from 'react'; import axios from 'axios'; -import { Carousel } from 'primereact/carousel'; import TemplateSkeleton from '@/components/content/carousels/skeletons/TemplateSkeleton'; import { VideoTemplate } from '@/components/content/carousels/templates/VideoTemplate'; import { DocumentTemplate } from '@/components/content/carousels/templates/DocumentTemplate'; import { CourseTemplate } from '@/components/content/carousels/templates/CourseTemplate'; import { CombinedTemplate } from '@/components/content/carousels/templates/CombinedTemplate'; -import debounce from 'lodash/debounce'; - -const responsiveOptions = [ - { - breakpoint: '3000px', - numVisible: 3, - }, - { - breakpoint: '1462px', - numVisible: 2, - }, - { - breakpoint: '575px', - numVisible: 1, - } -]; export default function GenericCarousel({items, selectedTopic, title}) { - const [carousels, setCarousels] = useState([]); const [lessons, setLessons] = useState([]); - const memoizedItems = useMemo(() => items, [items]); - useEffect(() => { axios.get('/api/lessons').then(res => { if (res.data) { @@ -41,60 +21,30 @@ export default function GenericCarousel({items, selectedTopic, title}) { }); }, []); - const getItemsPerCarousel = useCallback(() => { - const width = window.innerWidth; - if (width <= 575) return 1; - if (width <= 1462) return 2; - return 3; - }, []); - - const updateCarousels = useCallback(() => { - const itemsPerCarousel = getItemsPerCarousel(); - const newCarousels = []; - for (let i = 0; i < memoizedItems.length; i += itemsPerCarousel) { - newCarousels.push(memoizedItems.slice(i, i + itemsPerCarousel)); + const renderItem = (item) => { + if (!item) return ; + + if (item.topics?.includes('video') && item.topics?.includes('document')) { + return ; + } else if (item.type === 'document') { + return ; + } else if (item.type === 'video') { + return ; + } else if (item.type === 'course') { + return ; } - setCarousels(newCarousels); - }, [memoizedItems, getItemsPerCarousel]); - - useEffect(() => { - updateCarousels(); - const debouncedHandleResize = debounce(updateCarousels, 250); - window.addEventListener('resize', debouncedHandleResize); - - return () => { - window.removeEventListener('resize', debouncedHandleResize); - }; - }, [updateCarousels, memoizedItems]); + return ; + }; return ( - <> - {carousels.map((carouselItems, index) => ( - { - if (carouselItems.length > 0) { - if (item.topics?.includes('video') && item.topics?.includes('document')) { - return ; - } else if (item.type === 'document') { - return ; - } else if (item.type === 'video') { - return ; - } else if (item.type === 'course') { - return ; - } - } - return ; - }} - responsiveOptions={responsiveOptions} - className="mb-4" - pt={{ - previousButton: { className: 'hidden' }, - nextButton: { className: 'hidden' } - }} - /> - ))} - +
+
+ {items.map((item, index) => ( +
+ {renderItem(item)} +
+ ))} +
+
); } From 247b66f04ecb9b1e3d3df879a8e64211df040316 Mon Sep 17 00:00:00 2001 From: austinkelsay Date: Tue, 18 Mar 2025 16:18:51 -0500 Subject: [PATCH 2/2] Ensure unique keys for resource templates --- .../content/carousels/GenericCarousel.js | 39 ++++++++++++++----- 1 file changed, 30 insertions(+), 9 deletions(-) diff --git a/src/components/content/carousels/GenericCarousel.js b/src/components/content/carousels/GenericCarousel.js index 9234a8f..42da495 100644 --- a/src/components/content/carousels/GenericCarousel.js +++ b/src/components/content/carousels/GenericCarousel.js @@ -21,27 +21,48 @@ export default function GenericCarousel({items, selectedTopic, title}) { }); }, []); - const renderItem = (item) => { - if (!item) return ; + const generateUniqueTemplateKey = (item, index, type) => { + if (!item) return `${type}-${index}`; + const baseKey = item.id || item.d || `${type}-${index}`; + return `${type}-${baseKey}-${index}`; + }; + + const renderItem = (item, index) => { + if (!item) return ; if (item.topics?.includes('video') && item.topics?.includes('document')) { - return ; + return ; } else if (item.type === 'document') { - return ; + return ; } else if (item.type === 'video') { - return ; + return ; } else if (item.type === 'course') { - return ; + return ; } - return ; + return ; }; return (
{items.map((item, index) => ( -
- {renderItem(item)} +
+ {renderItem(item, index)}
))}