aboutsummaryrefslogtreecommitdiffstats
path: root/spring-front/src/App.js
diff options
context:
space:
mode:
Diffstat (limited to 'spring-front/src/App.js')
-rw-r--r--spring-front/src/App.js62
1 files changed, 40 insertions, 22 deletions
diff --git a/spring-front/src/App.js b/spring-front/src/App.js
index b2b9866..50f1bf2 100644
--- a/spring-front/src/App.js
+++ b/spring-front/src/App.js
@@ -13,12 +13,16 @@ export default class App extends React.Component {
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) => {
@@ -26,39 +30,58 @@ export default class App extends React.Component {
throw new Error(`request failed with status ${response.status}`);
}
let res = response.json();
- this.docId = data.Id;
+ // this.markdownText = response.body;
})
.then((data) => {
console.log(data);
- this.docId = data.Id;
+ // this.markdownText = data.body;
});
}
+
+ // DELETE
handleDelete() {
- fetch(`https://localhost:9080/api/v1/doc/${this.docId}`);
+ 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}`);
+ }
+ });
}
- handleSave() {
+
+ // POST
+ async 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"
+ 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}`)
+ 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}"> */}
+ <Editor markdownText={this.markdownText} loaded={this.loaded} />
<img
className="icon"
src="load.jpg"
@@ -66,8 +89,6 @@ export default class App extends React.Component {
height="20"
onClick={this.handleLoad.bind(this)}
/>
- {/* </a> */}
- {/* <a href="https://localhost:9080/api/v1/doc/{this.docId}"> */}
<img
className="icon"
src="trash3.png"
@@ -75,8 +96,6 @@ export default class App extends React.Component {
height="20"
onClick={this.handleDelete.bind(this)}
/>
- {/* </a> */}
- {/* <a href="https://localhost:9080/api/v1/doc/{this.docId}"> */}
<img
className="icon"
src="save.png"
@@ -84,7 +103,6 @@ export default class App extends React.Component {
height="20"
onClick={this.handleSave.bind(this)}
/>
- {/* </a> */}
</div>
);
}