1 import { Component } from 'inferno';
2 import { Link } from 'inferno-router';
3 import { Post } from '../interfaces';
4 import { PostListing } from './post-listing';
5 import { i18n } from '../i18next';
7 interface PostListingsProps {
9 showCommunity?: boolean;
10 removeDuplicates?: boolean;
13 export class PostListings extends Component<PostListingsProps, any> {
14 constructor(props: any, context: any) {
15 super(props, context);
21 {this.props.posts.length > 0 ? (
22 (this.props.removeDuplicates
23 ? this.removeDuplicates(this.props.posts)
29 showCommunity={this.props.showCommunity}
31 <hr class="d-md-none my-2" />
32 <div class="d-none d-md-block my-2"></div>
37 <div>{i18n.t('no_posts')}</div>
38 {this.props.showCommunity !== undefined && (
40 <Link to="/communities">
41 {i18n.t('subscribe_to_communities')}
51 removeDuplicates(posts: Array<Post>): Array<Post> {
52 // A map from post url to list of posts (dupes)
53 let urlMap = new Map<string, Array<Post>>();
55 // Loop over the posts, find ones with same urls
56 for (let post of posts) {
61 !post.community_deleted &&
62 !post.community_removed
64 if (!urlMap.get(post.url)) {
65 urlMap.set(post.url, [post]);
67 urlMap.get(post.url).push(post);
73 // Remove the ones that have no length
74 for (let e of urlMap.entries()) {
75 if (e[1].length == 1) {
78 e[1].sort((a, b) => a.published.localeCompare(b.published));
82 for (let i = 0; i < posts.length; i++) {
85 let found = urlMap.get(post.url);
87 // If its the oldest, add
88 if (post.id == found[0].id) {
89 post.duplicates = found.slice(1);
91 // Otherwise, delete it