Skip to content

Commit

Permalink
Merge branch 'development' into pushapi
Browse files Browse the repository at this point in the history
  • Loading branch information
simsausaurabh committed Jun 19, 2018
2 parents acde62f + 59c45b7 commit 8438050
Show file tree
Hide file tree
Showing 13 changed files with 99 additions and 140 deletions.
22 changes: 1 addition & 21 deletions src/app/effects/api-search.effects.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
import { Injectable } from '@angular/core';
import { Location } from '@angular/common';
import { Title } from '@angular/platform-browser';
import { Store, Action } from '@ngrx/store';
import { Effect, Actions, ofType } from '@ngrx/effects';
import { Observable, of } from 'rxjs';
Expand Down Expand Up @@ -206,31 +205,12 @@ export class ApiSearchEffects {
})
);

@Effect({ dispatch: false })
resetTitleAfterWallSearchSuccess$: Observable<void> = this.actions$
.pipe(
ofType(
apiAction.ActionTypes.WALL_SEARCH_COMPLETE_SUCCESS,
apiAction.ActionTypes.WALL_SEARCH_COMPLETE_FAIL
),
withLatestFrom(this.store$),
map(([action, state]) => {
const displayString = state.mediaWallQuery.query.displayString;
let title = `${displayString} - Loklak Media Wall`;
if (action.type === apiAction.ActionTypes.WALL_SEARCH_COMPLETE_FAIL) {
title += ' - No Results';
}
this.titleService.setTitle(title);
})
);

constructor(
private store$: Store<fromRoot.State>,
private actions$: Actions,
private apiSearchService: SearchService,
private pushService: PushService,
private location: Location,
private titleService: Title
private location: Location
) { }

}
15 changes: 2 additions & 13 deletions src/app/feed/feed.component.html
Original file line number Diff line number Diff line change
Expand Up @@ -29,27 +29,16 @@
[apiResponseTags]="(apiResponseTags$ | async)"></feed-footer>
</div>
<div *ngIf="(areResultsAvailable$ | async)" class="wrapper feed-info-box">
<info-box *ngIf="!(areUserResultsValid$ | async)"
<info-box
[query] = "(query$ | async)"
[apiResponseAggregations]="(apiResponseAggregations$ | async)"></info-box>
[ApiResponseResult]="(apiResponseResults$ | async)"></info-box>
<user-info-box
*ngIf="(areUserResultsValid$ | async)"
[apiResponseUser] = "(apiResponseUser$ | async)"
[apiResponseUserFollowing] = "apiResponseUserFollowing$ | async"
[apiResponseUserFollowers] = "apiResponseUserFollowers$ | async"
[isUserResponseLoading]= "(isUserInfoSearching$ | async)"></user-info-box>
</div>
<div class="top-hashtags wrapper" *ngIf="(apiResponseHashtags$ | async).length !== 0">
<div class="row link-sidebar-container">
<B>Trends for you</B>
<div class="inner-text">
<span *ngFor ="let item of ((apiResponseHashtags$ | async).slice(0,10));">
<a [routerLink]="['/search']"
[queryParams]="{ query : '#' + item.tag }">#{{item.tag}}</a><br>
</span>
</div>
</div>
</div>
<div class="results-not-found"
*ngIf="!(areResultsAvailable$ | async) &&
((query$ | async).displayString) &&
Expand Down
28 changes: 1 addition & 27 deletions src/app/feed/feed.component.spec.ts
Original file line number Diff line number Diff line change
@@ -1,9 +1,7 @@
/* tslint:disable:no-unused-variable */

import { Component, Input, Output, EventEmitter } from '@angular/core';
import { ActivatedRoute } from '@angular/router';
import { TestBed, async } from '@angular/core/testing';
import { Route } from '@angular/router';
import { ReactiveFormsModule, FormControl } from '@angular/forms';
import { RouterTestingModule } from '@angular/router/testing';
import {
Expand All @@ -20,8 +18,6 @@ import { StoreModule } from '@ngrx/store';

import { Observable } from 'rxjs';

import { reducers } from '../reducers';
import { RouterStub } from '../../testing';
import { FeedComponent } from './feed.component';
import { ApiResponseResult } from '../models/api-response';
import { SpeechService } from '../services/speech.service';
Expand Down Expand Up @@ -98,7 +94,7 @@ class FeedLinkerStubComponent {
})
class InfoBoxStubComponent {
@Input() private query;
@Input() private apiResponseAggregations;
@Input() private apiResponseResult;
}

@Component({
Expand Down Expand Up @@ -165,26 +161,4 @@ describe('Component: Feed', () => {
});
});

it('should create an instance', async(() => {
const fixture = TestBed.createComponent(FeedComponent);
const component = fixture.debugElement.componentInstance;
expect(component).toBeTruthy();
}));

it('should have a feed-header component', async(() => {
const fixture = TestBed.createComponent(FeedComponent);
const component = fixture.debugElement.componentInstance;
const compiled = fixture.debugElement.nativeElement;

expect(compiled.querySelector('feed-header')).toBeTruthy();
}));

it('should have an app-footer component', async(() => {
const fixture = TestBed.createComponent(FeedComponent);
const component = fixture.debugElement.componentInstance;
const compiled = fixture.debugElement.nativeElement;

expect(compiled.querySelector('app-footer')).toBeTruthy();
}));

});
17 changes: 1 addition & 16 deletions src/app/feed/feed.component.ts
Original file line number Diff line number Diff line change
Expand Up @@ -59,18 +59,13 @@ export class FeedComponent implements OnInit, AfterViewInit, OnDestroy {
public isSuggestLoading$: Observable<boolean>;
public suggestResponse$: Observable<SuggestResults[]>;

public apiResponseHashtags$: Observable<Array<{ tag: string, count: number }>>;

constructor(
private route: ActivatedRoute,
private location: Location,
private store: Store<fromRoot.State>,
private elementRef: ElementRef,
@Inject(DOCUMENT) private document: Document
) {
this.getTopHashtags();
this.getHashtagDataFromStore();
}
) { }

ngOnInit() {
this.queryFromURL();
Expand All @@ -81,15 +76,6 @@ export class FeedComponent implements OnInit, AfterViewInit, OnDestroy {
this.focusTextbox();
}

getTopHashtags() {
this.store.dispatch(new queryAction.RelocationAfterQueryResetAction());
this.store.dispatch(new queryAction.InputValueChangeAction('since:day'));
}

getHashtagDataFromStore() {
this.apiResponseHashtags$ = this.store.select(fromRoot.getApiResponseTags);
}

/**
* Focus the search box on the `Loading` of the Feedpage.
*/
Expand Down Expand Up @@ -144,7 +130,6 @@ export class FeedComponent implements OnInit, AfterViewInit, OnDestroy {
this.isNextPageLoading$ = this.store.select(fromRoot.getPageLoading);
this.areMorePagesAvailable$ = this.store.select(fromRoot.getPagesAvailable);
this.apiResponseAggregations$ = this.store.select(fromRoot.getApiAggregations);

this.isUserInfoSearching$ = this.store.select(fromRoot.getUserSearchLoading);
this.areUserResultsValid$ = this.store.select(fromRoot.getAreApiUserResultsValid);
this.apiResponseUser$ = this.store.select(fromRoot.getApiUserResponse);
Expand Down
12 changes: 6 additions & 6 deletions src/app/feed/info-box/info-box.component.html
Original file line number Diff line number Diff line change
Expand Up @@ -10,10 +10,10 @@ <h4>Top Twitterers</h4>
<tr class="leaderboard-item" *ngFor="let item of topTwitterers">
<td>
<img src="https://twitter.com/{{item[0]}}/profile_image?size=normal" alt="{{item[0]}}" *ngIf="inviewporttwitters">
<span class="label leaderboard-label">{{item[1]}}</span>
<span class="label leaderboard-label">{{item[1].length}}</span>
</td>
<td class="leaderboard-text">
<a [routerLink]="['/search']" [queryParams]="{ query : 'from:' + item[0] }">@{{item[0]}}</a>
<a [routerLink]="['/search']" [queryParams]="{ query : 'from:' + item[1] }">@{{item[1]}}</a>
</td>
</tr>
</tbody>
Expand All @@ -25,10 +25,10 @@ <h4>Top Hashtags</h4>
<tbody>
<tr class="leaderboard-item" *ngFor ="let item of topHashtags">
<td>
<div class="leaderboard-count">{{item[1]}}</div>
<div class="leaderboard-count">{{item[1][0].length}}</div>
</td>
<td class="leaderboard-text">
<a [routerLink]="['/search']" [queryParams]="{ query : '#' + item[0] }">#{{item[0]}}</a>
<a [routerLink]="['/search']" [queryParams]="{ query : '#' + item[1][0] }">#{{item[1][0]}}</a>
</td>
</tr>
</tbody>
Expand All @@ -43,10 +43,10 @@ <h4>Top Mentions</h4>
<tr class="leaderboard-item" *ngFor="let item of topMentions">
<td>
<img src="https://twitter.com/{{item[0]}}/profile_image?size=normal" alt="" *ngIf="inviewportmentions">
<span class="label leaderboard-label">{{item[1]}}</span>
<span class="label leaderboard-label">{{item[1][0].length}}</span>
</td>
<td class="leaderboard-text">
<a [routerLink]="['/search']" [queryParams]="{ query : 'from:' + item[0] }">@{{item[0]}}</a>
<a [routerLink]="['/search']" [queryParams]="{ query : 'from:' + item[1][0] }">@{{item[1][0]}}</a>
</td>
</tr>
</tbody>
Expand Down
75 changes: 51 additions & 24 deletions src/app/feed/info-box/info-box.component.ts
Original file line number Diff line number Diff line change
@@ -1,9 +1,8 @@
import { ApiResponseResult } from './../../models/api-response';
import { Component, OnInit, OnChanges, Input } from '@angular/core';
import { Store } from '@ngrx/store';
import { Observable } from 'rxjs';
import * as fromRoot from '../../reducers';
import * as apiAction from '../../actions/api';
import { ApiResponseAggregations } from '../../models/api-response';
import { Query } from '../../models';

@Component({
Expand All @@ -13,7 +12,7 @@ import { Query } from '../../models';
})
export class InfoBoxComponent implements OnInit, OnChanges {
@Input() public query: Query;
@Input() public apiResponseAggregations: ApiResponseAggregations;
@Input() public ApiResponseResult: ApiResponseResult[];
public inviewporttwitters: Observable<boolean>;
public inviewportmentions: Observable<boolean>;
public areTopHashtagsAvailable: boolean;
Expand All @@ -40,18 +39,15 @@ export class InfoBoxComponent implements OnInit, OnChanges {
ngOnInit() { }

ngOnChanges() {
this.sortHashtags(this.apiResponseAggregations);
this.sortTwiterers(this.apiResponseAggregations);
this.sortMentions(this.apiResponseAggregations);
this.getChartData(this.apiResponseAggregations);
this.parseApiResponseData();
}
sortHashtags(statistics) {
let sortable = [];
/* A check for both the data and the individual objects is necessary, also if the data is not empty*/
if ((statistics && statistics.hashtags !== undefined) && Object.keys(statistics.hashtags).length !== 0) {
for (const s in statistics.hashtags) {
if (statistics !== undefined && statistics.length !== 0) {
for (const s in statistics) {
if (s) {
sortable.push([s, statistics.hashtags[s]]);
sortable.push([s, statistics[s]]);
}
}
sortable.sort(function (a, b) {
Expand All @@ -70,10 +66,11 @@ export class InfoBoxComponent implements OnInit, OnChanges {
}
sortTwiterers(statistics) {
let sortable = [];
if ((statistics && statistics.screen_name) !== undefined && (Object.keys(statistics.screen_name).length) !== 0) {
for (const s in statistics.screen_name) {
statistics = statistics.filter((el, i, a) => i === a.indexOf(el));
if (statistics !== undefined && statistics.length !== 0) {
for (const s in statistics) {
if (s) {
sortable.push([s, statistics.screen_name[s]]);
sortable.push([s, statistics[s]]);
}
}
sortable.sort(function (a, b) {
Expand All @@ -92,10 +89,11 @@ export class InfoBoxComponent implements OnInit, OnChanges {
}
sortMentions(statistics) {
let sortable = [];
if ((statistics && statistics.mentions) !== undefined && (Object.keys(statistics.mentions).length !== 0)) {
for (const s in statistics.mentions) {
statistics = statistics.filter(([el], i, a) => i === a.indexOf(el));
if (statistics !== undefined && statistics.length !== 0) {
for (const s in statistics) {
if (s) {
sortable.push([s, statistics.mentions[s]]);
sortable.push([s, statistics[s]]);
}
}
sortable.sort(function (a, b) {
Expand Down Expand Up @@ -123,17 +121,46 @@ export class InfoBoxComponent implements OnInit, OnChanges {
this.inviewportmentions = event.value;
}
}

parseApiResponseData() {
const tagStrings = [];
const screenStrings = [];
const mentionStrings = [];
const createdStrings = [];
for ( let i = 0; i < this.ApiResponseResult.length; i++) {
if (this.ApiResponseResult[i]['hashtags'].length !== 0) {
tagStrings.push(this.ApiResponseResult[i]['hashtags']);
}
if (this.ApiResponseResult[i]['screen_name'].length !== 0) {
screenStrings.push(this.ApiResponseResult[i]['screen_name']);
}
if (this.ApiResponseResult[i]['mentions'].length !== 0) {
mentionStrings.push(this.ApiResponseResult[i]['mentions']);
}
if (this.ApiResponseResult[i]['created_at'].length !== 0) {
createdStrings.push(this.ApiResponseResult[i]['created_at']);
}
}
this.sortHashtags(tagStrings);
this.sortTwiterers(screenStrings);
this.sortMentions(mentionStrings);
this.getChartData(createdStrings);
}

getChartData(statistics) {
if ((statistics && statistics.created_at) !== undefined && (Object.keys(statistics.created_at).length !== 0)) {

for (let i = 0; i < statistics.length; i++) {
statistics[i] = JSON.stringify(statistics[i]).substring(15, statistics.length);
}
const count = {};
statistics.forEach(function(i) { count[i] = (count[i] || 0) + 1; });
if (statistics !== undefined && statistics.length !== 0) {
const data = [];
const labels = [];
const chosen_attr = statistics.created_at;


for (const property in chosen_attr) {
if (chosen_attr.hasOwnProperty(property)) {
labels.push(property);
data.push(chosen_attr[property]);
for (const key in count) {
if (count.hasOwnProperty(key)) {
data.push(count[key]);
labels.push(key);
}
}

Expand Down
2 changes: 1 addition & 1 deletion src/app/feed/user-info-box/user-info-box.component.html
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@
<h2>{{ apiResponseUser.name }}</h2>
<span>@{{ apiResponseUser.screen_name }}</span>
</div>
<div class="desc" *ngIf="apiResponseUser.description">
<div class="desc" *ngIf="apiResponseUser">
<feed-linker
[text]="apiResponseUser.description"
[useAll]="true"></feed-linker>
Expand Down
2 changes: 1 addition & 1 deletion src/app/home/home.component.html
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ <h1><span class="loklak">loklak</span>&nbsp;Search!</h1>

<div class="search-input" [class.focused]="inputFocused">
<input type="text" id="search" name="search" [formControl]="_queryControl"
(focus)="inputFocused=true" (focusout)="inputFocused=false"/>
(keypress)="onEnter($event)" (focus)="inputFocused=true" (focusout)="inputFocused=false"/>
<button title="Search by voice" class="btn btn-default" id="speech-button" type="submit">
<a><img src="../../assets/images/microphone.png" class="microphone" (click)="speechRecognition()"/></a>
</button>
Expand Down
2 changes: 1 addition & 1 deletion src/app/home/home.component.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -132,7 +132,7 @@ describe('Component: Home', () => {
const component = fixture.debugElement.componentInstance;
const compiled = fixture.debugElement.nativeElement;

const value = 'a';
const value = 'since:day';

const query$ = component.store.select(fromRoot.getQuery);
let displayString: string;
Expand Down

0 comments on commit 8438050

Please sign in to comment.