plebdevs/src/components/content/carousels/WorkshopsCarousel.js

63 lines
2.1 KiB
JavaScript
Raw Normal View History

import React, { useState, useEffect } from 'react';
import { Carousel } from 'primereact/carousel';
import { useRouter } from 'next/router';
import { useNostr } from '@/hooks/useNostr';
2024-02-11 21:32:46 -06:00
import { useImageProxy } from '@/hooks/useImageProxy';
import { parseEvent } from '@/utils/nostr';
2024-03-26 18:14:32 -05:00
import WorkshopTemplate from '@/components/content/carousels/templates/WorkshopTemplate';
2024-04-22 15:46:52 -05:00
import TemplateSkeleton from '@/components/content/carousels/skeletons/TemplateSkeleton';
2024-03-17 19:43:19 -05:00
const responsiveOptions = [
{
breakpoint: '3000px',
2024-03-17 19:43:19 -05:00
numVisible: 3,
numScroll: 1
},
{
breakpoint: '1462px',
2024-03-17 19:43:19 -05:00
numVisible: 2,
numScroll: 1
},
{
breakpoint: '575px',
numVisible: 1,
numScroll: 1
}
];
2024-03-13 17:45:55 -05:00
export default function WorkshopsCarousel() {
const [processedWorkshops, setProcessedWorkshops] = useState([]);
2024-04-22 15:46:52 -05:00
const [loading, setLoading] = useState(true);
2024-04-20 16:16:22 -05:00
const { fetchWorkshops } = useNostr();
useEffect(() => {
2024-04-20 16:16:22 -05:00
const fetch = async () => {
2024-04-22 15:46:52 -05:00
setLoading(true);
2024-04-20 16:16:22 -05:00
try {
2024-04-22 15:46:52 -05:00
const fetchedWorkshops = await fetchWorkshops();
if (fetchedWorkshops && fetchedWorkshops.length > 0) {
const processed = fetchedWorkshops.map(workshop => parseEvent(workshop));
setProcessedWorkshops(processed);
} else {
console.log('No workshops fetched or empty array returned');
}
setLoading(false);
2024-04-20 16:16:22 -05:00
} catch (error) {
console.error('Error fetching workshops:', error);
2024-04-22 15:46:52 -05:00
setLoading(false);
2024-04-20 16:16:22 -05:00
}
};
fetch();
}, [fetchWorkshops]);
return (
<>
2024-04-22 15:46:52 -05:00
<h2 className="ml-[6%] mt-4">Workshops</h2>
<Carousel value={loading ? [{}, {}, {}] : [...processedWorkshops, ...processedWorkshops]}
numVisible={2}
itemTemplate={loading ? TemplateSkeleton : WorkshopTemplate}
responsiveOptions={responsiveOptions} />
</>
2024-02-11 21:32:46 -06:00
);
}