Skip to content

Commit

Permalink
feat: render information from pod (#114)
Browse files Browse the repository at this point in the history
  • Loading branch information
Arne Vandoorslaer authored Jul 6, 2021
1 parent a61dc14 commit 79626f1
Show file tree
Hide file tree
Showing 3 changed files with 77 additions and 5 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ export class ProfileComponent extends BaseComponent {
const store = new Store(event.detail.data);

this.name = store.getQuads(null, new NamedNode(`${foaf}name`), null, null)[0]?.object.value;
this.avatar = store.getQuads(null, new NamedNode(`${n}hasPhoto`), null, null)[0]?.object.value;
this.avatar = store.getQuads(null, new NamedNode(`${n}hasPhoto`), null, null)[0]?.object.value ?? this.avatar;
this.job = store.getQuads(null, new NamedNode(`${n}role`), null, null)[0]?.object.value;
this.company = store.getQuads(null, new NamedNode(`${n}organization-name`), null, null)[0]?.object.value;
this.city = store.getQuads(null, new NamedNode(`${n}locality`), null, null)[0]?.object.value;
Expand Down
14 changes: 11 additions & 3 deletions packages/semcom-components/lib/demo.ts
Original file line number Diff line number Diff line change
Expand Up @@ -20,9 +20,13 @@ document.addEventListener(ComponentEventType.READ, (event: ComponentReadEvent) =

fetch(event.detail.uri).then((response) => response.text().then((profileText) => {

const target = event.target;

event.stopPropagation();

const quads = parser.parse(profileText);

event.target?.dispatchEvent(new ComponentResponseEvent({
target?.dispatchEvent(new ComponentResponseEvent({
detail: { uri: event.detail.uri, cause: event, data: quads, success: true },
}));

Expand All @@ -32,6 +36,10 @@ document.addEventListener(ComponentEventType.READ, (event: ComponentReadEvent) =

document.addEventListener(ComponentEventType.WRITE, (event: ComponentWriteEvent) => {

const target = event.target;

event.stopPropagation();

if (!event || !event.detail || !event.detail.uri) {

throw new Error('Argument event || !event.detail || !event.detail.uri should be set.');
Expand All @@ -42,13 +50,13 @@ document.addEventListener(ComponentEventType.WRITE, (event: ComponentWriteEvent)

new URL(event.detail.uri);

setTimeout(() => event.target?.dispatchEvent(new ComponentResponseEvent({
setTimeout(() => target?.dispatchEvent(new ComponentResponseEvent({
detail: { ...event.detail, cause: event, success: true },
})), 2000);

} catch(e) {

event.target?.dispatchEvent(new ComponentResponseEvent({
target?.dispatchEvent(new ComponentResponseEvent({
detail: { ...event.detail, cause: event, success: false },
}));

Expand Down
66 changes: 65 additions & 1 deletion packages/semcom-demo-app/src/demo.component.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,12 @@ import { createMachine, interpret, State } from 'xstate';
import { from } from 'rxjs';
import { RxLitElement } from 'rx-lit';
import { map } from 'rxjs/operators';
import { AuthenticateComponent, LoadingComponent, ProviderListComponent, ProviderListItemComponent, SolidSDKService } from '@digita-ai/ui-transfer-components';
import { AuthenticateComponent, LoadingComponent, ProviderListComponent, ProviderListItemComponent, Session, SolidSDKService } from '@digita-ai/ui-transfer-components';
import { ComponentMetadata } from '@digita-ai/semcom-core';
import { Theme } from '@digita-ai/ui-transfer-theme';
import { ComponentEventType, ComponentReadEvent, ComponentResponseEvent, ComponentWriteEvent } from '@digita-ai/semcom-sdk';
import { Parser } from 'n3';
import { fetch } from '@digita-ai/inrupt-solid-client';
import { demoMachine, DemoContext, DemoEvent, DemoState, DemoStates, AuthenticatedEvent } from './demo.machine';
import { SemComService } from './services/semcom.service';

Expand All @@ -28,6 +31,9 @@ export class DemoComponent extends RxLitElement {
@state()
components: ComponentMetadata[];

@state()
session: Session;

@query('.components')
contentElement: HTMLDivElement;

Expand All @@ -42,6 +48,7 @@ export class DemoComponent extends RxLitElement {
this.define('provider-list-item', ProviderListItemComponent);

this.subscribe('state', from(this.actor));
this.subscribe('session', from(this.actor).pipe(map((appState) => appState.context.session)));
this.subscribe('components', from(this.actor).pipe(map((appState) => appState.context.components)));

this.actor.start();
Expand All @@ -57,8 +64,65 @@ export class DemoComponent extends RxLitElement {
for (const component of this.components) {

const element = document.createElement('demo-' + component.tag);

const parser = new Parser();

element.addEventListener(ComponentEventType.READ, async (event: ComponentReadEvent) => {

const target = event.target;

event.stopPropagation();

if (!event || !event.detail || !event.detail.uri) {

throw new Error('Argument event || !event.detail || !event.detail.uri should be set.');

}

const response = await fetch(event.detail.uri);
const profileText = await response.text();
const quads = parser.parse(profileText);

target?.dispatchEvent(new ComponentResponseEvent({
detail: { uri: event.detail.uri, cause: event, data: quads, success: true },
}));

});

element.addEventListener(ComponentEventType.WRITE, (event: ComponentWriteEvent) => {

const target = event.target;

event.stopPropagation();

if (!event || !event.detail || !event.detail.uri) {

throw new Error('Argument event || !event.detail || !event.detail.uri should be set.');

}

try {

new URL(event.detail.uri);

setTimeout(() => target?.dispatchEvent(new ComponentResponseEvent({
detail: { ...event.detail, cause: event, success: true },
})), 2000);

} catch(e) {

target?.dispatchEvent(new ComponentResponseEvent({
detail: { ...event.detail, cause: event, success: false },
}));

}

});

this.contentElement.appendChild(element);

element.setAttribute('entry', this.session.webId);

}

}
Expand Down

0 comments on commit 79626f1

Please sign in to comment.