@@ -15,14 +15,15 @@ const Shape = dynamic(import("react-clip-path"), { ssr: false });
1515// Switch
1616import Switch from "react-switch" ;
1717
18- // html-to-image
19- import { toPng } from 'html-to-image' ;
20-
21- // downloadjs
22- import download from 'downloadjs' ;
23-
2418// icons
2519import { FiCopy , FiDownload , FiHeart , FiLock } from 'react-icons/fi' ;
20+ import { BiExport } from "react-icons/bi" ;
21+
22+ // Export Shape
23+ import { ExportShape } from '..' ;
24+
25+ // misc unitless
26+ import { getShapeFileName , getShapeId } from '../../utils/misc' ;
2627
2728// Shape Listing Styled-Componentns
2829const ShapeCards = styled . div `
@@ -86,7 +87,7 @@ const CopyIcon = styled(FiCopy)`
8687 }
8788` ;
8889
89- const DownloadIcon = styled ( FiDownload ) `
90+ const ExportIcon = styled ( BiExport ) `
9091 cursor: pointer;
9192 &:hover {
9293 color: #f71b76;
@@ -100,9 +101,11 @@ const LikeIcon = styled(FiHeart)`
100101 }
101102` ;
102103
103- const ShapeList = ( { data } ) => {
104+ const ShapeList = ( { setOpen , user , data } ) => {
104105
105106 const [ shapes , setShapes ] = useState ( data ) ;
107+ const [ showExportModal , setShowExportModal ] = useState ( false ) ;
108+ const [ shapeToExport , setShapeToExport ] = useState ( ) ;
106109
107110 const handleSwicth = ( shapeName ) => {
108111
@@ -118,20 +121,6 @@ const ShapeList = ({ data }) => {
118121 setShapes ( ...[ modifiedShapes ] ) ;
119122 } ;
120123
121- const getShapeFileName = ( name ) => {
122- return name . split ( " " ) . join ( "-" ) ;
123- } ;
124-
125- const saveAsPng = ( event , id , name ) => {
126- console . log ( 'Save as Png' ) ;
127-
128- toPng ( document . getElementById ( id ) ) . then ( function ( dataUrl ) {
129- console . log ( dataUrl ) ;
130- download ( dataUrl , `${ name } .png` ) ;
131- toast . success ( `${ name } .png has been exported sucessfully!` ) ;
132- } ) ;
133- }
134-
135124 async function performCopy ( event , formula ) {
136125 event . preventDefault ( ) ;
137126 try {
@@ -143,9 +132,22 @@ const ShapeList = ({ data }) => {
143132 }
144133 }
145134
135+ const performExport = shape => {
136+ if ( user . length === 0 ) {
137+ setOpen ( true ) ;
138+ } else {
139+ setShapeToExport ( shape ) ;
140+ setShowExportModal ( true ) ;
141+ }
142+ }
143+
146144 return (
147145 < ShapePallete >
148146 < ShapeCards >
147+ < ExportShape
148+ show = { showExportModal }
149+ setShow = { setShowExportModal }
150+ shape = { shapeToExport } />
149151 { shapes . map ( ( shape , index ) => (
150152 < React . Fragment key = { index } >
151153 < ShapeCard >
@@ -156,16 +158,10 @@ const ShapeList = ({ data }) => {
156158 < span title = "Like" >
157159 < LikeIcon size = { 24 } />
158160 </ span > { " " }
159- < span title = "Download " >
160- < DownloadIcon
161+ < span title = "Export " >
162+ < ExportIcon
161163 size = { 24 }
162- onClick = { ( event ) =>
163- saveAsPng (
164- event ,
165- `${ getShapeFileName ( shape . name ) } -id` ,
166- getShapeFileName ( shape . name )
167- )
168- }
164+ onClick = { ( ) => performExport ( shape ) }
169165 />
170166 </ span >
171167 </ ShapeActions >
@@ -174,7 +170,7 @@ const ShapeList = ({ data }) => {
174170 width = "300px"
175171 height = "300px"
176172 name = { shape . name }
177- id = { ` ${ getShapeFileName ( shape . name ) } -id` }
173+ id = { getShapeId ( shape . name ) }
178174 backgroundColor = "#eb3d86"
179175 showShadow = { shape . showAdvanced }
180176 />
0 commit comments