forked from webxdc/webxdc-dev
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathInstance.tsx
71 lines (61 loc) · 1.83 KB
/
Instance.tsx
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
import { Component, Show } from "solid-js";
import { Flex, createDisclosure, notificationService } from "@hope-ui/solid";
import { Instance as InstanceData } from "../types/instance";
import { Search } from "./Sidebar";
import InstanceStarted from "./InstanceStarted";
import InstanceStopped from "./InstanceStopped";
import InstanceHeader from "./InstanceHeader";
const Instance: Component<{
instance: InstanceData;
setSearch: (search: Search) => void;
}> = (props) => {
let iframeRef: HTMLIFrameElement | undefined = undefined;
const handleReload = () => {
if (iframeRef == null) {
return;
}
iframeRef.contentWindow?.postMessage("reload", props.instance.url);
notificationService.show({
title: `Instance ${props.instance.id} reloaded`,
});
};
const { isOpen, onOpen, onClose } = createDisclosure({
defaultIsOpen: false,
});
const getStyle = () => {
return {
// XXX these dimensions should be configurable somehow
height: "667px",
width: "375px",
"border-color": props.instance.color,
"border-width": "7px",
"border-style": "solid",
};
};
return (
<Flex id={"instance-" + props.instance.id} flexDirection="column">
<InstanceHeader
instance={props.instance}
setSearch={props.setSearch}
onReload={handleReload}
onStart={onOpen}
onStop={onClose}
isStarted={isOpen}
/>
<Show
when={isOpen()}
fallback={<InstanceStopped onStart={onOpen} style={getStyle()} />}
>
<InstanceStarted
instance={props.instance}
ref={iframeRef}
style={getStyle()}
/>
</Show>
</Flex>
);
};
export const scrollToInstance = (instanceId: string) => {
document.getElementById("instance-" + instanceId)?.scrollIntoView();
};
export default Instance;