File

src/lib/elements/related-discussion/related-discussion.component.ts

Implements

OnInit OnChanges

Metadata

Index

Properties
Methods
Inputs
Outputs

Constructor

constructor(router: Router, configService: ConfigService, discussionService: DiscussionService, navigationService: NavigationServiceService)
Parameters :
Name Type Optional
router Router No
configService ConfigService No
discussionService DiscussionService No
navigationService NavigationServiceService No

Inputs

catId
Type : any
topicId
Type : any

Outputs

stateChange
Type : EventEmitter<any>

Methods

fetchRelatedDiscussionData
fetchRelatedDiscussionData(cid: number)
Parameters :
Name Type Optional
cid number No
Returns : void
getDiscussion
getDiscussion(discuss)
Parameters :
Name Optional
discuss No
Returns : void
ngOnChanges
ngOnChanges()
Returns : void
ngOnInit
ngOnInit()
Returns : void

Properties

fetchSingleCategoryLoader
Default value : false
relatedDiscussions
Type : any[]
similarPosts
Type : any
import { Component, Input, OnChanges, OnInit, EventEmitter, Output } from '@angular/core';
import { Router } from '@angular/router';
import _ from 'lodash-es';
import { DiscussionService } from '../../services/discussion.service';
import { ConfigService } from '../../services/config.service';
import * as CONSTANTS from './../../common/constants.json';
import { NSDiscussData } from './../../models/discuss.model';
import { NavigationServiceService } from '../../navigation-service.service';

@Component({
  selector: 'lib-related-discussion',
  templateUrl: './related-discussion.component.html',
  styleUrls: ['./related-discussion.component.scss'],
  // host: { class: 'margin-left-l' },
})
export class RelatedDiscussionComponent implements OnInit, OnChanges {
  @Input() catId: any;
  @Input() topicId: any;

  @Output() stateChange: EventEmitter<any> = new EventEmitter();

  relatedDiscussions: any[];
  fetchSingleCategoryLoader = false;
  similarPosts: any;

  constructor(
    private router: Router,
    private configService: ConfigService,
      private discussionService: DiscussionService,
      private navigationService: NavigationServiceService

  ) { }

  ngOnInit() {
  }

  ngOnChanges() {
    if (this.catId) {
      this.fetchRelatedDiscussionData(this.catId)
    }
  }

  fetchRelatedDiscussionData(cid: number) {
    this.fetchSingleCategoryLoader = true;
    this.discussionService.fetchSingleCategoryDetails(cid).subscribe(
      (data: NSDiscussData.ICategoryData) => {
        this.relatedDiscussions = [];
        _.filter(data.topics, (topic) => {
          if (topic.deleted === 0 && this.topicId !== topic.tid) {
            this.relatedDiscussions.push(topic);
          }
        })
        this.fetchSingleCategoryLoader = false;
      },
      (err: any) => {
        console.log('Error in fetching category details')
        // this.openSnackbar(err.error.message.split('|')[1] || this.defaultError)
        this.fetchSingleCategoryLoader = false;
      });
  }

  getDiscussion(discuss) {
    const input = { data: { url: `${this.configService.getRouterSlug()}${CONSTANTS.ROUTES.DISCUSSION}topic/${discuss.slug}`, queryParams: {} } }
    this.navigationService.navigate(input);
    this.stateChange.emit(discuss);
  }


}
<h5 aria-label="Related discussions" class="related-discuss-label">Related discussions</h5>
<ng-container *ngIf="relatedDiscussions && relatedDiscussions.length > 0">
    <div *ngFor="let discussion of relatedDiscussions | slice:0:5;" class="related-discuss-card df-card" tabindex="0">
        <label role="link" tabindex="0" aria-label="related discussion post df-text-color"
            class="related-discuss-card-content discuss-user-label" (click)="getDiscussion(discussion)"
            [innerHTML]="discussion?.title">
        </label>
        <div class="related-discuss-card-description mt-8">
            <div class="category-name" [innerHTML]="discussion.category.name"></div>
            <div class="dot"></div>
            <div class="time">{{ discussion.timestamp | pipeRelativeTime }}</div>
        </div>
    </div>
</ng-container>

./related-discussion.component.scss

::ng-deep:root{
    --df-related-card-bg:var(--df-background);
}

.related-discuss-card {
	padding: 1rem;
    display: flex;
	box-shadow: 0 2px 1px -1px rgba(0,0,0,.2), 0 1px 1px 0 rgba(0,0,0,.14), 0 1px 3px 0 rgba(0,0,0,.12);
    background: var(--df-related-card-bg);
    color: var(--df-text);
    margin-bottom: 1rem;
    flex-direction: column;
	max-width: 18.75rem;
	@media (max-width: 768px) {
     max-width: 100%;
	}
}

.related-discuss-label{
    font-weight: bold;
	margin: 0 0 1rem 0;
    color: var(--df-text);
	@media (max-width: 768px) {
		margin: 1rem 0;
	   }
}

.related-discuss-card-content {
	margin: 0;
    cursor: pointer;
    font-size: 0.875rem;
    font-weight: 700;
    word-break: break-all;
}

.related-discuss-card-description {
	display: flex;
    -webkit-box-align: center;
    align-items: center;
    font-size: 0.875rem;
	flex-wrap: wrap;
    margin-top: 0.5rem;
    .dot{
        height: 0.375rem;
        width: 0.375rem;
        background-color: var(--gray-400);
        border-radius: 50%;
        display: inline-block;
        margin: 0 0.5rem;
        position: relative;
        bottom: 0;
      }
}


Legend
Html element
Component
Html element with directive

results matching ""

    No results matching ""