This repository has been archived on 2024-10-29. You can view files and clone it, but cannot push or open issues or pull requests.
FunctionProject/website/components/FunctionCard/FunctionCard.js

54 lines
2.1 KiB
JavaScript
Raw Normal View History

import Link from 'next/link';
import { useState, forwardRef } from 'react';
import date from 'date-and-time';
2020-03-21 23:03:30 +01:00
import Loader from '../Loader';
import './FunctionCard.css';
import { API_URL } from '../../utils/config';
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);
}
const isFormOrArticle = (props.type === 'form' || props.type === 'article');
2020-03-21 16:43:37 +01:00
return (
<Link
{
...(props.isAdmin) ?
{
href: "/admin/[slug]",
as: `/admin/${props.slug}`
}
:
{
href: (isFormOrArticle) ? "/functions/[slug]" : `/functions/${props.slug}`,
as: `/functions/${props.slug}`
}
}
>
{/* FunctionCard a une hauteur pendant chargement */}
<div ref={ref} style={isLoading ? { height: "360px", justifyContent: "center" } : null} className={"FunctionCard col-sm-24 col-md-10 col-xl-7"}>
{isLoading && <Loader width="125px" height="125px" />}
<div className={`FunctionCard__container ${isLoading ? "d-none" : ""}`}>
<div className="FunctionCard__top">
<img onLoad={handleLoad} className="FunctionCard__image" alt={props.title} src={API_URL + props.image} />
<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.categorie.color }}>{props.categorie.name}</p>
<p className="FunctionCard__publication-date">{date.format(new Date(props.createdAt), 'DD/MM/YYYY', true)}</p>
2020-03-21 16:43:37 +01:00
</div>
</div>
</div>
2020-03-21 16:43:37 +01:00
</Link>
);
});
export default FunctionCard;