Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions psoft-tools/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@
},
"dependencies": {
"@monaco-editor/react": "^4.6.0",
"@types/react-router-dom": "^5.3.3",
"autoprefixer": "^10.4.17",
"postcss": "^8.4.35",
"react": "^18.2.0",
Expand Down
26 changes: 24 additions & 2 deletions psoft-tools/src/components/DafnyEditor.tsx
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { EditorProps, useMonaco } from "@monaco-editor/react";
import { useEffect } from "react";
import { useEffect, useRef } from "react";
import { Editor } from "@monaco-editor/react";
import useDafny from "../hooks/useDafny";

Expand Down Expand Up @@ -41,5 +41,27 @@ export default function DafnyEditor({
};
}, [monaco]);

return <Editor {...EditorProps} />;
const editorRef = useRef(null);

function handleEditorDidMount(editor, monaco) {
editorRef.current = editor;
}

function showValue() {
globalThis.dafnyCode = editorRef.current?.getValue();
}

function clearValue() {
editorRef.current?.setValue("");
}

return (<div><button onClick={clearValue}>Clear</button>
<Editor {
...EditorProps}
value={"// Please enter Dafny code below and delete this comment!"}
onMount={handleEditorDidMount}
onChange={showValue}
/>
</div>
);
}
6 changes: 5 additions & 1 deletion psoft-tools/src/custom.d.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,8 @@
declare module "*.svg" {
const content: React.FunctionComponent<React.SVGAttributes<SVGElement>>;
export default content;
}
}

declare global {
var dafnyCode: string;
}
15 changes: 11 additions & 4 deletions psoft-tools/src/pages/index.tsx
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import Navbar from "../components/Navbar";
import { useState } from "react";
import { useState, useRef } from "react";
import { post } from "../lib/api";
import { ThreeDots } from "react-loader-spinner";
import DafnyEditor from "../components/DafnyEditor";
Expand All @@ -19,7 +19,16 @@ export default function Index() {

const handleVerify = () => {
setLoading(true);
post("http://localhost:3000/verify", code)
var obj = {
requester: "postman",
files: [
{
name: "problem.dfy",
content: globalThis.dafnyCode
}
]
}
post("http://localhost/compile", JSON.stringify(obj))
.then((response) => {
setLoading(false);
setData(response);
Expand Down Expand Up @@ -95,7 +104,6 @@ export default function Index() {
style={{ paddingTop: "50px", width: "100%", overflow: "hidden" }}
>
<div style={{ width: "50%", justifyContent: "left" }}>

<DafnyEditor
EditorProps={{
height: "92vh",
Expand All @@ -114,7 +122,6 @@ export default function Index() {
)}
</div>
<div className="flex flex-row justify-evenly max-h-11 mb-4">
<button onClick={handleClickClear}>Clear</button>
<button onClick={handleVerify}>Verify Dafny</button>
<button onClick={handleRun}>Run Dafny</button>
</div>
Expand Down