이정민

UI 수정

...@@ -18,6 +18,10 @@ const GifEditor = ({ previewURL }) => { ...@@ -18,6 +18,10 @@ const GifEditor = ({ previewURL }) => {
18 const [download, setDownload] = useState(null); 18 const [download, setDownload] = useState(null);
19 const [blob, setBlob] = useState(null); 19 const [blob, setBlob] = useState(null);
20 20
21 + const [isMakeStarted, setIsMakeStarted] = useState(false);
22 + const [isUploadLoading, setIsUploadLoading] = useState(false);
23 + const [viewLink, setViewLink] = useState(null);
24 +
21 useEffect(() => { 25 useEffect(() => {
22 if (window) { 26 if (window) {
23 setImageEditor( 27 setImageEditor(
...@@ -31,7 +35,7 @@ const GifEditor = ({ previewURL }) => { ...@@ -31,7 +35,7 @@ const GifEditor = ({ previewURL }) => {
31 width: "100%", 35 width: "100%",
32 height: "600px", 36 height: "600px",
33 }, 37 },
34 - initMenu: "filter", 38 + menu: ["draw", "text"],
35 menuBarPosition: "bottom", 39 menuBarPosition: "bottom",
36 }, 40 },
37 cssMaxWidth: 500, 41 cssMaxWidth: 500,
...@@ -48,16 +52,14 @@ const GifEditor = ({ previewURL }) => { ...@@ -48,16 +52,14 @@ const GifEditor = ({ previewURL }) => {
48 } 52 }
49 }, [imageEditor]); 53 }, [imageEditor]);
50 54
51 - const render = () => { 55 + const makeGif = () => {
52 - console.log("aaa", imageEditor._graphics.getCanvas().getObjects()); 56 + setIsMakeStarted(true);
53 const gifGenerator = new window.GifGenerator( 57 const gifGenerator = new window.GifGenerator(
54 imageEditor._graphics.getCanvas() 58 imageEditor._graphics.getCanvas()
55 ); 59 );
56 gifGenerator.make().then( 60 gifGenerator.make().then(
57 (blob) => { 61 (blob) => {
58 setBlob(blob); 62 setBlob(blob);
59 - console.log("blobaaa", blob);
60 - // console.log(window.URL.createObjectURL(blob));
61 setDownload(window.URL.createObjectURL(blob)); 63 setDownload(window.URL.createObjectURL(blob));
62 }, 64 },
63 (error) => { 65 (error) => {
...@@ -67,29 +69,51 @@ const GifEditor = ({ previewURL }) => { ...@@ -67,29 +69,51 @@ const GifEditor = ({ previewURL }) => {
67 }; 69 };
68 70
69 const handleUpload = async () => { 71 const handleUpload = async () => {
70 - const file = new File([blob], "file.gif"); 72 + setIsUploadLoading(true);
73 + const file = new File([blob], "new_gif.gif");
71 const formData = new FormData(); 74 const formData = new FormData();
72 formData.append("gif", file); 75 formData.append("gif", file);
73 const res = await postGif(formData); 76 const res = await postGif(formData);
74 console.log(res); 77 console.log(res);
78 + setIsUploadLoading(false);
79 + setViewLink(
80 + `https://gif-generator.s3.ap-northeast-2.amazonaws.com//gif/${res.id}.gif`
81 + );
75 }; 82 };
76 83
77 return ( 84 return (
78 <> 85 <>
79 <Wrapper> 86 <Wrapper>
80 - {download && ( 87 + {((isMakeStarted && !download) || isUploadLoading) && (
81 - <div style={{ display: "flex" }}> 88 + <>
82 - <a href={download} download="new_file_name.gif"> 89 + <div className="background" />
83 - download 90 + <div className="download">loading...</div>
84 - </a> 91 + </>
85 - <div onClick={handleUpload}>server upload</div> 92 + )}
93 + {!isUploadLoading && viewLink && (
94 + <div className="download" style={{ zIndex: 200 }}>
95 + <a href={viewLink}>{viewLink}</a>
86 </div> 96 </div>
87 )} 97 )}
88 - <div onClick={render} className="upload"> 98 + {download && !isUploadLoading && (
89 - Save 99 + <>
100 + <div className="background" />
101 + <div className="download">
102 + <div className="download__btn">
103 + <a href={download} download="new_gif.gif">
104 + Download a File
105 + </a>
106 + </div>
107 + <div className="download__btn">
108 + <div onClick={handleUpload}>Upload to Server</div>
109 + </div>
110 + </div>
111 + </>
112 + )}
113 + <div onClick={makeGif} className="make">
114 + Make a Gif
90 </div> 115 </div>
91 <div ref={rootEl} /> 116 <div ref={rootEl} />
92 - <div className="alert">Please select a photo.</div>
93 </Wrapper> 117 </Wrapper>
94 </> 118 </>
95 ); 119 );
...@@ -98,13 +122,17 @@ const GifEditor = ({ previewURL }) => { ...@@ -98,13 +122,17 @@ const GifEditor = ({ previewURL }) => {
98 const Wrapper = styled.div` 122 const Wrapper = styled.div`
99 position: fixed; 123 position: fixed;
100 width: 90%; 124 width: 90%;
101 - top: 15rem; 125 + top: 10rem;
102 border-radius: 1.5rem; 126 border-radius: 1.5rem;
103 box-shadow: ${({ theme }) => theme.boxShadow.normal}; 127 box-shadow: ${({ theme }) => theme.boxShadow.normal};
104 display: flex; 128 display: flex;
105 flex-direction: column; 129 flex-direction: column;
106 align-items: center; 130 align-items: center;
107 - .upload { 131 + a {
132 + color: black;
133 + text-decoration: none;
134 + }
135 + .make {
108 font: 800 11.5px Arial; 136 font: 800 11.5px Arial;
109 position: absolute; 137 position: absolute;
110 right: 0; 138 right: 0;
...@@ -121,11 +149,30 @@ const Wrapper = styled.div` ...@@ -121,11 +149,30 @@ const Wrapper = styled.div`
121 justify-content: center; 149 justify-content: center;
122 cursor: pointer; 150 cursor: pointer;
123 } 151 }
124 - .alert { 152 + .background {
125 position: fixed; 153 position: fixed;
126 - border-radius: 0.5rem; 154 + top: 0;
127 - transition: 1s; 155 + left: 0;
128 - top: 7rem; 156 + width: 100%;
157 + height: 100vh;
158 + background-color: black;
159 + opacity: 0.7;
160 + z-index: 100;
161 + }
162 + .download {
163 + position: absolute;
164 + top: 15rem;
165 + z-index: 100;
166 + display: flex;
167 + background-color: white;
168 + padding: 1.5rem 2rem;
169 + border-radius: 2rem;
170 + &__btn {
171 + cursor: pointer;
172 + :last-child {
173 + margin-left: 1rem;
174 + }
175 + }
129 } 176 }
130 .tui-image-editor-container { 177 .tui-image-editor-container {
131 border-radius: 1.5rem; 178 border-radius: 1.5rem;
...@@ -137,6 +184,9 @@ const Wrapper = styled.div` ...@@ -137,6 +184,9 @@ const Wrapper = styled.div`
137 .tui-image-editor-header-logo { 184 .tui-image-editor-header-logo {
138 display: none; 185 display: none;
139 } 186 }
187 + .tui-image-editor-header-buttons {
188 + display: none;
189 + }
140 `; 190 `;
141 191
142 export default GifEditor; 192 export default GifEditor;
......
...@@ -28,15 +28,14 @@ const ToastEditor = ({ setPreviewURL, setIsImgAdded, setIsEditorOpened }) => { ...@@ -28,15 +28,14 @@ const ToastEditor = ({ setPreviewURL, setIsImgAdded, setIsEditorOpened }) => {
28 28
29 return ( 29 return (
30 <Container> 30 <Container>
31 - <div onClick={handleEnd} className="upload"> 31 + <div onClick={handleEnd} className="move">
32 - Upload 32 + Move to Gif
33 </div> 33 </div>
34 <ImageEditor 34 <ImageEditor
35 includeUI={{ 35 includeUI={{
36 loadImage: { 36 loadImage: {
37 name: "SampleImage", 37 name: "SampleImage",
38 }, 38 },
39 - initMenu: "filter",
40 uiSize: { 39 uiSize: {
41 width: "100%", 40 width: "100%",
42 height: "600px", 41 height: "600px",
...@@ -67,7 +66,7 @@ const Container = styled.div` ...@@ -67,7 +66,7 @@ const Container = styled.div`
67 display: flex; 66 display: flex;
68 flex-direction: column; 67 flex-direction: column;
69 align-items: center; 68 align-items: center;
70 - .upload { 69 + .move {
71 font: 800 11.5px Arial; 70 font: 800 11.5px Arial;
72 position: absolute; 71 position: absolute;
73 right: 0; 72 right: 0;
......