diff options
author | terminaldweller <thabogre@gmail.com> | 2022-06-03 18:13:30 +0000 |
---|---|---|
committer | terminaldweller <thabogre@gmail.com> | 2022-06-03 18:13:30 +0000 |
commit | 5e8ba167f017a67263f03b3e8b25dcfa5ff7c98d (patch) | |
tree | 81305868877eb7841c01d7c99d06d52da03b8b89 /spring-front/src/App.js | |
parent | wip, the crud is working, now have to figure out how to update and save the a... (diff) | |
download | mdrtl-5e8ba167f017a67263f03b3e8b25dcfa5ff7c98d.tar.gz mdrtl-5e8ba167f017a67263f03b3e8b25dcfa5ff7c98d.zip |
wip. mostly working now. working out a few kinks.
Diffstat (limited to '')
-rw-r--r-- | spring-front/src/App.js | 97 |
1 files changed, 2 insertions, 95 deletions
diff --git a/spring-front/src/App.js b/spring-front/src/App.js index 50f1bf2..e965d51 100644 --- a/spring-front/src/App.js +++ b/spring-front/src/App.js @@ -1,108 +1,15 @@ -import React, { useState } from "react"; +import React 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); - } - console.log(this.docId); - this.markdownText = "tutti"; - this.loaded = false; - } - - genNewRandId() { - return Math.floor(Math.random() * (0x1 << 16)); - } - - // GET - 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.markdownText = response.body; - }) - .then((data) => { - console.log(data); - // this.markdownText = data.body; - }); - } - - // DELETE - handleDelete() { - fetch(`https://localhost:9080/api/v1/doc/${this.docId}`, { - method: "DELETE", - headers: { - Accept: "application/json", - }, - }).then((response) => { - if (!response.ok) { - throw new Error(`request failed with status ${response.status}`); - } - }); - } - - // POST - async handleSave() { - let obj = { - id: this.docId, - name: `${this.docId}`, - lastModified: Math.floor(Date.now() / 1000), - body: this.markdownText, - }; - let response = await fetch( - `https://localhost:9080/api/v1/doc/${this.docId}`, - { - method: "POST", - body: JSON.stringify(obj), - mode: "cors", - headers: { - Accept: "application/json", - "Content-Type": "application/json", - }, - } - ); - - if (!response.ok) { - throw new Error(`request failed with status code ${response.status}`); - } } render() { return ( <div> - <Editor markdownText={this.markdownText} loaded={this.loaded} /> - <img - className="icon" - src="load.jpg" - width="20" - height="20" - onClick={this.handleLoad.bind(this)} - /> - <img - className="icon" - src="trash3.png" - width="20" - height="20" - onClick={this.handleDelete.bind(this)} - /> - <img - className="icon" - src="save.png" - width="20" - height="20" - onClick={this.handleSave.bind(this)} - /> + <Editor /> </div> ); } |