import {DSCard, PlaceholderDSCard} from "../DSCard/DSCard.jsx";
import {DSEmptyState} from "../DSEmptyState/DSEmptyState.jsx";
import React from "react";
export class CardGrid extends React.PureComponent {
renderCards() {
const recs = this.props.data.recommendations.slice(0, this.props.items);
const cards = [];
for (let index = 0; index < this.props.items; index++) {
const rec = recs[index];
cards.push(!rec || rec.placeholder ? (
) : (
));
}
let divisibility = ``;
if (this.props.items % 4 === 0) {
divisibility = `divisible-by-4`;
} else if (this.props.items % 3 === 0) {
divisibility = `divisible-by-3`;
}
return (
{cards}
);
}
render() {
const {data} = this.props;
// Handle a render before feed has been fetched by displaying nothing
if (!data) {
return null;
}
// Handle the case where a user has dismissed all recommendations
const isEmpty = data.recommendations.length === 0;
return (
{this.props.title}
{isEmpty ?
:
this.renderCards()
}
);
}
}
CardGrid.defaultProps = {
border: `border`,
items: 4, // Number of stories to display
};