add fix with glb view on tab
This commit is contained in:
@@ -3,10 +3,15 @@ import {
|
||||
ChangeDetectionStrategy,
|
||||
Component,
|
||||
CUSTOM_ELEMENTS_SCHEMA,
|
||||
ElementRef,
|
||||
NgZone,
|
||||
computed,
|
||||
effect,
|
||||
inject,
|
||||
input,
|
||||
signal,
|
||||
untracked,
|
||||
viewChild,
|
||||
} from '@angular/core';
|
||||
import { MatButton } from '@angular/material/button';
|
||||
import { Router, RouterLink } from '@angular/router';
|
||||
@@ -27,6 +32,8 @@ export class CollectSuccess {
|
||||
private readonly store = inject(Store);
|
||||
private readonly location = inject(Location);
|
||||
private readonly router = inject(Router);
|
||||
private readonly zone = inject(NgZone);
|
||||
private readonly viewer = viewChild<ElementRef<ModelViewerElement>>('viewer');
|
||||
|
||||
readonly mode = input<'claim' | 'preview'>('claim');
|
||||
readonly title = input.required<string>();
|
||||
@@ -36,14 +43,51 @@ export class CollectSuccess {
|
||||
readonly opened = input(0);
|
||||
readonly total = input(1);
|
||||
|
||||
protected readonly view = signal<'model' | 'image'>('model');
|
||||
protected readonly modelLoaded = signal(false);
|
||||
|
||||
constructor() {
|
||||
effect(() => {
|
||||
if (!this.model()) {
|
||||
const src = this.model();
|
||||
|
||||
untracked(() => {
|
||||
this.view.set('model');
|
||||
this.modelLoaded.set(false);
|
||||
});
|
||||
|
||||
if (!src) {
|
||||
return;
|
||||
}
|
||||
|
||||
void import('@google/model-viewer/dist/model-viewer.min.js');
|
||||
});
|
||||
|
||||
effect((onCleanup) => {
|
||||
const element = this.viewer()?.nativeElement;
|
||||
|
||||
if (!element) {
|
||||
return;
|
||||
}
|
||||
|
||||
const markLoaded = (): void => {
|
||||
this.zone.run(() => this.modelLoaded.set(true));
|
||||
};
|
||||
|
||||
if (element.loaded) {
|
||||
markLoaded();
|
||||
}
|
||||
|
||||
element.addEventListener('load', markLoaded);
|
||||
onCleanup(() => element.removeEventListener('load', markLoaded));
|
||||
});
|
||||
}
|
||||
|
||||
protected showModel(): void {
|
||||
this.view.set('model');
|
||||
}
|
||||
|
||||
protected showImage(): void {
|
||||
this.view.set('image');
|
||||
}
|
||||
|
||||
protected readonly from = computed(() => {
|
||||
@@ -88,3 +132,7 @@ export class CollectSuccess {
|
||||
void this.router.navigateByUrl('/city');
|
||||
}
|
||||
}
|
||||
|
||||
interface ModelViewerElement extends HTMLElement {
|
||||
loaded: boolean;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user