Skip to content

Commit 5b4aacb

Browse files
committed
re-organize demo
1 parent 864081b commit 5b4aacb

File tree

9 files changed

+295
-222
lines changed

9 files changed

+295
-222
lines changed

demo/package-lock.json

Lines changed: 10 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

demo/package.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@
1515
"haddock-restraints-wasm": "file:../wasm/pkg",
1616
"react": "^19.1.0",
1717
"react-dom": "^19.1.0",
18+
"react-icons": "^5.5.0",
1819
"tailwindcss": "^4.1.10"
1920
},
2021
"devDependencies": {

demo/src/App.tsx

Lines changed: 2 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,7 @@
1-
import { Interactor } from "./Components/Interactor";
1+
import { GenTbl } from "./GenTbl";
22

33
function App() {
4-
return (
5-
<>
6-
<Interactor />
7-
</>
8-
);
4+
return <GenTbl />;
95
}
106

117
export default App;

demo/src/Components/Interactor.tsx

Lines changed: 0 additions & 216 deletions
This file was deleted.

demo/src/GenTbl.tsx

Lines changed: 78 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,78 @@
1+
// GenTbl.tsx (main component)
2+
import init, { WasmAir, WasmInteractor } from "haddock-restraints-wasm";
3+
import { IoAdd } from "react-icons/io5";
4+
import { useInteractors } from "./hooks/useInteractors";
5+
import { InteractorForm } from "./components/InteractorForm";
6+
import { TblOutput } from "./components/TblOutput";
7+
import { GenerateRestraintsButton } from "./components/GenerateRestraintsButton";
8+
9+
export const GenTbl = () => {
10+
const {
11+
interactors,
12+
tbl,
13+
setTbl,
14+
addInteractor,
15+
removeInteractor,
16+
updateInteractor,
17+
} = useInteractors();
18+
19+
async function gen_tbl() {
20+
await init();
21+
22+
const wasmInteractors = interactors.map((interactor) => {
23+
const wasmInteractor = new WasmInteractor(
24+
interactor.id,
25+
interactor.chain,
26+
new Int16Array(interactor.active),
27+
new Int16Array(interactor.passive),
28+
);
29+
30+
if (interactor.target) {
31+
wasmInteractor.set_target(interactor.target);
32+
}
33+
34+
return wasmInteractor;
35+
});
36+
37+
const air = new WasmAir(wasmInteractors);
38+
setTbl(air.gen_tbl());
39+
}
40+
41+
return (
42+
<div className="container mx-auto p-6 max-w-6xl">
43+
<h1 className="text-2xl font-bold text-gray-800 mb-6">
44+
HADDOCK Restraints Generator
45+
</h1>
46+
47+
<div className="bg-white rounded-lg shadow-md p-6 mb-6">
48+
<div className="flex justify-between items-center mb-4">
49+
<h2 className="text-xl font-semibold text-gray-700">Interactors</h2>
50+
<button
51+
onClick={addInteractor}
52+
className="px-4 py-2 bg-blue-600 text-white rounded-md hover:bg-blue-700 transition-colors flex items-center"
53+
>
54+
<IoAdd className="mr-2" />
55+
Add Interactor
56+
</button>
57+
</div>
58+
59+
<div className="space-y-4">
60+
{interactors.map((interactor) => (
61+
<InteractorForm
62+
key={interactor.id}
63+
interactor={interactor}
64+
otherInteractors={interactors.filter(
65+
(i) => i.id !== interactor.id,
66+
)}
67+
onRemove={removeInteractor}
68+
onUpdate={updateInteractor}
69+
/>
70+
))}
71+
</div>
72+
</div>
73+
74+
<GenerateRestraintsButton onClick={gen_tbl} />
75+
<TblOutput tbl={tbl} />
76+
</div>
77+
);
78+
};
Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
import React from "react";
2+
import { IoRocket } from "react-icons/io5";
3+
4+
interface GenerateButtonProps {
5+
onClick: () => void;
6+
}
7+
8+
export const GenerateRestraintsButton: React.FC<GenerateButtonProps> = ({
9+
onClick,
10+
}) => (
11+
<div className="flex justify-center my-6">
12+
<button
13+
onClick={onClick}
14+
className="px-6 py-3 bg-green-600 text-white rounded-md hover:bg-green-700 transition-colors font-medium"
15+
>
16+
<IoRocket className="inline-block mr-2" />
17+
Generate Restraints
18+
</button>
19+
</div>
20+
);

0 commit comments

Comments
 (0)