-
Notifications
You must be signed in to change notification settings - Fork 13
Expand file tree
/
Copy pathdev-tool.tsx
More file actions
64 lines (59 loc) · 1.85 KB
/
Copy pathdev-tool.tsx
File metadata and controls
64 lines (59 loc) · 1.85 KB
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
import { store } from '@graphprotocol/hypergraph';
import { useSelector } from '@xstate/store/react';
import { useState } from 'react';
import { Button } from './ui/button';
export function DevTool({ spaceId }: { spaceId: string }) {
const [isOpen, setIsOpen] = useState(false);
const spaces = useSelector(store, (state) => state.context.spaces);
const updatesInFlight = useSelector(store, (state) => state.context.updatesInFlight);
const space = spaces.find((space) => space.id === spaceId);
return (
<>
<div className="flex flex-row gap-2">
<Button
onClick={(event) => {
event.preventDefault();
setIsOpen(!isOpen);
}}
>
Hypergraph DevTool
</Button>
</div>
{isOpen && !space && <div>Space not found</div>}
{isOpen && space && (
<>
<h3>Space id: {space.id}</h3>
<p>Keys:</p>
<pre className="text-xs">{JSON.stringify(space.keys)}</pre>
<br />
<h3>Updates in flight</h3>
<ul className="text-xs">
{updatesInFlight.map((updateInFlight) => {
return (
<li key={updateInFlight} className="border border-gray-300">
{updateInFlight}
</li>
);
})}
</ul>
<hr />
<h3>State</h3>
<div className="text-xs">
<pre>{JSON.stringify(space.state, null, 2)}</pre>
</div>
<hr />
<h3>Events</h3>
<ul className="text-xs">
{space.events.map((event) => {
return (
<li key={event.transaction.id} className="border border-gray-300">
<pre>{JSON.stringify(event, null, 2)}</pre>
</li>
);
})}
</ul>
</>
)}
</>
);
}