<commit_before>import { Component, OnInit } from '@angular/core';
import { Article } from '../articles/article';
import { Http } from '@angular/http';
import { Deck } from '../decks/deck';
import { Author } from '../articles/article/author/author';
import { BASE_URL } from '../core/globals';

@Component({
    templateUrl: './home-page.component.html',
    styleUrls: ['./home-page.component.css']
})
export class HomePageComponent implements OnInit {
    featuredArticles: Article[] = [];
    tierOne: Deck[] = [];
    tierTwo: Deck[] = [];
    decksArr: Deck[][] = [];
    firstTilesColumn: Article[] = [];
    secondTilesColumn: Article[] = [];
    onlineStreamers: Author[] = [];

    constructor(private http: Http) {
    }

    ngOnInit() {
        this.setFeatured();
        this.setArticles();
        this.setDecks();
        this.setTierListDecks();
        this.setOnlineStreamers();
    }

    setFeatured(): void { // TODO move in service, handle errors in case they take place...
        this.http.get(`${BASE_URL}/api/articles/featured`).subscribe(res => {
            const articles = res.json();
            if (articles.length > 1) {
                this.featuredArticles = articles;
                this.firstTilesColumn.unshift(this.featuredArticles[1]);
                if (this.firstTilesColumn.length > 6) {
                    this.secondTilesColumn.unshift(this.firstTilesColumn.pop());
                    this.secondTilesColumn.pop();
                }
            } else {
                this.featuredArticles = articles.concat(this.featuredArticles);
            }
        });
    }

    setArticles(): void { // TODO move in service, handle errors in case they take place...
        this.http.get(`${BASE_URL}/api/articles/list?amount=12&offset=0`).subscribe(res => {
            const articles = res.json();
            if (this.firstTilesColumn.length > 1) {
                this.firstTilesColumn = this.firstTilesColumn.concat(articles.slice(0, 5));
                this.secondTilesColumn = this.secondTilesColumn.concat(articles.slice(5, 11));
            } else {
                this.featuredArticles = this.featuredArticles.concat(articles.slice(0, 1));
                this.firstTilesColumn = this.firstTilesColumn.concat(articles.slice(0, 6));
                this.secondTilesColumn = this.secondTilesColumn.concat(articles.slice(6, 12));
            }
        });
    }

    setDecks(): void { // TODO move in service, handle errors in case they take place...
        this.http.get(`${BASE_URL}/api/decks/list?amount=12&offset=0`).subscribe(res => {
            const decks = res.json();
            this.decksArr.push(decks.slice(0, 6));
            this.decksArr.push(decks.slice(6));
        });
    }

    setTierListDecks() { // TODO optimize the component for displaying them and requests...<commit_msg>fixed article showing up twice if featured<commit_after>import { Component, OnInit } from '@angular/core';
import { Article } from '../articles/article';
import { Http } from '@angular/http';
import { Deck } from '../decks/deck';
import { Author } from '../articles/article/author/author';
import { BASE_URL } from '../core/globals';

@Component({
    templateUrl: './home-page.component.html',
    styleUrls: ['./home-page.component.css']
})
export class HomePageComponent implements OnInit {
    featuredArticles: Article[] = [];
    tierOne: Deck[] = [];
    tierTwo: Deck[] = [];
    decksArr: Deck[][] = [];
    firstTilesColumn: Article[] = [];
    secondTilesColumn: Article[] = [];
    onlineStreamers: Author[] = [];
	completedFeatured: Boolean = false;

    constructor(private http: Http) {
    }

    ngOnInit() {
        this.setFeatured();
        this.setArticles();
        this.setDecks();
        this.setTierListDecks();
        this.setOnlineStreamers();
    }

    setFeatured(): void { // TODO move in service, handle errors in case they take place...
        this.http.get(`${BASE_URL}/api/articles/featured`).subscribe(res => {
            const articles = res.json();
            if (articles.length > 1) {
                this.featuredArticles = articles;
                this.firstTilesColumn.unshift(this.featuredArticles[1]);
                if (this.firstTilesColumn.length > 6) {
                    this.secondTilesColumn.unshift(this.firstTilesColumn.pop());
                    this.secondTilesColumn.pop();
                }
            } else {
                this.featuredArticles = articles.concat(this.featuredArticles);
            }
			this.completedFeatured = true;
        });
    }

    setArticles(): void { // TODO move in service, handle errors in case they take place...
        this.http.get(`${BASE_URL}/api/articles/list?amount=13&offset=0`).subscribe(res => {
            var articles = res.json();
            if (this.firstTilesColumn.length > 1) {
                this.firstTilesColumn = this.firstTilesColumn.concat(articles.slice(0, 5));
                this.secondTilesColumn = this.secondTilesColumn.concat(articles.slice(5, 11));
            } else {
				var parent = this;
				var todo = function() { 
					if (!parent.completedFeatured) {
						setTimeout(todo,200);
						return;
					}
					articles = articles.filter(art =>
						parent.featuredArticles.length == 0 || 
						art.id !== parent.featuredArticles[0].id
					);
					parent.featuredArticles = parent.featuredArticles.concat(articles.slice(0, 1));
					parent.firstTilesColumn = parent.firstTilesColumn.concat(articles.slice(0, 6));
					parent.secondTilesColumn = parent.secondTilesColumn.concat(articles.slice(6, 12));
				}
				setTimeout(todo,100);
            }
        });
    }

    setDecks(): void { // TODO move in service, handle errors in case they take place...
        this.http.get(`${BASE_URL}/api/decks/list?amount=12&offset=0`).subscribe(res => {
            const decks = res.json();
            this.decksArr.push(decks.slice(0, 6));
            this.decksArr.push(decks.slice(6));
        });
    }

    setTierListDecks() { // TODO optimize the component for displaying them and requests...
{'fraction_non_alphanumeric': 0.14363099146421537, 'fraction_numerical': 0.009520682862770847, 'mean_word_length': 2.3925389755011137, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 16, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '7641582', 'n_tokens_mistral': 1907, 'n_tokens_neox': 1752, 'n_words': 337}