Changeset View
Changeset View
Standalone View
Standalone View
src/app/userPosts/userPosts.component.ts
import { Component, OnInit, OnDestroy, NgModule, ChangeDetectorRef } from '@angular/core'; | import { Component, OnInit, OnDestroy, NgModule, ChangeDetectorRef } from '@angular/core'; | ||||
import { Router, ActivatedRoute } from '@angular/router'; | import { Router, ActivatedRoute } from '@angular/router'; | ||||
import { Subject } from 'rxjs/Subject'; | import { Subject } from 'rxjs/Subject'; | ||||
import { Area } from '../_models/area'; | import { Area } from '../_models/area'; | ||||
import * as C from '../_models/constants'; | import * as C from '../_models/constants'; | ||||
import { Post } from '../_models/post'; | import { Post } from '../_models/post'; | ||||
import { NavBarService } from '../_services/navBar.service'; | import { NavBarService } from '../_services/navBar.service'; | ||||
import { PostService } from '../_services/post.service'; | import { PostService } from '../_services/post.service'; | ||||
import { RouteService } from '../_services/route.service'; | import { RouteService } from '../_services/route.service'; | ||||
@Component({ | @Component({ | ||||
templateUrl: 'userPosts.component.html' | templateUrl: 'userPosts.component.html', | ||||
styleUrls: ['./userPosts.component.scss'] | |||||
}) | }) | ||||
export class UserPostsComponent implements OnInit, OnDestroy { | export class UserPostsComponent implements OnInit, OnDestroy { | ||||
backupPosts: { [area: string]: Post[]; } = {}; | backupPosts: { [area: string]: Post[]; } = {}; | ||||
componentDestroyed: Subject<boolean> = new Subject(); | componentDestroyed: Subject<boolean> = new Subject(); | ||||
currentArea: string; | currentArea: string; | ||||
imageArray: { [area: string]: string[]; } = {}; | imageArray: { [area: string]: string[]; } = {}; | ||||
index = 1; | index = 1; | ||||
limit = 10; | limit = 10; | ||||
▲ Show 20 Lines • Show All 75 Lines • ▼ Show 20 Lines | input = input | ||||
.replace(/\n{2,}/g, '\n\n'); | .replace(/\n{2,}/g, '\n\n'); | ||||
return input; | return input; | ||||
} | } | ||||
ngOnInit() { | ngOnInit() { | ||||
this.cdRef.detectChanges(); | this.cdRef.detectChanges(); | ||||
this.routeService.resetRoutes(); | this.routeService.resetRoutes(); | ||||
this.routeService.addNextRoute('/posts'); | this.routeService.addNextRoute('/posts'); | ||||
this.route.params | this.route.params | ||||
.takeUntil(this.componentDestroyed) | .takeUntil(this.componentDestroyed) | ||||
.subscribe(params => { | .subscribe(params => { | ||||
if (params['index'] !== undefined) { | if (params['index'] !== undefined) { | ||||
this.index = params['index']; | this.index = params['index']; | ||||
} | } | ||||
}); | }); | ||||
this.navBarService.currentArea | this.navBarService.currentArea | ||||
.takeUntil(this.componentDestroyed) | .takeUntil(this.componentDestroyed) | ||||
.subscribe((currentArea: Area) => { | .subscribe((currentArea: Area) => { | ||||
if (currentArea.name !== '') { | if (currentArea.name !== '') { | ||||
this.currentArea = currentArea.name; | this.currentArea = currentArea.name; | ||||
if (!this.superPosts[currentArea.name]) { | if (!this.superPosts[currentArea.name]) { | ||||
this.superPosts[currentArea.name] = []; | this.superPosts[currentArea.name] = []; | ||||
} | } | ||||
if (!this.backupPosts[currentArea.name]) { | if (!this.backupPosts[currentArea.name]) { | ||||
this.backupPosts[currentArea.name] = []; | this.backupPosts[currentArea.name] = []; | ||||
} | } | ||||
this.loading = true; | |||||
const posts: Post[] = []; | const posts: Post[] = []; | ||||
this.postService.getOwnPosts(currentArea.name, this.limit, 0) | this.postService.getOwnPosts(currentArea.name, this.limit, 0) | ||||
.takeUntil(this.componentDestroyed) | .takeUntil(this.componentDestroyed) | ||||
.subscribe(superPost => { | .subscribe(superPost => { | ||||
superPost.results.forEach((obj: any) => { | superPost.results.forEach((obj: any) => { | ||||
posts.push(Post.parse(obj)); | posts.push(Post.parse(obj)); | ||||
}); | }); | ||||
▲ Show 20 Lines • Show All 91 Lines • Show Last 20 Lines |