File
Implements
Methods
fetchUserProfile
|
fetchUserProfile(userName)
|
|
Parameters :
Name |
Optional |
userName |
No
|
|
filter
|
filter(key: string | "timestamp" | "best" | "saved" | "watched" | "upvoted" | "downvoted", resetpagination: boolean)
|
|
Parameters :
Name |
Type |
Optional |
Description |
key |
string | "timestamp" | "best" | "saved" | "watched" | "upvoted" | "downvoted"
|
No
|
|
resetpagination |
boolean
|
No
|
- its used to reset the pagination value based on the filter data
|
|
getRecentTopics
|
getRecentTopics(scrollIndex: number)
|
|
Parameters :
Name |
Type |
Optional |
scrollIndex |
number
|
No
|
|
logTelemetry
|
logTelemetry(event)
|
|
|
navigateToDiscussionDetails
|
navigateToDiscussionDetails(discussionData)
|
|
Parameters :
Name |
Optional |
discussionData |
No
|
|
ngAfterViewChecked
|
ngAfterViewChecked()
|
|
|
onModalScrollDown
|
onModalScrollDown()
|
|
|
currentFilter
|
Type : string
|
Default value : 'timestamp'
|
|
department
|
Type : string | null
|
|
discussionList
|
Type : []
|
Default value : []
|
|
elementView
|
Type : ElementRef
|
Decorators :
@ViewChild('scrollContainerHeight')
|
|
InfiniteScrollConfig
|
Type : object
|
Default value : {
modalScrollDistance: 2,
modalScrollThrottle: 50
}
|
|
location
|
Type : string | null
|
|
pagination
|
Default value : Object.create({})
|
|
Public
router
|
Type : Router
|
|
showLoader
|
Default value : false
|
|
userInitial
|
Type : string
|
Default value : ''
|
|
import { DiscussionService } from './../../services/discussion.service';
import { Component, ElementRef, OnInit, ViewChild } from '@angular/core';
import { TelemetryUtilsService } from './../../telemetry-utils.service';
import { NSDiscussData } from './../../models/discuss.model';
import { Router } from '@angular/router';
import * as CONSTANTS from '../../common/constants.json';
/* tslint:disable */
import * as _ from 'lodash'
import { ConfigService } from '../../services/config.service';
import { combineLatest } from 'rxjs';
/* tslint:enable */
@Component({
selector: 'lib-my-discussion',
templateUrl: './my-discussion.component.html',
styleUrls: ['./my-discussion.component.scss']
})
export class MyDiscussionComponent implements OnInit {
@ViewChild('scrollContainerHeight') elementView: ElementRef;
data; // this is for user
discussionList = []; // this is for posts
currentFilter = 'timestamp';
department!: string | null;
location!: string | null;
profilePhoto!: string;
userInitial = '';
showLoader = false;
pagination = Object.create({});
recentFilter;
// Input parameters for infinite scroll
InfiniteScrollConfig = {
modalScrollDistance: 2,
modalScrollThrottle: 50
};
constructor(
private discussService: DiscussionService,
private configService: ConfigService,
public router: Router,
private telemetryUtils: TelemetryUtilsService) { }
/** To fetch user details */
fetchUserProfile(userName) {
this.discussService.fetchUserProfile(userName).subscribe(response => {
this.showLoader = false;
console.log(response);
this.data = response;
if (_.get(this.data, 'posts')) {
this.discussionList = _.get(this.data, 'posts').filter(p => (p.isMainPost === true));
}
// if (this.configSvc.userProfile) {
// localStorage.setItem(this.configSvc.userProfile.userId, this.profilePhoto);
// }
}, error => {
this.showLoader = false;
// error code check
this.discussService.showTrafficAlert(error);
// TODO: Toaster
console.log('error fetching user details');
});
}
ngOnInit() {
this.telemetryUtils.setContext([]);
this.telemetryUtils.logImpression(NSDiscussData.IPageName.MY_DISCUSSION);
this.filter(this.currentFilter, false);
}
/**
* @description - set the scroll container height
*/
ngAfterViewChecked() {
if (this.elementView && this.elementView.nativeElement && !this.elementView.nativeElement.style.height) {
// the number 10 is just a random value to reduce the height of the parent container to the infinite scroll
this.elementView.nativeElement.style.height = (this.elementView.nativeElement.clientHeight - 10) + 'px';
}
}
/**
* @param {string|'timestamp'|'best'|'saved'|'watched'|'upvoted'|'downvoted'} key
* @param {boolean} resetpagination - its used to reset the pagination value based on the filter data
*/
filter(key: string | 'timestamp' | 'best' | 'saved' | 'watched' | 'upvoted' | 'downvoted', resetpagination: boolean) {
this.currentFilter = key;
if (key) {
// reset the currentpage value to 1 and reset the discussionList data based on the respective api response when the filter is changed
if (resetpagination) {
this.discussionList = []
this.pagination.currentPage = 1;
}
// setting the current page index
const scrollIndex = this.pagination.currentPage ? this.pagination.currentPage : 1;
this.showLoader = true;
switch (key) {
case 'timestamp':
this.getRecentTopics(scrollIndex);
break;
case 'best':
// this.discussionList = _.uniqBy(this.data.bestPosts, 'tid');
this.discussService.fetchBestPost(scrollIndex).subscribe(result => {
if (result) {
const bestPost = result['posts'].filter(p => (p.isMainPost === true));
this.discussionList = [...this.discussionList, ...bestPost];
this.pagination = _.get(result, 'pagination');
this.showLoader = false;
} else {
this.showLoader = false;
this.discussionList = [];
}
}, error => {
// error code check
this.discussService.showTrafficAlert(error);
});
break;
case 'saved':
this.discussService.fetchSaved(scrollIndex).subscribe(response => {
if (response) {
// this.discussionList = _.uniqBy(response['posts'], 'tid');
this.discussionList = [...this.discussionList, ...response['posts']];
this.pagination = _.get(response, 'pagination');
this.showLoader = false;
} else {
this.showLoader = false;
this.discussionList = [];
}
},
// tslint:disable-next-line
(error) => {
// error code check
this.discussService.showTrafficAlert(error);
this.discussionList = [];
})
break;
case 'watched':
this.showLoader = false;
this.discussionList = [];
break;
case 'upvoted':
this.discussService.fetchUpvoted(scrollIndex).subscribe(response => {
if (response) {
// this.discussionList = _.uniqBy(response['posts'], 'tid');
const upvoted = response['posts'].filter(p => (p.isMainPost === true));
this.pagination = _.get(response, 'pagination');
this.discussionList = [...this.discussionList, ...upvoted];
this.showLoader = false;
} else {
this.showLoader = false;
this.discussionList = [];
}
},
// tslint:disable-next-line
(error) => {
this.discussionList = [];
// error code check
this.discussService.showTrafficAlert(error);
});
break;
case 'downvoted':
this.discussService.fetchDownvoted(scrollIndex).subscribe(response => {
if (response) {
// this.discussionList = _.uniqBy(response['posts'], 'tid');
const downvoted = response['posts'].filter(p => (p.isMainPost === true));
this.discussionList = [...this.discussionList, ...downvoted];
this.pagination = _.get(response, 'pagination');
this.showLoader = false;
} else {
this.showLoader = false;
this.discussionList = [];
}
},
// tslint:disable-next-line
(error) => {
this.discussionList = [];
// error code check
this.discussService.showTrafficAlert(error);
});
break;
default:
// this.discussionList = _.uniqBy(this.data.latestPosts, 'tid');
this.pagination = _.get(this.data, 'pagination');
this.discussionList = _.get(this.data, 'latestPosts');
break;
}
}
}
navigateToDiscussionDetails(discussionData) {
console.log('discussionData', discussionData);
const slug = _.get(discussionData, 'slug') || _.get(discussionData, 'topic.slug')
this.router.navigate([`${this.configService.getRouterSlug()}${CONSTANTS.ROUTES.TOPIC}${slug}`]);
}
logTelemetry(event) {
this.telemetryUtils.logInteract(event, NSDiscussData.IPageName.MY_DISCUSSION);
}
/**
* @description - getting the recent post data
* @param {number} scrollIndex
*/
getRecentTopics(scrollIndex: number) {
const userId = this.discussService.userId;
// const userSlug = this.discussService.userDetails.userslug;
combineLatest([
this.discussService.fetchUserProfile(userId),
this.discussService.fetchRecentPost(scrollIndex)
]).subscribe(result => {
console.log('getRecentTopics', result)
this.showLoader = false;
this.data = _.merge(result[0], result[1]);
this.discussionList = [...this.discussionList, ...(_.get(this.data, 'posts'))];
this.discussionList = this.discussionList.filter(p => (p.isMainPost === true));
this.pagination = _.get(this.data, 'pagination');
}, error => {
this.showLoader = false;
console.log(error);
});
}
/**
* @description - call the topic get api when scrolled down and setting the limit of API Call
*/
onModalScrollDown() {
if (this.pagination.currentPage !== this.pagination.pageCount) {
this.pagination.currentPage = this.pagination.next.page;
const resetpagination = false;
// using settimeout to avoid the function call before getting the pagination response from api,
// because the api is called twice with the same page index
setTimeout(() => {
this.filter(this.currentFilter, resetpagination)
}, 800);
}
}
}
<lib-app-loader *ngIf="showLoader"></lib-app-loader>
<div class="profileCard">
<div class="profile-card-content">
<div class="profile-header-image">
<div class="box-text">
<span class="box-label"></span>{{ data?.username | splitInitials }}
</div>
</div>
<div>
<div class="profile-label name" [innerHTML]="data?.username"></div>
<div class="profile-label department">{{ department }}</div>
<div class="profile-label location">{{ location }}</div>
<div class="profile-label email">{{ data?.email || data?.username }}</div>
<ng-container>
<div class="my-discuss-topics">
<div class="my-discuss-topics__content">
<div class="my-discuss-label">
<span class="number">{{ data?.topiccount || 0 }}</span>
Discussions
</div>
<div class="post-count-area my-discuss-label">
<span class="number">{{ data?.postcount || 0 }}</span>
Posts
</div>
</div>
<div class="text-right">
<!-- Enable lated when other user can visit your profile -->
<!-- <span class="noocoments" mat-card-subtitle>Last online {{data?.lastonline | pipeRelativeTime}}</span> -->
</div>
</div>
</ng-container>
</div>
</div>
</div>
<ng-container>
<div class="recent-tabs">
<div class="tabs-content">
<div class="tabs-filter">
<a href="javascript:void(0)" role="link" class="filter-option" [ngClass]="{
'tabs-active': currentFilter === 'timestamp',
'ws-mat-accent-border font-medium': currentFilter !== 'timestamp'
}" (click)="filter('timestamp', true); logTelemetry($event)" id="recent-post">
Recent posts
</a>
<a href="javascript:void(0)" role="link" class="filter-option" [ngClass]="{
'tabs-active': currentFilter === 'best',
'ws-mat-accent-border font-medium': currentFilter !== 'best'
}" (click)="filter('best', true); logTelemetry($event)" id="best-post">
Best posts
</a>
<a href="javascript:void(0)" role="link" class="filter-option" [ngClass]="{
'tabs-active': currentFilter === 'saved',
'ws-mat-accent-border font-medium': currentFilter !== 'saved'
}" (click)="filter('saved', true); logTelemetry($event)" id="saved-post">
Saved posts
</a>
<!-- <a href="javascript:void(0)" role="link" class="filter-option " [ngClass]="{'ws-mat-accent-border-active' : currentFilter === 'watched',
'ws-mat-accent-border font-medium':currentFilter !== 'watched'}" mat-button
(click)="filter('watched')">
Watched </a> -->
<a href="javascript:void(0)" role="link" class="filter-option" [ngClass]="{
'tabs-active': currentFilter === 'upvoted',
'ws-mat-accent-border font-medium': currentFilter !== 'upvoted'
}" (click)="filter('upvoted', true); logTelemetry($event)" id="upvoted-post">
Upvoted
</a>
<a href="javascript:void(0)" role="link" class="filter-option" [ngClass]="{
'tabs-active': currentFilter === 'downvoted',
'ws-mat-accent-border font-medium': currentFilter !== 'downvoted'
}" (click)="filter('downvoted', true); logTelemetry($event)" id="downvoted-post">
Downvoted
</a>
</div>
</div>
</div>
</ng-container>
<div *ngIf="discussionList && discussionList.length > 0" class="topic-list-container" id="topic-scroll"
#scrollContainerHeight>
<!--infinite scroll-->
<div [infiniteScrollContainer]="'.topic-list-container'" infinite-scroll class="infinite-scroll"
[scrollWindow]="false" [infiniteScrollDistance]="InfiniteScrollConfig.modalScrollDistance" [fromRoot]="true"
[infiniteScrollThrottle]="InfiniteScrollConfig.modalScrollThrottle" (scrolled)="onModalScrollDown()">
<ng-container *ngFor="let data of discussionList">
<div (click)="navigateToDiscussionDetails(data); logTelemetry($event)" id="discuss-card">
<lib-discuss-card [discussionData]="data"></lib-discuss-card>
</div>
</ng-container>
</div>
</div>
<lib-app-loader *ngIf="showLoader"></lib-app-loader>
<ng-container *ngIf="!(discussionList && discussionList.length > 0)">
<div class="no-card-content" tabindex="0">
<div class="no-data-label">No Data</div>
<div>
<span> </span>
</div>
</div>
</ng-container>
::ng-deep:root {
--df-box-text:var(--white);
--df-profile-bg: var(--primary-400);
}
.profileCard {
box-shadow: 0 2px 1px -1px rgba(0, 0, 0, 0.2), 0 1px 1px 0 rgba(0, 0, 0, 0.14),
0 1px 3px 0 rgba(0, 0, 0, 0.12);
background: var(--df-card-bg);
color: var(--df-text);
flex: 1;
height: auto;
margin-bottom: 0px;
transition: box-shadow 280ms cubic-bezier(0.4, 0, 0.2, 1);
display: block;
position: relative;
padding: 1rem;
border-radius: 0.25rem;
width: auto;
.profile-card-content {
display: flex;
flex-wrap: wrap;
.profile-header-image {
display: flex;
justify-content: center;
align-items: center;
width: 100%;
border-radius: 0.25rem;
max-width: 9.5rem;
height: 8.4375rem;
border: 0.0625rem solid var(--gray-100);
margin-right: 1.5rem;
background: var(--df-profile-bg);
text-align: center;
.box-text {
font-size: 4rem;
color: var(--df-box-text);
text-transform: uppercase;
.box-label {
color: var(--white);
font-size: 1rem;
line-height: 0.75rem;
letter-spacing: 0.2625px;
text-transform: uppercase;
}
}
}
.profile-label {
font-weight: 700;
margin-bottom: 0.5rem;
font-size: 0.875rem;
}
.name {
font-size: 1rem;
}
.my-discuss-topics {
font-size: 0.875rem;
margin: 1rem 0;
font-weight: 600;
&__content {
display: flex;
.my-discussion-label {
margin: 0 0.5rem;
.number {
color: var(--primary-300);
}
}
.post-count-area {
margin-left: 2rem;
}
}
}
}
}
Legend
Html element with directive