angular universal WIP

refs #104
This commit is contained in:
softsimon
2020-11-07 04:30:52 +07:00
parent d8c4f5a6ac
commit 14c9d0c409
25 changed files with 18061 additions and 758 deletions

View File

@@ -1,4 +1,5 @@
import { Component, HostListener, OnInit } from '@angular/core';
import { Location } from '@angular/common';
import { Router, NavigationEnd } from '@angular/router';
import { WebsocketService } from '../../services/websocket.service';
import { StateService } from 'src/app/services/state.service';
@@ -15,6 +16,7 @@ export class AppComponent implements OnInit {
public router: Router,
private websocketService: WebsocketService,
private stateService: StateService,
private location: Location,
) { }
@HostListener('document:keydown', ['$event'])
@@ -28,7 +30,7 @@ export class AppComponent implements OnInit {
ngOnInit() {
this.router.events.subscribe((val) => {
if (val instanceof NavigationEnd) {
this.link.setAttribute('href', 'https://mempool.space' + (location.pathname === '/' ? '' : location.pathname));
this.link.setAttribute('href', 'https://mempool.space' + (this.location.path() === '/' ? '' : this.location.path()));
}
});
}

View File

@@ -194,7 +194,7 @@ export class ChartistComponent implements OnInit, OnChanges, OnDestroy {
};
};
}(window, document, Chartist));
}(null, null, Chartist));
/**
@@ -278,7 +278,7 @@ export class ChartistComponent implements OnInit, OnChanges, OnDestroy {
};
};
}(window, document, Chartist));
}(null, null, Chartist));
const defaultOptions = {
className: '',

View File

@@ -1,4 +1,5 @@
import { Component, OnInit, OnDestroy, ChangeDetectionStrategy, Input, ChangeDetectorRef, OnChanges } from '@angular/core';
import { isPlatformBrowser } from '@angular/common';
import { Component, OnInit, OnDestroy, ChangeDetectionStrategy, Input, ChangeDetectorRef, OnChanges, PLATFORM_ID, Inject } from '@angular/core';
@Component({
selector: 'app-time-since',
@@ -6,6 +7,7 @@ import { Component, OnInit, OnDestroy, ChangeDetectionStrategy, Input, ChangeDet
changeDetection: ChangeDetectionStrategy.OnPush
})
export class TimeSinceComponent implements OnInit, OnChanges, OnDestroy {
isBrowser: boolean = isPlatformBrowser(this.platformId);
interval: number;
text: string;
intervals = {};
@@ -14,7 +16,8 @@ export class TimeSinceComponent implements OnInit, OnChanges, OnDestroy {
@Input() fastRender = false;
constructor(
private ref: ChangeDetectorRef
private ref: ChangeDetectorRef,
@Inject(PLATFORM_ID) private platformId: any,
) {
if (document.body.clientWidth < 768) {
this.intervals = {
@@ -40,6 +43,11 @@ export class TimeSinceComponent implements OnInit, OnChanges, OnDestroy {
}
ngOnInit() {
if (!this.isBrowser) {
this.text = this.calculate();
this.ref.markForCheck();
return;
}
this.interval = window.setInterval(() => {
this.text = this.calculate();
this.ref.markForCheck();