blob: b2b9866ca7069cdfc21d5bac4b4798f7374ce1b1 (
plain) (
blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
|
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 />
{/* <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>
);
}
}
|