ReactJS
1import React from 'react';
2import styles from './cardlist.css';
3import {Card, ICardProps} from "./Card";
4import {postsContext} from "../context/PostsContext";
5import moment from "moment";
6
7export function CardList() {
8const posts = React.useContext(postsContext);
9const shortPosts = posts.map(x => {
10let shortPostInfo: ICardProps = {
11id: x.id,
12post: {
13url: "#Post_URL",
14author: {
15name: x.author,
16avatarUrl: "https://www.redditinc.com/assets/images/site/reddit-logo.png",
17profileLink: "#USER_LINK"
18},
19crDate: moment(x.created).format("DD-mm-YYYY HH:mm"),
20title: x.title
21},
22previewImageUrl: !x.thumbnail.includes("http") ? "https://kluban.net/wp-content/uploads/2015/05/blank-thumbnail.jpg" : x.thumbnail
23};
24return shortPostInfo;
25})
26
27
28return (
29<ul className={styles.cardList}>
30{shortPosts.map(x => <Card id={x.id} key={x.id} post={x.post} previewImageUrl={x.previewImageUrl}/>)}
31</ul>
32);
33}
34