Add ability to save and view a list of workflows
This CL introduces the following functionality:
- Introduces some logic to handle the persistence of workflows in the
browser storage.
- Lets the user save created workflows in the "create workflow" dialog.
- Shows a list of workflows. If the user hasn't added any workflow, a
placeholder image is shown alongside a text which invites the user to
create a new workflow.
Bug: twpowertools:74
Change-Id: Icba09d20468bafc1415b802a3c935e22669546e6
diff --git a/src/workflows/common.js b/src/workflows/common.js
new file mode 100644
index 0000000..6d6ed03
--- /dev/null
+++ b/src/workflows/common.js
@@ -0,0 +1,16 @@
+// Source: https://stackoverflow.com/a/66046176
+export const arrayBufferToBase64 = async (data) => {
+ // Use a FileReader to generate a base64 data URI
+ const base64url = await new Promise((r) => {
+ const reader = new FileReader();
+ reader.onload = () => r(reader.result);
+ reader.readAsDataURL(new Blob([data]));
+ });
+
+ /*
+ The result looks like
+ "data:application/octet-stream;base64,<your base64 data>",
+ so we split off the beginning:
+ */
+ return base64url.split(',', 2)[1]
+}