2020-03-19 16:13:51 +01:00
|
|
|
import Link from 'next/link';
|
2020-03-21 20:48:46 +01:00
|
|
|
import { useState, forwardRef } from 'react';
|
2020-03-21 23:03:30 +01:00
|
|
|
import Loader from '../Loader';
|
2020-03-19 16:13:51 +01:00
|
|
|
import './FunctionCard.css';
|
2020-03-24 09:54:50 +01:00
|
|
|
import { API_URL } from '../../utils/config';
|
2020-03-19 16:13:51 +01:00
|
|
|
|
2020-03-21 18:24:10 +01:00
|
|
|
const FunctionCard = forwardRef((props, ref) => {
|
2020-03-21 16:43:37 +01:00
|
|
|
|
|
|
|
const [isLoading, setIsLoading] = useState(true);
|
|
|
|
|
|
|
|
const handleLoad = () => {
|
|
|
|
setIsLoading(false);
|
|
|
|
}
|
|
|
|
|
2020-03-23 14:42:26 +01:00
|
|
|
const isFormOrArticle = (props.type === 'form' || props.type === 'article');
|
|
|
|
|
2020-03-21 16:43:37 +01:00
|
|
|
return (
|
2020-03-21 23:54:08 +01:00
|
|
|
<Link
|
2020-03-23 14:42:26 +01:00
|
|
|
href={isFormOrArticle ? "/functions/[slug]" : `/functions/${props.slug}`}
|
2020-03-21 23:54:08 +01:00
|
|
|
as={`/functions/${props.slug}`}
|
|
|
|
>
|
|
|
|
{/* FunctionCard a une hauteur pendant chargement */}
|
2020-03-21 20:48:46 +01:00
|
|
|
<div ref={ref} style={isLoading ? { height: "360px", justifyContent: "center" } : null} className={"FunctionCard col-sm-24 col-md-10 col-xl-7"}>
|
2020-03-21 23:54:08 +01:00
|
|
|
|
2020-03-21 20:48:46 +01:00
|
|
|
{isLoading && <Loader width="125px" height="125px" />}
|
2020-03-21 23:54:08 +01:00
|
|
|
|
2020-03-21 20:48:46 +01:00
|
|
|
<div className={`FunctionCard__container ${isLoading ? "d-none" : ""}`}>
|
|
|
|
<div className="FunctionCard__top">
|
2020-03-23 14:42:26 +01:00
|
|
|
<img onLoad={handleLoad} className="FunctionCard__image" alt={props.title} src={API_URL + props.image} />
|
2020-03-21 20:48:46 +01:00
|
|
|
<h2 className="FunctionCard__title">{props.title}</h2>
|
|
|
|
<p className="FunctionCard__description">{props.description}</p>
|
|
|
|
</div>
|
|
|
|
<div className="FunctionCard__info">
|
|
|
|
<p className="FunctionCard__category" style={{ backgroundColor: props.category.color }}>{props.category.name}</p>
|
|
|
|
<p className="FunctionCard__publication-date">{props.publicationDate}</p>
|
2020-03-21 16:43:37 +01:00
|
|
|
</div>
|
|
|
|
</div>
|
2020-03-21 20:48:46 +01:00
|
|
|
</div>
|
2020-03-21 16:43:37 +01:00
|
|
|
</Link>
|
|
|
|
);
|
2020-03-21 18:24:10 +01:00
|
|
|
})
|
2020-03-19 16:13:51 +01:00
|
|
|
|
|
|
|
export default FunctionCard;
|