From 6496bfe08c2c5bae024ae942ed743a5266b30e6d Mon Sep 17 00:00:00 2001 From: terminaldweller Date: Fri, 3 Jun 2022 19:18:38 +0430 Subject: wip, the crud is working, now have to figure out how to update and save the actual text --- spring-front/nginx.conf | 2 +- spring-front/src/App.js | 62 ++++++++++++++++++++++------------- spring-front/src/components/Editor.js | 10 +++--- 3 files changed, 45 insertions(+), 29 deletions(-) (limited to 'spring-front') diff --git a/spring-front/nginx.conf b/spring-front/nginx.conf index 10e2785..cf2a208 100644 --- a/spring-front/nginx.conf +++ b/spring-front/nginx.conf @@ -21,7 +21,7 @@ http { tcp_nopush on; add_header X-Content-Type-Options "nosniff" always; add_header Strict-Transport-Security "max-age=31536000; includeSubDomains" always; - add_header Content-Security-Policy "default-src 'self'; script-src 'self' 'unsafe-inline' 'unsafe-eval' unpkg.com cdnjs.cloudflare.com; style-src 'self' 'unsafe-inline' unpkg.com cdnjs.cloudflare.com"; + add_header Content-Security-Policy "default-src 'self'; script-src 'self' 'unsafe-inline' 'unsafe-eval' unpkg.com cdnjs.cloudflare.com; style-src 'self' 'unsafe-inline' unpkg.com cdnjs.cloudflare.com; connect-src *;"; add_header X-Frame-Options SAMEORIGIN always; add_header X-XSS-Protection "1; mode=block" always; add_header Permissions-Policy "geolocation=(self),midi=(self),sync-xhr=(self),microphone=(self),camera=(self),magnetometer=(self),gyroscope=(self),fullscreen=(self),payment=(self),usb=(self)"; 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 (
- - {/* */} + - {/* */} - {/* */} - {/* */} - {/* */} - {/* */}
); } diff --git a/spring-front/src/components/Editor.js b/spring-front/src/components/Editor.js index f7c4ec5..d82a3fb 100644 --- a/spring-front/src/components/Editor.js +++ b/spring-front/src/components/Editor.js @@ -117,9 +117,9 @@ export default class Editor extends React.Component { this.setState((prevState) => ({ drawerActive: !prevState.drawerActive })); } - render() { - const { markdownText, drawerTitle, drawerChildren } = this.props; - const drawerStyles = this.state.drawerActive ? "is-expanded" : ""; + render(props) { + // const { markdownText, drawerTitle, drawerChildren } = this.props; + // const drawerStyles = this.state.drawerActive ? "is-expanded" : ""; return (
@@ -142,9 +142,7 @@ export default class Editor extends React.Component { onKeyDown={this.handleKeyDown.bind(this)} direction="rtl" tabIndex="0" - > - {markdownText} - + >
-- cgit v1.2.3