Skip to content

Commit 0f60861

Browse files
committed
Fixed resize bug, trading view listens to intents
1 parent 32990a3 commit 0f60861

File tree

10 files changed

+86
-21
lines changed

10 files changed

+86
-21
lines changed

directory/sail.json

+13-1
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,19 @@
2222
{
2323
"src": "/static/example-apps/tradingview/tradingview-icon.png"
2424
}
25-
]
25+
],
26+
"interop": {
27+
"intents": {
28+
"listensFor": {
29+
"ViewChart": {
30+
"contexts": [
31+
"fdc3.instrument"
32+
],
33+
"displayName": "View Chart"
34+
}
35+
}
36+
}
37+
}
2638
}
2739
],
2840
"message": "OK"

src/client/grid/grid.tsx

+1
Original file line numberDiff line numberDiff line change
@@ -114,6 +114,7 @@ export const Content = ({
114114
}}
115115
/>
116116
</div>
117+
<div className={styles.resizeBaffle} />
117118
<div className={styles.contentBody}>
118119
{panel.url ? <AppSlot panel={panel} /> : <div />}
119120
</div>

src/client/grid/gridstate.ts

+9-2
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
11
import { GridItemHTMLElement, GridStack, GridStackElement, GridStackWidget } from "gridstack"
22
import { ReactElement } from "react"
3-
import ReactDOM from 'react-dom';
43
import { AppPanel, ClientState } from "../state/clientState"
54
import { createRoot } from 'react-dom/client';
5+
import * as styles from "./styles.module.css";
66

77

88
const TRASH_DROP = "trash";
@@ -89,7 +89,8 @@ export class GridsStateImpl implements GridsState {
8989
{
9090
removable: "#" + TRASH_DROP,
9191
acceptWidgets: true,
92-
margin: '1'
92+
margin: '1',
93+
cellHeight: '70px'
9394
},
9495
e as GridStackElement
9596
)
@@ -104,6 +105,12 @@ export class GridsStateImpl implements GridsState {
104105
this.cs.updatePanel(panel)
105106
}
106107
}
108+
109+
element.classList.remove(styles.resizing)
110+
})
111+
112+
grid.on("resizestart", (_event, element) => {
113+
element.classList.add(styles.resizing)
107114
})
108115

109116
grid.on("removed", (event, items) => {

src/client/grid/styles.module.css

+16
Original file line numberDiff line numberDiff line change
@@ -40,6 +40,22 @@
4040
padding-right: .2rem;
4141
}
4242

43+
.resizeBaffle {
44+
display: none;
45+
position: absolute;
46+
top: 2rem;
47+
left: 0;
48+
right: 0;
49+
bottom: 0;
50+
background-color: white;
51+
z-index: 1000;
52+
}
53+
54+
.resizing .resizeBaffle {
55+
display: block;
56+
background-color: #FFFFFF22;
57+
}
58+
4359
.contentBody {
4460
position: absolute;
4561
top: 2rem;

src/client/resolver/resolver.tsx

+1
Original file line numberDiff line numberDiff line change
@@ -192,6 +192,7 @@ export const ResolverPanel = ({
192192
<div className={styles.resolverPane}>
193193
{intentsToUse.map((i) => (
194194
<LineItemComponent
195+
key={i}
195196
li={i}
196197
text={i}
197198
setState={(a) => {

src/client/state/AppState.ts

+9-2
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,12 @@
1-
import { WebConnectionProtocol1Hello } from "@kite9/fdc3-common";
1+
import { BrowserTypes } from "@kite9/fdc3";
22
import { getClientState } from "./clientState"
33
import { getServerState } from "./ServerState"
44
import { DirectoryApp } from "@kite9/fdc3-web-impl";
55
import { v4 as uuid } from 'uuid'
66

7+
type WebConnectionProtocol1Hello = BrowserTypes.WebConnectionProtocol1Hello
8+
9+
710
interface AppState {
811

912
registerAppWindow(window: Window, instanceId: string): void
@@ -21,7 +24,11 @@ class DefaultAppState implements AppState {
2124
async getDirectoryAppForUrl(identityUrl: string): DirectoryApp {
2225
const strippedIdentityUrl = identityUrl.replace(/\/$/, "")
2326
const applications: DirectoryApp[] = await getServerState().getApplications()
24-
const firstMatchingApp = applications.find(x => (x.details.url == strippedIdentityUrl) || (x.details.url == identityUrl))
27+
const firstMatchingApp = applications.find(x =>
28+
(x.details.url == strippedIdentityUrl) ||
29+
(x.details.url == identityUrl) ||
30+
((x.details.url.startsWith("/")) && identityUrl.endsWith(x.details.url)) // allows for local urls
31+
)
2532
return firstMatchingApp
2633
}
2734

src/example-apps/tradingview/TradingViewWidget.tsx

+31-8
Original file line numberDiff line numberDiff line change
@@ -1,30 +1,53 @@
11
// TradingViewWidget.jsx
2-
import { useEffect, useRef, memo } from "react";
2+
import { getAgent } from "@kite9/fdc3";
3+
import { useEffect, useRef, memo, useState } from "react";
34

4-
export function TradingViewWidget() {
5+
export const TradingViewWidget = () => {
56
const container: any = useRef();
67

8+
const [state, setState] = useState("MSFT");
9+
10+
useEffect(() => {
11+
getAgent().then((fdc3) => {
12+
fdc3.addIntentListener("ViewChart", async (context) => {
13+
setState(context?.id?.ticker);
14+
});
15+
});
16+
}, []);
17+
718
useEffect(() => {
8-
const script = document.createElement("script");
19+
var script: HTMLScriptElement | null = null;
20+
21+
script = document.getElementById(
22+
"tradingview-widget-script",
23+
) as HTMLScriptElement;
24+
25+
if (script) {
26+
container.current.removeChild(script);
27+
}
28+
29+
script = document.createElement("script");
30+
container.current.appendChild(script);
31+
32+
script!!.id = "tradingview-widget-script";
933
script.src =
1034
"https://s3.tradingview.com/external-embedding/embed-widget-advanced-chart.js";
1135
script.type = "text/javascript";
1236
script.async = true;
1337
script.innerHTML = `
1438
{
1539
"autosize": true,
16-
"symbol": "NASDAQ:AAPL",
40+
"symbol": "NASDAQ:${state}",
1741
"interval": "D",
1842
"timezone": "Etc/UTC",
1943
"theme": "light",
2044
"style": "1",
2145
"locale": "en",
22-
"allow_symbol_change": true,
46+
"allow_symbol_change": false,
2347
"calendar": false,
2448
"support_host": "https://www.tradingview.com"
2549
}`;
26-
container.current.appendChild(script);
27-
}, []);
50+
}, [state]);
2851

2952
return (
3053
<div
@@ -47,6 +70,6 @@ export function TradingViewWidget() {
4770
</div>
4871
</div>
4972
);
50-
}
73+
};
5174

5275
export default memo(TradingViewWidget);
+2-6
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,7 @@
11
import { createRoot } from "react-dom/client";
2-
import { TradingViewWidget } from "./TradingViewWidget";
3-
import { getAgent } from "@kite9/fdc3";
2+
import TradingViewWidget from "./TradingViewWidget";
43

54
const container = document.getElementById("app");
65
const root = createRoot(container!);
7-
root.render(<TradingViewWidget />);
86

9-
window.onload = async () => {
10-
const fdc3 = await getAgent();
11-
};
7+
root.render(<TradingViewWidget />);

src/server/da/SailServerContext.ts

+2-1
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,8 @@ export enum State { Pending, Open, Closed }
1111

1212
export type SailData = AppIdentifier & {
1313
socket?: Socket,
14-
state: State
14+
state: State,
15+
url?: string
1516
}
1617

1718
export class SailServerContext implements ServerContext<SailData> {

src/server/da/initSocketService.ts

+2-1
Original file line numberDiff line numberDiff line change
@@ -83,13 +83,14 @@ export function initSocketService(httpServer: any, sessions: Map<string, SailFDC
8383
if (fdc3Server != undefined) {
8484
console.log("An app connected: ", userSessionId, appInstanceId)
8585
const appInstance = fdc3Server.getServerContext().getInstanceDetails(appInstanceId)
86+
const directoryItem = fdc3Server.getServerContext().directory.retrieveAppsById(props.appId)
8687
if ((appInstance != undefined) && (appInstance.state == State.Pending)) {
8788
appInstance.socket = socket
89+
appInstance.url = directoryItem[0].details.url
8890
fdc3ServerInstance = fdc3Server
8991
fdc3ServerInstance.serverContext.setAppConnected({ appId: props.appId, instanceId: appInstanceId })
9092
} else if (DEBUG_MODE) {
9193
console.error("App tried to connect with invalid instance id, allowing connection anyway ", appInstanceId)
92-
const directoryItem = fdc3Server.getServerContext().directory.retrieveAppsById(props.appId)
9394

9495
fdc3Server?.serverContext.setInstanceDetails(appInstanceId, {
9596
appId: props.appId,

0 commit comments

Comments
 (0)