2024-10-04 02:18:47 +02:00
|
|
|
import { IdpState } from '../idp.state.js';
|
2024-09-29 16:48:06 +02:00
|
|
|
import * as plugins from '../plugins.js';
|
2024-10-04 02:18:47 +02:00
|
|
|
import * as elements from '../elements/index.js';
|
2024-09-29 16:48:06 +02:00
|
|
|
|
|
|
|
|
import {
|
|
|
|
|
customElement,
|
|
|
|
|
DeesElement,
|
|
|
|
|
property,
|
|
|
|
|
html,
|
|
|
|
|
cssManager,
|
|
|
|
|
unsafeCSS,
|
|
|
|
|
css,
|
|
|
|
|
type TemplateResult,
|
|
|
|
|
} from '@design.estate/dees-element';
|
|
|
|
|
|
|
|
|
|
@customElement('idp-viewcontainer')
|
|
|
|
|
export class IdpViewcontainer extends DeesElement {
|
|
|
|
|
constructor() {
|
|
|
|
|
super();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public static styles = [
|
|
|
|
|
cssManager.defaultStyles,
|
|
|
|
|
css`
|
|
|
|
|
:host {
|
|
|
|
|
display: block;
|
|
|
|
|
color: #fff;
|
|
|
|
|
font-family: 'Geist Sans';
|
|
|
|
|
}
|
|
|
|
|
:host([hidden]) {
|
|
|
|
|
display: none;
|
|
|
|
|
}
|
|
|
|
|
.viewContainer {
|
|
|
|
|
min-width: 100vh;
|
|
|
|
|
min-height: 100vh;
|
|
|
|
|
}
|
2024-10-04 02:18:47 +02:00
|
|
|
`,
|
2024-09-29 16:48:06 +02:00
|
|
|
];
|
|
|
|
|
|
|
|
|
|
public render(): TemplateResult {
|
|
|
|
|
return html`
|
|
|
|
|
<style></style>
|
2024-10-04 02:18:47 +02:00
|
|
|
<div class="viewContainer"></div>
|
2024-09-29 16:48:06 +02:00
|
|
|
`;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public currentElement: plugins.deesElement.DeesElement;
|
|
|
|
|
public async loadElement(viewElement: typeof plugins.deesElement.DeesElement) {
|
2024-10-04 02:18:47 +02:00
|
|
|
const idpState = await IdpState.getSingletonInstance();
|
|
|
|
|
|
2024-09-29 16:48:06 +02:00
|
|
|
// Wait until the viewContainer itself is rendered
|
|
|
|
|
await this.updateComplete;
|
|
|
|
|
|
|
|
|
|
// Select the viewContainer
|
|
|
|
|
const viewContainer = this.shadowRoot.querySelector('.viewContainer');
|
|
|
|
|
|
|
|
|
|
// Check if viewContainer is present
|
|
|
|
|
if (!viewContainer) {
|
|
|
|
|
throw new Error('View container not found in the rendered DOM.');
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// Remove the current element if it exists
|
|
|
|
|
if (this.currentElement) {
|
2024-10-04 15:43:36 +02:00
|
|
|
const currentElement = this.currentElement as any;
|
|
|
|
|
if (currentElement.hide) {
|
|
|
|
|
await currentElement.hide();
|
|
|
|
|
}
|
2024-09-29 16:48:06 +02:00
|
|
|
viewContainer.removeChild(this.currentElement);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// Create a new instance of the viewElement
|
2024-10-04 15:43:36 +02:00
|
|
|
const newElement = new viewElement() as any;
|
2024-09-29 16:48:06 +02:00
|
|
|
(newElement as any).viewContainer = this;
|
|
|
|
|
viewContainer.appendChild(newElement);
|
|
|
|
|
|
2024-10-04 15:43:36 +02:00
|
|
|
if (newElement.show) {
|
|
|
|
|
await newElement.show();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
2024-09-29 16:48:06 +02:00
|
|
|
// Wait until the new element is fully rendered
|
|
|
|
|
await newElement.updateComplete;
|
|
|
|
|
|
|
|
|
|
// Set the new element as the current element
|
|
|
|
|
this.currentElement = newElement;
|
|
|
|
|
}
|
2024-10-04 02:18:47 +02:00
|
|
|
|
|
|
|
|
public async firstUpdated() {
|
|
|
|
|
const idpState = await IdpState.getSingletonInstance();
|
|
|
|
|
idpState.mainStatePart
|
|
|
|
|
.select((stateArg) => stateArg.view)
|
|
|
|
|
.subscribe(async (viewArg) => {
|
|
|
|
|
switch (viewArg) {
|
|
|
|
|
case 'welcome':
|
|
|
|
|
await this.loadElement(elements.IdpWelcome);
|
|
|
|
|
break;
|
|
|
|
|
case 'login':
|
|
|
|
|
console.log('now on /login');
|
2024-10-04 15:43:36 +02:00
|
|
|
await this.loadElement(elements.IdpLoginPrompt);
|
2024-10-04 02:18:47 +02:00
|
|
|
break;
|
|
|
|
|
case 'register':
|
|
|
|
|
await this.loadElement(elements.IdpRegistrationPrompt);
|
|
|
|
|
break;
|
2024-10-04 15:43:36 +02:00
|
|
|
case 'finishregistration':
|
|
|
|
|
await this.loadElement(elements.IdpRegistrationStepper);
|
2024-10-04 02:18:47 +02:00
|
|
|
}
|
|
|
|
|
});
|
|
|
|
|
}
|
2024-09-29 16:48:06 +02:00
|
|
|
}
|