@@ -6,36 +6,15 @@ import { harperFetch } from "../../utils/HarperFetch";
66
77// Dummy Shape Data
88// import { shapes } from "../../data/shapes";
9-
10- // Toast
11- import toast from "react-hot-toast" ;
12-
13- // Clip-Path
14- const Shape = dynamic ( import ( "react-clip-path" ) , { ssr : false } ) ;
15-
16- // Switch
17- import Switch from "react-switch" ;
18-
199// loader
2010import Loader from "react-loader-spinner" ;
2111
22- import {
23- ShapeCards ,
24- ShapeCard ,
25- ShapeName ,
26- ShapePallete ,
27- ShapeDetailsItems ,
28- ShapeCardSwitch ,
29- ShapeActions ,
30- ShapeCardHeader ,
31- CopyIcon ,
32- DownloadIcon ,
33- LikeIcon ,
34- } from "../utils/StyledComponents" ;
12+ // ShapeListing
13+ import { ShapeList } from '..' ;
3514
3615const App = ( props ) => {
3716 const [ data , setData ] = useState ( [ ] ) ;
38- const [ loading , setLoading ] = useState ( false ) ;
17+ const [ loading , setLoading ] = useState ( true ) ;
3918
4019 useEffect ( async ( ) => {
4120 setData ( [ ] ) ;
@@ -46,48 +25,19 @@ const App = (props) => {
4625 operation : "sql" ,
4726 sql : "SELECT * FROM tryshape.shapes" ,
4827 } ) ;
49-
5028 console . log ( shapes ) ;
5129 let modifiedShapes = shapes . map ( ( shape , index ) => {
5230 shape . showAdvanced = false ;
5331 return shape ;
5432 } ) ;
33+
5534 console . log ( modifiedShapes ) ;
5635
5736 await setData ( modifiedShapes ) ;
5837 setLoading ( false ) ;
5938 } , [ ] ) ;
6039
61- const handleSwicth = ( shapeName ) => {
62- console . log ( shapeName ) ;
63-
64- let modifiedShapes = data . map ( ( shape , index ) => {
65- if ( shape . name === shapeName ) {
66- return {
67- ...shape ,
68- showAdvanced : ! shape . showAdvanced ,
69- } ;
70- }
71- return shape ;
72- } ) ;
73- console . log ( modifiedShapes ) ;
74- setData ( ...[ modifiedShapes ] ) ;
75- } ;
76-
77- const getShapeFileName = ( name ) => {
78- return name . split ( " " ) . join ( "-" ) ;
79- } ;
80-
81- async function performCopy ( event , formula ) {
82- event . preventDefault ( ) ;
83- try {
84- await navigator . clipboard . writeText ( formula ) ;
85- toast . success ( "Successfully Copied!" ) ;
86- console . log ( "The clip-path formula copied to clipboard" ) ;
87- } catch ( err ) {
88- console . error ( "Failed to copy: " , err ) ;
89- }
90- }
40+
9141
9242 return (
9343 < >
@@ -100,72 +50,7 @@ const App = (props) => {
10050 width = { 300 }
10151 />
10252 ) : (
103- < ShapePallete >
104- < ShapeCards >
105- { data . map ( ( shape , index ) => (
106- < React . Fragment key = { index } >
107- < ShapeCard >
108- < ShapeCardHeader >
109- < ShapeName > { shape . name } </ ShapeName >
110- < ShapeActions >
111- < span title = "Like" >
112- < LikeIcon size = { 24 } />
113- </ span > { " " }
114- < span title = "Download" >
115- < DownloadIcon
116- size = { 24 }
117- onClick = { ( event ) =>
118- saveAsPng (
119- event ,
120- `${ getShapeFileName ( shape . name ) } -id` ,
121- getShapeFileName ( shape . name )
122- )
123- }
124- />
125- </ span >
126- </ ShapeActions >
127- </ ShapeCardHeader >
128- < Shape
129- width = "300px"
130- height = "300px"
131- name = { shape . name }
132- id = { `${ getShapeFileName ( shape . name ) } -id` }
133- backgroundColor = "#eb3d86"
134- showShadow = { shape . showAdvanced }
135- />
136-
137- < ShapeCardSwitch >
138- < label htmlFor = { `${ getShapeFileName ( shape . name ) } -form` } >
139- < span > Show Clip-Path Info</ span > { " " }
140- < Switch
141- onChange = { ( ) => handleSwicth ( shape . name ) }
142- checked = { shape . showAdvanced }
143- id = { `${ getShapeFileName ( shape . name ) } -form` }
144- />
145- </ label >
146- </ ShapeCardSwitch >
147-
148- { shape . showAdvanced && (
149- < ShapeDetailsItems >
150- < span >
151- < b > Clip-Path:</ b > { " " }
152- < code >
153- < b > { shape . formula } </ b >
154- </ code >
155- </ span > { " " }
156- < span title = "Copy" >
157- < CopyIcon
158- size = { 24 }
159- onClick = { ( event ) => performCopy ( event , shape . formula ) }
160- />
161- </ span >
162- </ ShapeDetailsItems >
163- ) }
164- </ ShapeCard >
165- </ React . Fragment >
166- ) ) }
167- </ ShapeCards >
168- </ ShapePallete >
53+ < ShapeList data = { data } />
16954 ) }
17055 </ >
17156 ) ;
0 commit comments