diff options
author | terminaldweller <thabogre@gmail.com> | 2022-06-03 07:55:13 +0000 |
---|---|---|
committer | terminaldweller <thabogre@gmail.com> | 2022-06-03 07:55:13 +0000 |
commit | b955fc8e6ccf372d8fc14e443e4599ae6152ca8e (patch) | |
tree | 01777ce59ce8a0d439bdd26747fa66f31d4cd9d8 /spring-front/src/App.js | |
parent | removed useless ycm config (diff) | |
download | mdrtl-b955fc8e6ccf372d8fc14e443e4599ae6152ca8e.tar.gz mdrtl-b955fc8e6ccf372d8fc14e443e4599ae6152ca8e.zip |
wip
Diffstat (limited to 'spring-front/src/App.js')
-rw-r--r-- | spring-front/src/App.js | 80 |
1 files changed, 76 insertions, 4 deletions
diff --git a/spring-front/src/App.js b/spring-front/src/App.js index a91418e..b2b9866 100644 --- a/spring-front/src/App.js +++ b/spring-front/src/App.js @@ -1,18 +1,90 @@ -import React from "react"; +import React, { useState } from "react"; import Editor from "./components/Editor.js"; export default class App extends React.Component { constructor(props) { super(props); + this.genNewRandId = this.genNewRandId.bind(this); + this.handleLoad = this.handleLoad.bind(this); + this.handleSave = this.handleSave.bind(this); + this.handleDelete = this.handleDelete.bind(this); + this.docId = localStorage.getItem("docId"); + if (this.docId === null) { + this.docId = this.genNewRandId(); + localStorage.setItem("docId", this.docId); + } + } + + genNewRandId() { + return Math.floor(Math.random() * (0x1 << 16)); + } + + handleLoad() { + fetch(`https://localhost:9080/api/v1/doc/${this.docId}`) + .then((response) => { + if (!response.ok) { + throw new Error(`request failed with status ${response.status}`); + } + let res = response.json(); + this.docId = data.Id; + }) + .then((data) => { + console.log(data); + this.docId = data.Id; + }); + } + handleDelete() { + fetch(`https://localhost:9080/api/v1/doc/${this.docId}`); + } + handleSave() { + let obj = { + Id = this.docId, + Doc = props.markdownText + } + let response = await fetch(`https://localhost:9080/api/v1/doc/${this.docId}`,{ + method: "POST", + body: JSON.stringify(obj), + header: { + "Content-Type": "application/json" + } + }); + + if (!response.ok){ + throw new Error(`request failed with status code ${response.status}`) + } } render() { return ( <div> <Editor /> - <img className="icon" src="save.png" width="20" height="20" /> - <img className="icon" src="load.jpg" width="20" height="20" /> - <img className="icon" src="delete.png" width="20" height="20" /> + {/* <a href="https://localhost:9080/api/v1/doc/{this.docId}"> */} + <img + className="icon" + src="load.jpg" + width="20" + height="20" + onClick={this.handleLoad.bind(this)} + /> + {/* </a> */} + {/* <a href="https://localhost:9080/api/v1/doc/{this.docId}"> */} + <img + className="icon" + src="trash3.png" + width="20" + height="20" + onClick={this.handleDelete.bind(this)} + /> + {/* </a> */} + {/* <a href="https://localhost:9080/api/v1/doc/{this.docId}"> */} + <img + className="icon" + src="save.png" + width="20" + height="20" + onClick={this.handleSave.bind(this)} + /> + {/* </a> */} </div> ); } |