You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
50 lines
1.4 KiB
50 lines
1.4 KiB
import { sliderTitles } from '@app/components/Discover/constants';
|
|
import RequestCard from '@app/components/RequestCard';
|
|
import Slider from '@app/components/Slider';
|
|
import { ArrowRightCircleIcon } from '@heroicons/react/24/outline';
|
|
import type { RequestResultsResponse } from '@server/interfaces/api/requestInterfaces';
|
|
import Link from 'next/link';
|
|
import { useIntl } from 'react-intl';
|
|
import useSWR from 'swr';
|
|
|
|
const RecentRequestsSlider = () => {
|
|
const intl = useIntl();
|
|
const { data: requests, error: requestError } =
|
|
useSWR<RequestResultsResponse>(
|
|
'/api/v1/request?filter=all&take=10&sort=modified&skip=0',
|
|
{
|
|
revalidateOnMount: true,
|
|
}
|
|
);
|
|
|
|
if (requests && requests.results.length === 0 && !requestError) {
|
|
return null;
|
|
}
|
|
|
|
return (
|
|
<>
|
|
<div className="slider-header">
|
|
<Link href="/requests?filter=all">
|
|
<a className="slider-title">
|
|
<span>{intl.formatMessage(sliderTitles.recentrequests)}</span>
|
|
<ArrowRightCircleIcon />
|
|
</a>
|
|
</Link>
|
|
</div>
|
|
<Slider
|
|
sliderKey="requests"
|
|
isLoading={!requests}
|
|
items={(requests?.results ?? []).map((request) => (
|
|
<RequestCard
|
|
key={`request-slider-item-${request.id}`}
|
|
request={request}
|
|
/>
|
|
))}
|
|
placeholder={<RequestCard.Placeholder />}
|
|
/>
|
|
</>
|
|
);
|
|
};
|
|
|
|
export default RecentRequestsSlider;
|