Skip to content

Commit

Permalink
Moving manifest to zos instead of expecting it from external app
Browse files Browse the repository at this point in the history
  • Loading branch information
RickyRoller committed Mar 7, 2025
1 parent e2b3ae9 commit 7358d2c
Show file tree
Hide file tree
Showing 7 changed files with 32 additions and 65 deletions.
7 changes: 2 additions & 5 deletions src/apps/explorer/index.tsx
Original file line number Diff line number Diff line change
@@ -1,12 +1,9 @@
import { Component } from 'react';
import { ExternalApp } from '../external-app';

const EXPLORER_ROUTE = '/explorer';
const EXPLORER_TITLE = 'Explorer';
const EXPLORER_URL = 'https://explorer.zero.tech/';
import { ExplorerManifest } from './manifest';

export class ExplorerApp extends Component {
render() {
return <ExternalApp route={EXPLORER_ROUTE} title={EXPLORER_TITLE} url={EXPLORER_URL} />;
return <ExternalApp manifest={ExplorerManifest} />;
}
}
8 changes: 8 additions & 0 deletions src/apps/explorer/manifest.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
import { ZAppManifest } from '../external-app/types/manifest';

export const ExplorerManifest: ZAppManifest = {
title: 'Explorer',
route: '/explorer',
url: 'https://explorer.zero.tech/',
features: [],
};
30 changes: 17 additions & 13 deletions src/apps/external-app/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -12,14 +12,13 @@ import { Dispatch, AnyAction } from 'redux';
import { IFrame } from '../iframe';
import { IncomingMessage } from './types/types';
import { routeChangedHandler } from './message-handlers/routeChangeHandler';
import { isAuthenticateEvent, isRouteChangeEvent, isSubmitManifestEvent } from './types/messageTypeGuard';
import { isAuthenticateEvent, isRouteChangeEvent } from './types/messageTypeGuard';
import { authenticateHandler } from './message-handlers/authenticateHandler';
import { submitManifestHandler } from './message-handlers/submitManifestHandler';
import { clearActiveZAppManifest } from '../../store/active-zapp';
import { clearActiveZAppManifest, setActiveZAppManifest } from '../../store/active-zapp';
import { ZAppManifest } from './types/manifest';

export interface PublicProperties {
route: `/${string}`;
title: string;
url: string;
manifest: ZAppManifest;
}

interface Properties extends PublicProperties {
Expand All @@ -40,14 +39,17 @@ class ExternalAppComponent extends Component<Properties, State> {
componentDidMount() {
const {
location: { pathname },
route,
url,
manifest: { route, url },
dispatch,
} = this.props;

const loadedUrl = new URL(pathname.replace(route, ''), url);
this.setState({ loadedUrl: loadedUrl.href });

window.addEventListener('message', this.onMessage);

// Register the manifest with the store
dispatch(setActiveZAppManifest(this.props.manifest));
}

componentWillUnmount(): void {
Expand All @@ -56,19 +58,21 @@ class ExternalAppComponent extends Component<Properties, State> {
}

onMessage = (event: MessageEvent<IncomingMessage>) => {
const {
history,
manifest: { route, url },
} = this.props;

if (isRouteChangeEvent(event)) {
const handler = routeChangedHandler(this.props.history, this.props.route, this.props.url);
const handler = routeChangedHandler(history, route, url);
handler(event);
} else if (isAuthenticateEvent(event)) {
authenticateHandler(event);
} else if (isSubmitManifestEvent(event)) {
const handler = submitManifestHandler(this.props.dispatch);
handler(event);
}
};

render() {
return <IFrame src={this.state.loadedUrl} title={this.props.title} />;
return <IFrame src={this.state.loadedUrl} title={this.props.manifest.title} />;
}
}

Expand Down
23 changes: 0 additions & 23 deletions src/apps/external-app/message-handlers/submitManifestHandler.ts

This file was deleted.

7 changes: 3 additions & 4 deletions src/apps/external-app/types/manifest.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,12 +3,11 @@ import { ZAppFeature } from './features';
/**
* The manifest is a JSON object that describes the app.
* It is used to provide information about the app to the zOS.
*
* For now, it'll just include features that the app supports. In the future,
* it'll include other information like the name, description, version, url, auth scopes, etc.
*/
type ZAppManifest = {
name: string;
title: string;
route: `/${string}`;
url: string;
features: ZAppFeature[];
};

Expand Down
14 changes: 1 addition & 13 deletions src/apps/external-app/types/messageTypeGuard.ts
Original file line number Diff line number Diff line change
@@ -1,21 +1,9 @@
import {
ZAppMessageType,
IncomingMessage,
RouteChangeMessage,
SubmitManifestMessage,
AuthenticateMessage,
} from './types';
import { ZAppMessageType, IncomingMessage, RouteChangeMessage, AuthenticateMessage } from './types';

export function isRouteChangeEvent(event: MessageEvent<IncomingMessage>): event is MessageEvent<RouteChangeMessage> {
return event.data.type === ZAppMessageType.RouteChange;
}

export function isSubmitManifestEvent(
event: MessageEvent<IncomingMessage>
): event is MessageEvent<SubmitManifestMessage> {
return event.data.type === ZAppMessageType.SubmitManifest;
}

export function isAuthenticateEvent(event: MessageEvent<IncomingMessage>): event is MessageEvent<AuthenticateMessage> {
return event.data.type === ZAppMessageType.Authenticate;
}
8 changes: 1 addition & 7 deletions src/apps/external-app/types/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -18,16 +18,11 @@ type RouteChangeMessage = {
};
};

type SubmitManifestMessage = {
type: ZAppMessageType.SubmitManifest;
manifest: ZAppManifest;
};

type AuthenticateMessage = {
type: ZAppMessageType.Authenticate;
};

type IncomingMessage = RouteChangeMessage | SubmitManifestMessage | AuthenticateMessage;
type IncomingMessage = RouteChangeMessage | AuthenticateMessage;

type ManifestResponseMessage = {
type: ZOSMessageType.ManifestReceived;
Expand All @@ -47,7 +42,6 @@ export type {
IncomingMessage,
OutgoingMessage,
RouteChangeMessage,
SubmitManifestMessage,
AuthenticateMessage,
ManifestResponseMessage,
AuthenticateResponseMessage,
Expand Down

0 comments on commit 7358d2c

Please sign in to comment.