Skip to content

Commit

Permalink
added documentation for front end
Browse files Browse the repository at this point in the history
  • Loading branch information
Eurydia committed Jan 6, 2024
1 parent 87865d2 commit 2bb0d0c
Show file tree
Hide file tree
Showing 8 changed files with 102 additions and 35 deletions.
19 changes: 19 additions & 0 deletions docs/technical-documentation/frontend/01-sharable-link.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
# Sharable link

One of the main features of the application is the ability to share a diagram with other users via a sharable link.

The link is generated by setting a query parameter in the URL to the content of the code editor.

The content of the query parameter is read into the code editor when the application is loaded.

Here is a snippet for generating the sharable link:

```ts
const url = new URL(window.location.href);
url.searchParams.set("preview", "true");
url.searchParams.set("content", editorContent);
navigator.clipboard.writeText(url.href);
enqueueSnackbar("Copied link to clipboard", {
variant: "info",
});
```
32 changes: 32 additions & 0 deletions docs/technical-documentation/frontend/02-exporting-diagrams.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
# Exporting diagrams

The diagram itself is an HTML element, but the main issue is that browsers do not provide a way to export an HTML element as an image.

The current solution is to capture the diagram element, convert to a data URL, then download it as an image.

The conversion step is handled by [html-to-image](https://github.com/bubkoo/html-to-image).
It provides simple APIs to capture an HTML element and convert it to a data URL.
In the project, I used `toPng`, `toSvg` and `toJpeg` functions.

The download step is handled by [FileSaver.js](https://github.com/eligrey/FileSaver.js)

Here is a snippet of the code:

```ts
const HTMLNode = document.getElementById(
"structogram-preview",
);
if (HTMLNode === null) {
return;
}
toSvg(HTMLNode).then((blob) => {
if (blob === null) {
return;
}
if (window.saveAs) {
window.saveAs(blob, "diagram");
} else {
saveAs(blob, "diagram");
}
});
```
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
# Snackbar notification

When copying a shareable link or exporting a diagram, a snackbar notification will appear to provide feedback to the user.
This is handled by [Notistack](https://iamhosseindhv.com/notistack).

There is no practical reason why I chose Notistack over other libraries, apart from the fact that it is built on top of Material UI, so it is very easy to integrate it with Material UI.
5 changes: 5 additions & 0 deletions docs/technical-documentation/frontend/04-ui-library.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
# UI library

The UI library is built with [Material UI](https://material-ui.com/).

I was tempted to use other icon libraries like [Font Awesome](https://fontawesome.com/) or [Feather Icons](https://feathericons.com/), but I decided to stick with [MUI Icon](https://material-ui.com/components/material-icons/) for style consistency.
5 changes: 5 additions & 0 deletions docs/technical-documentation/frontend/05-code-editor.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
# Code editor

The code editor is the most important part of the project, so I want to a few functionalities of text editors such auto-pairing brackets, syntax highlighting, etc.

The code editor is built with [CodeMirror](https://codemirror.net/), which is a very popular text editor library.
35 changes: 35 additions & 0 deletions docs/technical-documentation/frontend/06-auto-saving.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
# Auto-saving

The save the progress of the user, the application automatically saves the content of the code editor to the browser's local storage when a change has been made to the code editor.

```ts
useEffect(() => {
localStorage.setItem(
"editorContent",
editorContent,
);
}, [editorContent]);
```

This is a very simple solution, but it is not perfect.

There will be cases where the user opened a sharable link while having some previous progress saved in the local storage.
In this case, the content of the code editor will be overwritten by the content of the sharable link.

I have decided that the sharable link should take precedence over the local storage, so the content of the sharable link will be loaded into the code editor if it is available.

```ts
const url = new URL(window.location.href);
const content = url.searchParams.get("content");
if (content !== null) {
window.localStorage.setItem("content", content);
return content;
}

const savedContent =
window.localStorage.getItem("content");
if (savedContent !== null) {
return savedContent;
}
return "";
```
2 changes: 0 additions & 2 deletions docs/technical-documentation/renderer/02-structogram-node.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,6 @@

This compnent is a collection of smaller components that are used to render a `Node` object as a `StructogramNodeLoopFirst`, `StructogramNodeLoopLast`, `StructogramNodeIfElse`, or `StructogramNodeProcess` component based on its `kind` property.

The `StructogramNode` component is a functional component that takes a `Node` object and optional border properties as its props. It uses a switch statement to determine the `kind` of the `Node` object and renders different components accordingly.

Here is an interface of the component:

```tsx
Expand Down
33 changes: 0 additions & 33 deletions docs/technical-documentation/web-technologies.md

This file was deleted.

0 comments on commit 2bb0d0c

Please sign in to comment.