aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorterminaldweller <thabogre@gmail.com>2022-06-03 07:55:13 +0000
committerterminaldweller <thabogre@gmail.com>2022-06-03 07:55:13 +0000
commitb955fc8e6ccf372d8fc14e443e4599ae6152ca8e (patch)
tree01777ce59ce8a0d439bdd26747fa66f31d4cd9d8
parentremoved useless ycm config (diff)
downloadmdrtl-b955fc8e6ccf372d8fc14e443e4599ae6152ca8e.tar.gz
mdrtl-b955fc8e6ccf372d8fc14e443e4599ae6152ca8e.zip
wip
-rw-r--r--spring-front/src/App.js80
-rw-r--r--spring-front/src/components/Editor.js2
2 files changed, 77 insertions, 5 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>
);
}
diff --git a/spring-front/src/components/Editor.js b/spring-front/src/components/Editor.js
index eee31a9..f7c4ec5 100644
--- a/spring-front/src/components/Editor.js
+++ b/spring-front/src/components/Editor.js
@@ -1,4 +1,4 @@
-import React from "react";
+import React, { useState } from "react";
import ReactDOM from "react-dom";
import hljs from "highlight.js/lib/core";
// const hljs = window.hljs;