From b955fc8e6ccf372d8fc14e443e4599ae6152ca8e Mon Sep 17 00:00:00 2001 From: terminaldweller Date: Fri, 3 Jun 2022 12:25:13 +0430 Subject: wip --- spring-front/src/App.js | 80 +++++++++++++++++++++++++++++++++-- spring-front/src/components/Editor.js | 2 +- 2 files changed, 77 insertions(+), 5 deletions(-) (limited to 'spring-front') 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 (
- - - + {/* */} + + {/* */} + {/* */} + + {/* */} + {/* */} + + {/* */}
); } 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; -- cgit v1.2.3