plebdevs/src/components/resources/ResourcesCarousel.js

55 lines
2.3 KiB
JavaScript
Raw Normal View History

import React, { useState, useEffect } from 'react';
import { Button } from 'primereact/button';
import { Carousel } from 'primereact/carousel';
2024-02-11 21:32:46 -06:00
import Image from 'next/image';
import { useSelector } from 'react-redux';
2024-02-11 21:32:46 -06:00
import { useImageProxy } from '@/hooks/useImageProxy';
import { parseResourceEvent } from '@/utils/nostr';
2024-02-11 21:32:46 -06:00
import { formatUnixTimestamp } from '@/utils/time';
export default function ResourcesCarousel() {
const resources = useSelector((state) => state.events.resources);
2024-02-11 21:32:46 -06:00
const [processedResources, setProcessedResources] = useState([]);
const { returnImageProxy } = useImageProxy();
2024-02-11 21:32:46 -06:00
useEffect(() => {
const processResources = resources.map(resource => {
const { content, title, summary, image, published_at } = parseResourceEvent(resource);
return { content, title, summary, image, published_at };
});
setProcessedResources(processResources);
}, [resources]);
const resourceTemplate = (resource) => {
return (
<div className="flex flex-col items-center w-full px-4">
<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"
/>
</div>
<div className='text-center'>
2024-02-11 21:32:46 -06:00
<h4 className="mb-1 font-bold text-center">{resource.title}</h4>
<p className="text-center">{resource.summary}</p>
<div className="flex flex-row items-center justify-center gap-2">
<Button icon="pi pi-search" rounded />
<Button icon="pi pi-star-fill" rounded severity="success" />
</div>
2024-02-11 21:32:46 -06:00
<p className="text-center mt-2">Published: {formatUnixTimestamp(resource.published_at)}</p>
</div>
</div>
);
2024-02-11 21:32:46 -06:00
};
return (
<>
<h1 className="text-2xl font-bold ml-[6%] my-4">Resources</h1>
2024-02-11 21:32:46 -06:00
<Carousel value={processedResources} numVisible={3} itemTemplate={resourceTemplate} />
</>
2024-02-11 21:32:46 -06:00
);
}