2023-12-23 20:33:25 -06:00
|
|
|
import React, { useState, useEffect } from 'react';
|
|
|
|
import { Carousel } from 'primereact/carousel';
|
2024-02-27 18:29:57 -06:00
|
|
|
import { useRouter } from 'next/router';
|
2024-03-19 17:47:16 -05:00
|
|
|
import { useNostr } from '@/hooks/useNostr';
|
2024-02-11 21:32:46 -06:00
|
|
|
import { useImageProxy } from '@/hooks/useImageProxy';
|
2024-02-27 18:29:57 -06:00
|
|
|
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';
|
2023-12-23 20:33:25 -06:00
|
|
|
|
2024-03-17 19:43:19 -05:00
|
|
|
const responsiveOptions = [
|
|
|
|
{
|
2024-03-19 12:32:05 -05:00
|
|
|
breakpoint: '3000px',
|
2024-03-17 19:43:19 -05:00
|
|
|
numVisible: 3,
|
|
|
|
numScroll: 1
|
|
|
|
},
|
|
|
|
{
|
2024-03-19 12:32:05 -05:00
|
|
|
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() {
|
2024-03-17 16:16:47 -05:00
|
|
|
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();
|
2023-12-23 20:33:25 -06:00
|
|
|
|
2024-03-19 17:47:16 -05:00
|
|
|
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]);
|
2024-02-27 18:29:57 -06:00
|
|
|
|
2023-12-23 20:33:25 -06:00
|
|
|
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} />
|
2023-12-23 20:33:25 -06:00
|
|
|
</>
|
2024-02-11 21:32:46 -06:00
|
|
|
);
|
2023-12-23 20:33:25 -06:00
|
|
|
}
|