diff --git a/psoft-tools/package.json b/psoft-tools/package.json index d0b20de..b90fb1b 100644 --- a/psoft-tools/package.json +++ b/psoft-tools/package.json @@ -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", diff --git a/psoft-tools/src/components/DafnyEditor.tsx b/psoft-tools/src/components/DafnyEditor.tsx index ede2b9c..d7ed154 100644 --- a/psoft-tools/src/components/DafnyEditor.tsx +++ b/psoft-tools/src/components/DafnyEditor.tsx @@ -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"; @@ -41,5 +41,27 @@ export default function DafnyEditor({ }; }, [monaco]); - return ; + const editorRef = useRef(null); + + function handleEditorDidMount(editor, monaco) { + editorRef.current = editor; + } + + function showValue() { + globalThis.dafnyCode = editorRef.current?.getValue(); + } + + function clearValue() { + editorRef.current?.setValue(""); + } + + return (
+ +
+ ); } diff --git a/psoft-tools/src/custom.d.ts b/psoft-tools/src/custom.d.ts index 251c070..627ac90 100644 --- a/psoft-tools/src/custom.d.ts +++ b/psoft-tools/src/custom.d.ts @@ -1,4 +1,8 @@ declare module "*.svg" { const content: React.FunctionComponent>; export default content; - } \ No newline at end of file + } + +declare global { + var dafnyCode: string; +} \ No newline at end of file diff --git a/psoft-tools/src/pages/index.tsx b/psoft-tools/src/pages/index.tsx index 14ce84e..5454c9e 100644 --- a/psoft-tools/src/pages/index.tsx +++ b/psoft-tools/src/pages/index.tsx @@ -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"; @@ -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); @@ -95,7 +104,6 @@ export default function Index() { style={{ paddingTop: "50px", width: "100%", overflow: "hidden" }} >
-
-