Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fixes #862: Fix irrelevant results in news tab #890

Merged
merged 1 commit into from Aug 2, 2018
Merged
Changes from all commits
Commits
File filter...
Filter file types
Jump to…
Jump to file
Failed to load files.

Always

Just for now

@@ -8,7 +8,7 @@
</div>
<div class="feed-wrapper">
<div class="wrapper feed-results">
<div *ngFor="let item of newsResponse.slice(0,30); let i = index ">
<div *ngFor="let item of newsResponse; let i = index ">
<feed-card [feedItem]="item" [feedIndex]="i"></feed-card>
</div>
</div>
@@ -3,6 +3,8 @@ import { Component, OnInit, OnDestroy } from '@angular/core';
import { Store } from '@ngrx/store';
import * as fromRoot from '../../reducers';
import * as newsAction from '../../actions/news';
import { Query } from '../../models/query';
import { Observable } from 'rxjs';

@Component({
selector: 'app-feed-news',
@@ -12,20 +14,31 @@ import * as newsAction from '../../actions/news';

export class FeedNewsComponent implements OnInit, OnDestroy {
public newsResponse: ApiResponseResult[] = [];
public query: string;
public query$: Observable<Query>;

constructor(
private store: Store<fromRoot.State>
) { }

ngOnInit() {
const texts = [];
this.store.select(fromRoot.getQuery).subscribe(res => this.query = res.displayString);
this.query$ = this.store.select(fromRoot.getQuery);
this.store.select(fromRoot.getNewsResponse).subscribe(v => {
for ( let i = 0; i < v.length; i++ ) {
this.newsResponse.push(v[i]);
if (v[i]['text'].includes(this.query.replace(/\s/g, '').toLowerCase())) {
if (!texts.includes(v[i]['text'].replace(/\s/g, '').toLowerCase())) {
texts.push(v[i]['text'].replace(/\s/g, '').toLowerCase());
this.newsResponse.push(v[i]);
}
}
}
});
}

ngOnDestroy() {
this.store.dispatch(new newsAction.NewsStatusAction(false));
this.newsResponse = null;
}

}
@@ -1,4 +1,8 @@
export const newsOrgs = [
'CNN',
'nytimes'
'CNNPolitics',
'BBC',
'nytimes',
'guardian',
'toi'
];
ProTip! Use n and p to navigate between commits in a pull request.
You can’t perform that action at this time.