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-13 17:45:55 -05:00
|
|
|
export default function WorkshopsCarousel() {
|
2024-02-11 16:26:33 -06:00
|
|
|
const resources = useSelector((state) => state.events.resources);
|
2024-03-16 14:56:58 -05:00
|
|
|
console.log(resources);
|
2024-02-11 21:32:46 -06:00
|
|
|
const [processedResources, setProcessedResources] = useState([]);
|
|
|
|
const { returnImageProxy } = useImageProxy();
|
2023-12-23 20:33:25 -06:00
|
|
|
|
2024-02-27 18:29:57 -06:00
|
|
|
const router = useRouter();
|
|
|
|
|
2024-02-11 21:32:46 -06:00
|
|
|
useEffect(() => {
|
|
|
|
const processResources = resources.map(resource => {
|
2024-02-27 18:29:57 -06:00
|
|
|
const { id, content, title, summary, image, published_at } = parseEvent(resource);
|
|
|
|
return { id, content, title, summary, image, published_at };
|
2024-02-11 21:32:46 -06:00
|
|
|
});
|
|
|
|
setProcessedResources(processResources);
|
|
|
|
}, [resources]);
|
2024-02-11 16:26:33 -06:00
|
|
|
|
|
|
|
const resourceTemplate = (resource) => {
|
2023-12-23 20:33:25 -06:00
|
|
|
return (
|
2024-03-16 14:56:58 -05:00
|
|
|
<div onClick={() => router.push(`/details/${resource.id}`)} className="flex flex-col items-center w-full px-4 cursor-pointer mt-8">
|
2023-12-23 20:33:25 -06:00
|
|
|
<div className="w-86 h-60 bg-gray-200 overflow-hidden rounded-md shadow-lg">
|
2024-02-11 21:32:46 -06:00
|
|
|
<Image
|
|
|
|
alt="resource thumbnail"
|
|
|
|
src={returnImageProxy(resource.image)}
|
|
|
|
width={344}
|
|
|
|
height={194}
|
|
|
|
className="w-full h-full object-cover object-center"
|
|
|
|
/>
|
2023-12-23 20:33:25 -06:00
|
|
|
</div>
|
2024-02-27 18:29:57 -06:00
|
|
|
<div className='flex flex-col justify-start w-[426px]'>
|
|
|
|
<h4 className="mb-1 font-bold text-xl">{resource.title}</h4>
|
|
|
|
<p className='truncate'>{resource.summary}</p>
|
|
|
|
<p className="text-sm mt-1 text-gray-400">Published: {formatTimestampToHowLongAgo(resource.published_at)}</p>
|
|
|
|
{/* <div className="flex flex-row items-center justify-center gap-2">
|
2023-12-23 20:33:25 -06:00
|
|
|
<Button icon="pi pi-search" rounded />
|
|
|
|
<Button icon="pi pi-star-fill" rounded severity="success" />
|
2024-02-27 18:29:57 -06:00
|
|
|
</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-02-11 21:32:46 -06:00
|
|
|
<Carousel value={processedResources} numVisible={3} itemTemplate={resourceTemplate} />
|
2023-12-23 20:33:25 -06:00
|
|
|
</>
|
2024-02-11 21:32:46 -06:00
|
|
|
);
|
2023-12-23 20:33:25 -06:00
|
|
|
}
|