aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorterminaldweller <thabogre@gmail.com>2022-06-17 17:56:14 +0000
committerterminaldweller <thabogre@gmail.com>2022-06-17 17:56:14 +0000
commit4b2a5b8b09b02de9e855a1e5e9a75101d6c334bc (patch)
treebb33c8ff297e6c9faaa91f43f1191734b05b440a
parentCORS fix (diff)
downloadmdrtl-4b2a5b8b09b02de9e855a1e5e9a75101d6c334bc.tar.gz
mdrtl-4b2a5b8b09b02de9e855a1e5e9a75101d6c334bc.zip
added comments
-rw-r--r--spring-front/src/components/Editor.js39
-rw-r--r--src/main/java/com/terminaldweller/doc/Doc.java1
-rw-r--r--src/main/java/com/terminaldweller/doc/DocService.java8
-rw-r--r--src/main/java/com/terminaldweller/main/DevConfiguration.java6
4 files changed, 51 insertions, 3 deletions
diff --git a/spring-front/src/components/Editor.js b/spring-front/src/components/Editor.js
index 108d87d..ac13882 100644
--- a/spring-front/src/components/Editor.js
+++ b/spring-front/src/components/Editor.js
@@ -59,6 +59,10 @@ export default class Editor extends React.Component {
}
// TODO-use web worker instead
+ /**
+ * Highlights all the pre-code elements in the page, both the left-hand
+ * and righ-hand side.
+ */
updateCodeSyntaxHighlighting() {
document.querySelectorAll("pre code").forEach((block) => {
hljs.highlightElement(block);
@@ -70,6 +74,10 @@ export default class Editor extends React.Component {
}
// TODO-use web worker instead
+ /**
+ * Parses the markdown to create the rendered HTML for the right-hand
+ * side of the page.
+ */
parseMarkdown(event) {
let element = document.getElementById("markdown-placeholder");
let htm = md.render(event.target.value);
@@ -84,6 +92,10 @@ export default class Editor extends React.Component {
// this.setState({ value: event.target.value });
}
+ /**
+ * Updates the syntax highlighting and markdown rendering when the
+ * text changes inside the left-hand side editor.
+ */
handleInput(event) {
let result_element = document.getElementById("highlight-content");
result_element.textContent = event.target.value;
@@ -99,6 +111,10 @@ export default class Editor extends React.Component {
this.setState({ value: event.target.value });
}
+ /**
+ * Scrolls both the pre-code area and the text area together so
+ * we get the illusion of the two elements moving together.
+ */
handleScroll(event) {
let result_element = document.querySelector("#highlight-content");
result_element.scrollTop = event.currentTarget.scrollTop;
@@ -109,6 +125,9 @@ export default class Editor extends React.Component {
result_element_2.scrollLeft = event.currentTarget.scrollLeft;
}
+ /**
+ * Handles Tab correctly so the text area acts like an editor.
+ */
handleKeyDown(event) {
let element = event.currentTarget;
let code = this.state.value;
@@ -128,11 +147,17 @@ export default class Editor extends React.Component {
this.setState((prevState) => ({ drawerActive: !prevState.drawerActive }));
}
+ /**
+ * generates a random ID that's will be used to store the document.
+ */
genNewRandId() {
return Math.floor(Math.random() * (0x1 << 16));
}
- // DELETE
+ /**
+ * The document DELETE method. simply sends a DELETE request to delete
+ * the document from the database.
+ */
handleDelete() {
fetch(`${mdrtlConfig.serverURL}/${this.docId}`, {
method: "DELETE",
@@ -146,7 +171,10 @@ export default class Editor extends React.Component {
});
}
- // GET
+ /**
+ * The document LOAD method. sends a GET request to the database with
+ * the document id ID which is saved in local storage.
+ */
handleLoad(event) {
let res;
fetch(`${mdrtlConfig.serverURL}/${this.docId}`).then((response) => {
@@ -165,7 +193,12 @@ export default class Editor extends React.Component {
});
}
- // POST & PUT
+ /**
+ * The SAVE method. If no document with the given ID exists sends a POST
+ * request to the database to create the document with document id ID.
+ * If the document has been previously saved, then sends a PUT request
+ * to update the last modified date and document text.
+ */
async handleSave() {
let obj = {
id: this.docId,
diff --git a/src/main/java/com/terminaldweller/doc/Doc.java b/src/main/java/com/terminaldweller/doc/Doc.java
index 80247eb..35ee5fd 100644
--- a/src/main/java/com/terminaldweller/doc/Doc.java
+++ b/src/main/java/com/terminaldweller/doc/Doc.java
@@ -25,6 +25,7 @@ public class Doc {
* @param id the id given by the db.
* @param name the name of the documment given by the user.
* @param lastModified the date of the last modification in unix epoch.
+ * @param body the actual text of the document.
*/
public Doc(Long id, String name, long lastModified, String body) {
this.id = id;
diff --git a/src/main/java/com/terminaldweller/doc/DocService.java b/src/main/java/com/terminaldweller/doc/DocService.java
index df4456e..a885b9a 100644
--- a/src/main/java/com/terminaldweller/doc/DocService.java
+++ b/src/main/java/com/terminaldweller/doc/DocService.java
@@ -14,6 +14,12 @@ public class DocService {
this.docRepository = docRepository;
}
+ /**
+ * get a document by its id.
+ *
+ * @param id of the document to get.
+ * @return returns the found doc if any.
+ */
public Optional<Doc> getDocs(Long id) {
Optional<Doc> docOptional = docRepository.findById(id);
if (docOptional.isPresent()) {
@@ -26,6 +32,7 @@ public class DocService {
* Adds a new Document to the data store.
*
* @param doc the new Document to add.
+ * @param id the id of the document that's going to be created.
*/
public void addNewDoc(Long id, Doc doc) {
// Optional<Doc> docOptional = docRepository.findDocByName(doc.getName());
@@ -41,6 +48,7 @@ public class DocService {
* Update a Document.
*
* @param doc the document to update.
+ * @param id the id of the document to be updated.
*/
public void updateDoc(Doc doc, Long id) {
Optional<Doc> docOptional = docRepository.findById(id);
diff --git a/src/main/java/com/terminaldweller/main/DevConfiguration.java b/src/main/java/com/terminaldweller/main/DevConfiguration.java
index 0b253df..b63ca7b 100644
--- a/src/main/java/com/terminaldweller/main/DevConfiguration.java
+++ b/src/main/java/com/terminaldweller/main/DevConfiguration.java
@@ -6,11 +6,17 @@ import org.springframework.web.servlet.config.annotation.CorsRegistry;
import org.springframework.web.servlet.config.annotation.EnableWebMvc;
import org.springframework.web.servlet.config.annotation.WebMvcConfigurer;
+/** The server config class. */
@Configuration
@EnableWebMvc
@Profile("development")
public class DevConfiguration implements WebMvcConfigurer {
+ /**
+ * Configuring CORS headers.
+ *
+ * @param registry the registry.
+ */
@Override
public void addCorsMappings(CorsRegistry registry) {
registry