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-02-11 21:32:46 -06:00
|
|
|
import Image from 'next/image';
|
2024-02-11 16:26:33 -06:00
|
|
|
import { useSelector } from 'react-redux';
|
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';
|
|
|
|
import { formatTimestampToHowLongAgo } from '@/utils/time';
|
2023-12-23 20:33:25 -06:00
|
|
|
|
2024-03-17 19:43:19 -05:00
|
|
|
const responsiveOptions = [
|
|
|
|
{
|
|
|
|
breakpoint: '1199px',
|
|
|
|
numVisible: 3,
|
|
|
|
numScroll: 1
|
|
|
|
},
|
|
|
|
{
|
|
|
|
breakpoint: '767px',
|
|
|
|
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 workshops = useSelector((state) => state.events.resources);
|
|
|
|
const [processedWorkshops, setProcessedWorkshops] = useState([]);
|
2024-03-18 19:32:43 -05:00
|
|
|
const [screenWidth, setScreenWidth] = useState(null);
|
2024-02-11 21:32:46 -06:00
|
|
|
const { returnImageProxy } = useImageProxy();
|
2023-12-23 20:33:25 -06:00
|
|
|
|
2024-02-27 18:29:57 -06:00
|
|
|
const router = useRouter();
|
|
|
|
|
2024-03-18 19:32:43 -05:00
|
|
|
useEffect(() => {
|
|
|
|
// Update the state to the current window width
|
|
|
|
setScreenWidth(window.innerWidth);
|
|
|
|
|
|
|
|
const handleResize = () => {
|
|
|
|
// Update the state to the new window width when it changes
|
|
|
|
setScreenWidth(window.innerWidth);
|
|
|
|
};
|
|
|
|
|
|
|
|
window.addEventListener('resize', handleResize);
|
|
|
|
|
|
|
|
// Remove the event listener on cleanup
|
|
|
|
return () => window.removeEventListener('resize', handleResize);
|
|
|
|
}, []); // The empty array ensures this effect only runs once, similar to componentDidMount
|
|
|
|
|
|
|
|
|
|
|
|
const calculateImageDimensions = () => {
|
|
|
|
if (screenWidth >= 1200) {
|
|
|
|
// Large screens
|
|
|
|
return { width: 426, height: 240 };
|
|
|
|
} else if (screenWidth >= 768 && screenWidth < 1200) {
|
|
|
|
// Medium screens
|
|
|
|
return { width: 344, height: 194 };
|
|
|
|
} else {
|
|
|
|
// Small screens
|
|
|
|
return { width: screenWidth - 50, height: (screenWidth - 50) * (9 / 16) };
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
2024-02-11 21:32:46 -06:00
|
|
|
useEffect(() => {
|
2024-03-17 16:16:47 -05:00
|
|
|
const processWorkshops = workshops.map(workshop => {
|
|
|
|
const { id, content, title, summary, image, published_at } = parseEvent(workshop);
|
2024-02-27 18:29:57 -06:00
|
|
|
return { id, content, title, summary, image, published_at };
|
2024-02-11 21:32:46 -06:00
|
|
|
});
|
2024-03-17 16:16:47 -05:00
|
|
|
setProcessedWorkshops(processWorkshops);
|
|
|
|
}, [workshops]);
|
2024-02-11 16:26:33 -06:00
|
|
|
|
2024-03-17 16:16:47 -05:00
|
|
|
const workshopTemplate = (workshop) => {
|
2024-03-18 19:32:43 -05:00
|
|
|
const { width, height } = calculateImageDimensions();
|
2023-12-23 20:33:25 -06:00
|
|
|
return (
|
2024-03-18 19:32:43 -05:00
|
|
|
<div style={{width: width < 768 ? "auto" : width}} onClick={() => router.push(`/details/${workshop.id}`)} className="flex flex-col items-center mx-auto px-4 cursor-pointer mt-8 rounded-md shadow-lg">
|
2024-03-19 11:11:23 -05:00
|
|
|
<div style={{maxWidth: width, minWidth: width}} className="max-tab:h-auto max-mob:h-auto">
|
2024-02-11 21:32:46 -06:00
|
|
|
<Image
|
|
|
|
alt="resource thumbnail"
|
2024-03-17 16:16:47 -05:00
|
|
|
src={returnImageProxy(workshop.image)}
|
2024-03-18 19:32:43 -05:00
|
|
|
quality={100}
|
|
|
|
width={width}
|
|
|
|
height={height}
|
|
|
|
className="w-full h-full object-cover object-center rounded-md"
|
2024-02-11 21:32:46 -06:00
|
|
|
/>
|
2024-03-18 19:32:43 -05:00
|
|
|
<div className='flex flex-col justify-start'>
|
|
|
|
<h4 className="mb-1 font-bold text-2xl font-blinker">{workshop.title}</h4>
|
|
|
|
<p style={{
|
|
|
|
display: '-webkit-box',
|
|
|
|
WebkitBoxOrient: 'vertical',
|
|
|
|
WebkitLineClamp: 3,
|
|
|
|
overflow: 'hidden',
|
|
|
|
textOverflow: 'ellipsis',
|
|
|
|
whiteSpace: 'prewrap',
|
|
|
|
font: '400 1rem/1.5 Blinker, sans-serif'
|
|
|
|
}}>
|
|
|
|
{workshop.summary}
|
|
|
|
</p>
|
|
|
|
<p className="text-sm mt-1 text-gray-400 font-blinker">Published: {formatTimestampToHowLongAgo(workshop.published_at)}</p>
|
|
|
|
</div>
|
2023-12-23 20:33:25 -06:00
|
|
|
</div>
|
|
|
|
</div>
|
|
|
|
);
|
2024-02-11 21:32:46 -06:00
|
|
|
};
|
2023-12-23 20:33:25 -06:00
|
|
|
|
|
|
|
return (
|
|
|
|
<>
|
2024-03-13 17:45:55 -05:00
|
|
|
<h1 className="text-2xl ml-[6%] mt-4">workshops</h1>
|
2024-03-17 19:43:19 -05:00
|
|
|
<Carousel value={processedWorkshops} numVisible={2} itemTemplate={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
|
|
|
}
|