From 1025c5b7224a5c8961fbd692623fc0df6a3622b7 Mon Sep 17 00:00:00 2001 From: brausjonas Date: Fri, 7 Jul 2023 18:20:50 +0200 Subject: [PATCH] More Input Form --- src/Drawing.js | 14 +++++++++++ src/Save.js | 17 +++++++++++++ src/StartForm.js | 63 ++++++++++++++++++++++++++++++++++++------------ 3 files changed, 78 insertions(+), 16 deletions(-) create mode 100644 src/Save.js diff --git a/src/Drawing.js b/src/Drawing.js index 17d7d98..45fd522 100644 --- a/src/Drawing.js +++ b/src/Drawing.js @@ -1,5 +1,6 @@ import './App.css'; import {useEffect, useLayoutEffect, useRef, useState} from "react"; +import {Save} from "./Save"; let mouseDownMenuBar = false let mouseDownCanvas = false @@ -688,6 +689,19 @@ export default function Drawing(p) { pointerEvents: "auto" }} onClick={() => { + let save = canvas.toDataURL("image/png") + let arrString = localStorage.getItem("save") + if(arrString !== null) { + let json = JSON.parse(arrString) + json.arr.push(new Save(save)) + localStorage.setItem("save", JSON.stringify(json)) + } + else { + let json = { + arr: [new Save(save)] + } + localStorage.setItem("save", JSON.stringify(json)) + } window.location.reload() }}> Home diff --git a/src/Save.js b/src/Save.js new file mode 100644 index 0000000..0b636ac --- /dev/null +++ b/src/Save.js @@ -0,0 +1,17 @@ +export class Save { + constructor(content) { + let localID = localStorage.getItem("id") + this.id = 0 + let now = new Date() + this.name = now.getFullYear() + "." + (now.getMonth() + 1)+ "." + now.getDate() + "-" + now.getHours() + "h" + now.getMinutes() + "-" + now.getSeconds() + "s" + if(localID !== null) { + this.id = parseInt(localID) + 1 + localStorage.setItem("id", this.id) + } + else { + localStorage.setItem("id", 0) + } + + this.content = content + } +} \ No newline at end of file diff --git a/src/StartForm.js b/src/StartForm.js index 7fda8b6..b833825 100644 --- a/src/StartForm.js +++ b/src/StartForm.js @@ -1,14 +1,22 @@ -import {useEffect} from "react"; +import {useEffect, useState} from "react"; let inputWidth, inputHeight export default function StartForm(p) { + const [saves, setSaves] = useState([]) + useEffect(() => { - if(p.show !== "none") { + if (p.show !== "none") { inputWidth = document.getElementById("inputWidth") inputHeight = document.getElementById("inputHeight") } + + let saveString = localStorage.getItem("save") + + if (saveString !== null) { + setSaves(JSON.parse(saveString).arr) + } }, []) useEffect(() => { @@ -22,21 +30,21 @@ export default function StartForm(p) { width: "100vw", height: "100vh", justifyContent: "center", - alignItems: "center" + alignItems: "center", }}>
-

Welcome To ReDraw

+

Welcome To ReDraw

-

Specify your drawing canvas width and height

+

Specify your drawing canvas width and height

Create + style={{ + boxShadow: "0 0 5px gray", + borderWidth: 0, + borderRadius: 15, + padding: 10, + background: "rgba(0, 0, 0, 0)" + }}>Create +
-

Please note that ReDraw is still in beta and will not guarantee correctness

+

Recent:

+
+ {saves.map(e => ( +
{ + console.log("test") + }}>

{e.name}

+ ))} +
);