Toggle navigation
Toggle navigation
This project
Loading...
Sign in
2021-1-capstone-design1
/
MAC_Project1
Go to a project
Toggle navigation
Toggle navigation pinning
Projects
Groups
Snippets
Help
Project
Activity
Repository
Pipelines
Graphs
Issues
0
Merge Requests
0
Wiki
Snippets
Network
Create a new issue
Builds
Commits
Issue Boards
Authored by
이정민
2021-04-22 00:59:04 +0900
Browse Files
Options
Browse Files
Download
Email Patches
Plain Diff
Commit
7a1200cac0904533a44b4e8e6be788f77e6ace8c
7a1200ca
1 parent
5b54f902
이미지 수정 플로우 변경
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
72 additions
and
51 deletions
src/components/Image.tsx
src/components/ToastEditor/index.tsx
src/pages/index.tsx
src/components/Image.tsx
View file @
7a1200c
...
...
@@ -5,9 +5,9 @@ import styled from "styled-components";
const ToastEditor = dynamic(() => import("components/ToastEditor"), {
ssr: false,
});
const Image = () => {
const Image = (
{ previewURL, setPreviewURL }
) => {
const [file, setFile] = useState(undefined);
cons
t [previewURL, setPreviewURL] = useState<string | ArrayBuffer>("");
cons
ole.log('previewURL',previewURL)
// const uploadImage = (file) => {
// if (!file) {
...
...
@@ -15,32 +15,32 @@ const Image = () => {
// }
// };
const selectImg = (e) => {
const reader = new FileReader();
const targetFile = e.target.files[0];
setFile(targetFile);
// uploadImage(targetFile);
//
const selectImg = (e) => {
//
const reader = new FileReader();
//
const targetFile = e.target.files[0];
//
setFile(targetFile);
//
// uploadImage(targetFile);
reader.onloadend = () => {
setPreviewURL(reader.result);
};
//
reader.onloadend = () => {
//
setPreviewURL(reader.result);
//
};
reader.readAsDataURL(targetFile);
};
//
reader.readAsDataURL(targetFile);
//
};
const [isEditorOpened, setIsEditorOpened] = useState(false);
const handleEditor = () => {
setIsEditorOpened(true);
};
//
const [isEditorOpened, setIsEditorOpened] = useState(false);
//
const handleEditor = () => {
//
setIsEditorOpened(true);
//
};
return (
<>
<Container>
<ImgBox>
<div onClick={handleEditor}>asdf</div>
{
file === undefined ? (
{/* <div onClick={handleEditor}>asdf</div> */}
{
/* {file === undefined ? ( */}
<>
<div className="sub-flex">
{/*
<div className="sub-flex">
<BlankBox />
<div>Click to add a photo</div>
<input
...
...
@@ -59,9 +59,9 @@ const Image = () => {
onChange={selectImg}
/>
</div>
<div className="sub-flex">Open Image Editor</div>
<div className="sub-flex">Open Image Editor</div>
*/}
</>
) : (
{/* ) : ( */}
<img
id="image"
alt={""}
...
...
@@ -69,15 +69,15 @@ const Image = () => {
objectFit: "cover",
display: "flex",
margin: "0 auto",
width: "
3
0rem",
width: "
5
0rem",
}}
src={previewURL as string}
/>
)
}
{/* )} */
}
</ImgBox>
{/* <Menu /> */}
</Container>
{
isEditorOpened && <ToastEditor {...{ setPreviewURL }} />
}
{
/* {isEditorOpened && <ToastEditor {...{ setPreviewURL, setIsImgAdded }} />} */
}
</>
);
};
...
...
src/components/ToastEditor/index.tsx
View file @
7a1200c
...
...
@@ -3,28 +3,28 @@ import ImageEditor from "@toast-ui/react-image-editor";
import { useEffect, useState } from "react";
import "tui-image-editor/dist/tui-image-editor.css";
const ToastEditor = ({ setPreviewURL }) => {
const [lowerCanvas, setLowerCanvas] = useState<HTMLCanvasElement>();
const [upperCanvas, setUpperCanvas] = useState<HTMLCanvasElement>();
// console.log(
// document.getElementsByClassName("lower-canvas")[0]?.toDataURL("image/png")
// );
console.log("s");
const ToastEditor = ({ setPreviewURL
, setIsImgAdded
}) => {
//
const [lowerCanvas, setLowerCanvas] = useState<HTMLCanvasElement>();
//
const [upperCanvas, setUpperCanvas] = useState<HTMLCanvasElement>();
//
//
console.log(
//
//
document.getElementsByClassName("lower-canvas")[0]?.toDataURL("image/png")
//
//
);
//
console.log("s");
// const [upperCanvas, setUpperCanvas] = useState(
// document.getElementsByClassName("upper-canvas ")[0]
// );
//
//
const [upperCanvas, setUpperCanvas] = useState(
//
//
document.getElementsByClassName("upper-canvas ")[0]
//
//
);
useEffect(() => {
window?.addEventListener("click", () => {
setLowerCanvas(
document.getElementsByClassName("lower-canvas")[0] as HTMLCanvasElement
);
setUpperCanvas(
document.getElementsByClassName("upper-canvas")[0] as HTMLCanvasElement
);
});
}, []);
//
useEffect(() => {
//
window?.addEventListener("click", () => {
//
setLowerCanvas(
//
document.getElementsByClassName("lower-canvas")[0] as HTMLCanvasElement
//
);
//
setUpperCanvas(
//
document.getElementsByClassName("upper-canvas")[0] as HTMLCanvasElement
//
);
//
});
//
}, []);
// useEffect(() => {
// const img = lowerCanvas?.toDataURL("image/png");
...
...
@@ -54,7 +54,10 @@ const ToastEditor = ({ setPreviewURL }) => {
// }, [lowerCanvas?.toDataURL("image/png")]);
const handleEnd = () => {
const lowerCanvas = document.getElementsByClassName("lower-canvas")[0] as HTMLCanvasElement;
setPreviewURL(lowerCanvas.toDataURL("image/png"));
console.log('asdf')
setIsImgAdded(true);
};
return (
...
...
src/pages/index.tsx
View file @
7a1200c
...
...
@@ -2,23 +2,41 @@ import Header from "components/Header";
import Image from "components/Image";
import styled from "styled-components";
import dynamic from "next/dynamic";
import { useState } from "react";
const ToastEditor = dynamic(() => import("components/ToastEditor"), {
ssr: false,
});
const Index = () => (
<Container>
<Header />
<Image />
{/* <ToastEditor /> */}
</Container>
);
const Index = () => {
const [isEditorOpened, setIsEditorOpened] = useState(false);
const [previewURL, setPreviewURL] = useState<string | ArrayBuffer>("");
const [isImgAdded, setIsImgAdded] = useState(false);
return (
<Container>
<Header />
{!isImgAdded ? (
<button className="open-button" onClick={() => setIsEditorOpened(true)}>
asdf
</button>
) : (
<Image {...{ previewURL, setPreviewURL }} />
)}
{isEditorOpened && !isImgAdded && (
<ToastEditor {...{ setPreviewURL, setIsImgAdded }} />
)}
</Container>
);
};
const Container = styled.div`
display: flex;
flex-direction: column;
align-items: center;
.open-button {
}
`;
export default Index;
...
...
Please
register
or
login
to post a comment