Skip to content

Commit

Permalink
add ssr support for more components/services
Browse files Browse the repository at this point in the history
  • Loading branch information
EverettSummer committed Jul 29, 2024
1 parent 116f877 commit b84ee29
Show file tree
Hide file tree
Showing 5 changed files with 23 additions and 9 deletions.
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "deneb-ui",
"version": "4.1.1",
"version": "4.1.2",
"scripts": {
"ng": "ng",
"start": "ng serve --project Deneb-UI-Demo",
Expand Down
2 changes: 1 addition & 1 deletion projects/irohalab/deneb-ui/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@irohalab/deneb-ui",
"version": "4.1.1",
"version": "4.1.2",
"description": "Building blocks for mira-ui",
"author": "Everett Summer",
"license": "Apache-2.0",
Expand Down
4 changes: 3 additions & 1 deletion projects/irohalab/deneb-ui/src/dialog/dialog.ts
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,9 @@ export class UIDialog {
const environmentInjector = this._appRef.injector;
container = createComponent<UIDialogContainer>(UIDialogContainer, {environmentInjector});
this._appRef.attachView(container.hostView);
document.body.appendChild(this.getComponentRootNode(container));
if (document) {
document.body.appendChild(this.getComponentRootNode(container));
}
}
container.instance.dialogConfig = config;
container.instance.insideParent = !!viewContainer;
Expand Down
11 changes: 8 additions & 3 deletions projects/irohalab/deneb-ui/src/dropdown/dropdown.ts
Original file line number Diff line number Diff line change
@@ -1,8 +1,9 @@

import {fromEvent as observableFromEvent, Observable, Subscription } from 'rxjs';
import {fromEvent as observableFromEvent, Subscription } from 'rxjs';

import {takeUntil, delay, takeWhile, mergeMap, tap} from 'rxjs/operators';
import { Directive, ElementRef, HostListener, Input, OnDestroy, OnInit } from '@angular/core';
import { Directive, ElementRef, HostListener, Inject, Input, OnDestroy, OnInit, PLATFORM_ID } from '@angular/core';
import { isPlatformServer } from '@angular/common';

@Directive({
selector: '[uiDropdown]',
Expand Down Expand Up @@ -44,7 +45,8 @@ export class UIDropdown implements OnInit, OnDestroy {
return this._menuOpen;
}

constructor(private _element: ElementRef) {
constructor(private _element: ElementRef,
@Inject(PLATFORM_ID) private platformId: object) {
}

@HostListener('click', ['$event'])
Expand All @@ -58,6 +60,9 @@ export class UIDropdown implements OnInit, OnDestroy {
}

ngOnInit(): void {
if (isPlatformServer(this.platformId)) {
return;
}
let _el = this._element.nativeElement;
this._subscription.add(
observableFromEvent<MouseEvent>(document.body, 'click')
Expand Down
13 changes: 10 additions & 3 deletions projects/irohalab/deneb-ui/src/toast/toast.ts
Original file line number Diff line number Diff line change
@@ -1,13 +1,14 @@
import {
Injectable, Injector, ApplicationRef, Type, ComponentRef,
EmbeddedViewRef,
createComponent
createComponent, Inject, PLATFORM_ID
} from '@angular/core';
import {UIToastRef} from './toast-ref';
import {UIToastComponent} from './toast.component';
import {ToastInjector} from './toast-injector';
import {Subscription} from 'rxjs';
import {UIToastAnimation} from './toast-interface';
import { isPlatformServer } from '@angular/common';

@Injectable()
export class UIToast {
Expand All @@ -22,7 +23,8 @@ export class UIToast {
private timerId: any;

constructor(private _injector: Injector,
private _appRef: ApplicationRef) {
private _appRef: ApplicationRef,
@Inject(PLATFORM_ID) private platformId: object) {
}

make<T>(componentType?: Type<T>): UIToastRef<T> {
Expand All @@ -39,6 +41,9 @@ export class UIToast {
}

activeToast<T>(component: ComponentRef<T>, duration: number) {
if (isPlatformServer(this.platformId)) {
return;
}
if (this._pendingToast) {
this._pendingToast = component;
this._pendingToastDuration = duration;
Expand All @@ -60,13 +65,15 @@ export class UIToast {

this._appRef.attachView(this._currentActiveToast.hostView);
document.body.appendChild(this._getComponentRootNode(this._currentActiveToast));

this.timerId = setTimeout(() => {
this.deactiveToast();
}, duration);
}

deactiveToast() {
if (isPlatformServer(this.platformId)) {
return;
}
clearTimeout(this.timerId);
if (this._currentActiveToast) {
if (this._currentActiveToast.instance['animationEvent'] && this._currentActiveToast.instance['uiLeaveAnimationDone']) {
Expand Down

0 comments on commit b84ee29

Please sign in to comment.