Skip to content

Commit

Permalink
fix loading lib http on server side
Browse files Browse the repository at this point in the history
  • Loading branch information
FunixG committed Sep 20, 2023
1 parent 7c3bb4d commit aa78445
Show file tree
Hide file tree
Showing 5 changed files with 22 additions and 6 deletions.
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import {AfterViewInit, Component} from '@angular/core';
import {AfterViewInit, Component, Inject, PLATFORM_ID} from '@angular/core';
import {
PacifistaNewsDTO,
PacifistaNewsService,
Expand All @@ -7,6 +7,7 @@ import {
} from "@funixproductions/funixproductions-requests";
import {HttpClient} from "@angular/common/http";
import {environment} from "../../../../../environments/environment";
import {isPlatformBrowser} from "@angular/common";

@Component({
selector: 'news-section',
Expand All @@ -20,11 +21,14 @@ export class NewsAccueilSectionComponent implements AfterViewInit {
newsList: PacifistaNewsDTO[] = [];
totalNews: number = 0;

constructor(httpClient: HttpClient) {
constructor(@Inject(PLATFORM_ID) private platfomId: Object,
httpClient: HttpClient) {
this.newsService = new PacifistaNewsService(httpClient, environment.production);
}

ngAfterViewInit(): void {
if (!isPlatformBrowser(this.platfomId)) return;

const pageOption = new PageOption();
pageOption.elemsPerPage = 3;
pageOption.sort = 'createdAt:desc';
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import {AfterViewInit, Component, Renderer2} from '@angular/core';
import {AfterViewInit, Component, Inject, PLATFORM_ID, Renderer2} from '@angular/core';
import {Title} from "@angular/platform-browser";
import {faTwitter} from "@fortawesome/free-brands-svg-icons";
import NotificationService from "../../../services/notifications/services/NotificationService";
Expand All @@ -12,6 +12,7 @@ import {
import {PacifistaPage} from "../../../components/pacifista-page/pacifista-page";
import {HttpClient} from "@angular/common/http";
import {environment} from "../../../../environments/environment";
import {isPlatformBrowser} from "@angular/common";

@Component({
selector: 'app-news-list-page',
Expand All @@ -36,6 +37,7 @@ export class NewsListPageComponent extends PacifistaPage implements AfterViewIni
private newsService: PacifistaNewsService;

constructor(private notificationService: NotificationService,
@Inject(PLATFORM_ID) private platfomId: Object,
titleService: Title,
renderer: Renderer2,
httpClient: HttpClient) {
Expand All @@ -48,6 +50,8 @@ export class NewsListPageComponent extends PacifistaPage implements AfterViewIni
}

ngAfterViewInit(): void {
if (!isPlatformBrowser(this.platfomId)) return;

this.loadNews();
}

Expand Down
6 changes: 5 additions & 1 deletion src/app/pages/news/news-page/news-page.component.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import {Component, Renderer2} from '@angular/core';
import {Component, Inject, PLATFORM_ID, Renderer2} from '@angular/core';
import {ActivatedRoute, Router} from "@angular/router";
import NotificationService from "../../../services/notifications/services/NotificationService";
import {PacifistaPage} from "../../../components/pacifista-page/pacifista-page";
Expand All @@ -12,6 +12,7 @@ import {
} from "@funixproductions/funixproductions-requests";
import {HttpClient} from "@angular/common/http";
import {environment} from "../../../../environments/environment";
import {isPlatformBrowser} from "@angular/common";

@Component({
selector: 'app-news-page',
Expand All @@ -30,12 +31,15 @@ export class NewsPageComponent extends PacifistaPage {
constructor(private notificationService: NotificationService,
private router: Router,
private activatedRoute: ActivatedRoute,
@Inject(PLATFORM_ID) private platfomId: Object,
httpClient: HttpClient,
titleService: Title,
renderer: Renderer2) {
super(titleService, renderer);
this.newsService = new PacifistaNewsService(httpClient, environment.production);

if (!isPlatformBrowser(this.platfomId)) return;

this.activatedRoute.params.subscribe(params => {
const newsName = params['newsName'];

Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { Component } from '@angular/core';
import {Component} from '@angular/core';

@Component({
selector: 'app-shop-basket-little',
Expand Down
6 changes: 5 additions & 1 deletion src/app/pages/user/user-page/user-page.component.ts
Original file line number Diff line number Diff line change
@@ -1,11 +1,12 @@
import {Component, Renderer2} from '@angular/core';
import {Component, Inject, PLATFORM_ID, Renderer2} from '@angular/core';
import {Router} from "@angular/router";
import {faSearch} from '@fortawesome/free-solid-svg-icons';
import {PacifistaPage} from "../../../components/pacifista-page/pacifista-page";
import {UserAuthService, UserDTO} from "@funixproductions/funixproductions-requests";
import {Title} from "@angular/platform-browser";
import {environment} from "../../../../environments/environment";
import {HttpClient} from "@angular/common/http";
import {isPlatformBrowser} from "@angular/common";

@Component({
selector: 'app-user-page',
Expand All @@ -24,6 +25,7 @@ export class UserPageComponent extends PacifistaPage {
user?: UserDTO;

constructor(private router: Router,
@Inject(PLATFORM_ID) private platfomId: Object,
title: Title,
renderer: Renderer2,
httpClient: HttpClient) {
Expand All @@ -32,6 +34,8 @@ export class UserPageComponent extends PacifistaPage {
}

protected override onPageInit() {
if (!isPlatformBrowser(this.platfomId)) return;

this.authService.currentUser().subscribe({
next: value => {
this.user = value;
Expand Down

0 comments on commit aa78445

Please sign in to comment.