11import React , { useEffect , useState } from "react" ;
2- import dynamic from ' next/dynamic' ;
2+ import dynamic from " next/dynamic" ;
33import { harperFetch } from "../../utils/HarperFetch" ;
44
55import { shapes } from "../../data/shapes" ;
66
7- const Shape = dynamic ( import ( 'react-clip-path' ) , { ssr : false } )
7+ import toast from "react-hot-toast" ;
8+
9+ const Shape = dynamic ( import ( "react-clip-path" ) , { ssr : false } ) ;
810import Switch from "react-switch" ;
911
1012import {
@@ -13,8 +15,9 @@ import {
1315 ShapeName ,
1416 ShapePallete ,
1517 ShapeDetailsItems ,
18+ ShapeCardSwitch ,
1619 ShapeActions ,
17- ShapeHeader ,
20+ ShapeCardHeader ,
1821 CopyIcon ,
1922 DownloadIcon ,
2023 LikeIcon ,
@@ -47,20 +50,19 @@ const App = (props) => {
4750
4851 const handleSwicth = ( shapeName ) => {
4952 console . log ( shapeName ) ;
50-
5153
5254 let modifiedShapes = data . map ( ( shape , index ) => {
5355 if ( shape . name === shapeName ) {
5456 return {
5557 ...shape ,
56- showAdvanced : ! shape . showAdvanced
57- }
58+ showAdvanced : ! shape . showAdvanced ,
59+ } ;
5860 }
5961 return shape ;
6062 } ) ;
6163 console . log ( modifiedShapes ) ;
6264 setData ( ...[ modifiedShapes ] ) ;
63- }
65+ } ;
6466
6567 const getShapeFileName = ( name ) => {
6668 return name . split ( " " ) . join ( "-" ) ;
@@ -70,78 +72,86 @@ const App = (props) => {
7072 event . preventDefault ( ) ;
7173 try {
7274 await navigator . clipboard . writeText ( formula ) ;
75+ toast . success ( "Successfully Copied!" ) ;
7376 console . log ( "The clip-path formula copied to clipboard" ) ;
7477 } catch ( err ) {
7578 console . error ( "Failed to copy: " , err ) ;
7679 }
7780 }
7881
7982 return (
80- < ShapePallete >
81- < h2 > Available Shapes({ shapes . length } )</ h2 >
82- < ShapeCards >
83- { data . map ( ( shape , index ) => (
84- < React . Fragment key = { index } >
85- < ShapeCard >
86- < ShapeHeader >
87- < ShapeName > { shape . name } </ ShapeName >
88- < ShapeActions >
89- < span title = "Like" >
90- < LikeIcon size = { 24 } />
91- </ span > { " " }
92- < span title = "Download" >
93- < DownloadIcon
94- size = { 24 }
95- onClick = { ( event ) =>
96- saveAsPng (
97- event ,
98- `${ getShapeFileName ( shape . name ) } -id` ,
99- getShapeFileName ( shape . name )
100- )
101- }
102- />
103- </ span >
104- </ ShapeActions >
105- </ ShapeHeader >
106- < Shape
107- width = "300px"
108- height = "300px"
109- name = { shape . name }
110- id = { `${ getShapeFileName ( shape . name ) } -id` }
111- backgroundColor = "#eb3d86"
112- showShadow = { shape . showAdvanced }
113- />
114-
115- < label htmlFor = { `${ getShapeFileName ( shape . name ) } -form` } >
116- < span > Show Advanced</ span > { ' ' }
117- < Switch
118- onChange = { ( ) => handleSwicth ( shape . name ) }
119- checked = { shape . showAdvanced }
120- id = { `${ getShapeFileName ( shape . name ) } -form` }
121- />
122- </ label >
123-
124- { shape . showAdvanced && (
125- < ShapeDetailsItems >
126- < span >
127- < b > Clip-Path:</ b > { " " }
128- < code >
129- < b > { shape . formula } </ b >
130- </ code >
131- </ span > { " " }
132- < span title = "Copy" >
133- < CopyIcon
134- size = { 24 }
135- onClick = { ( event ) => performCopy ( event , shape . formula ) }
136- />
137- </ span >
138- </ ShapeDetailsItems >
139- ) }
140- </ ShapeCard >
141- </ React . Fragment >
142- ) ) }
143- </ ShapeCards >
144- </ ShapePallete >
83+ < >
84+ { loading ? (
85+ < h1 > Loading...</ h1 >
86+ ) : (
87+ < ShapePallete >
88+ < ShapeCards >
89+ { data . map ( ( shape , index ) => (
90+ < React . Fragment key = { index } >
91+ < ShapeCard >
92+ < ShapeCardHeader >
93+ < ShapeName > { shape . name } </ ShapeName >
94+ < ShapeActions >
95+ < span title = "Like" >
96+ < LikeIcon size = { 24 } />
97+ </ span > { " " }
98+ < span title = "Download" >
99+ < DownloadIcon
100+ size = { 24 }
101+ onClick = { ( event ) =>
102+ saveAsPng (
103+ event ,
104+ `${ getShapeFileName ( shape . name ) } -id` ,
105+ getShapeFileName ( shape . name )
106+ )
107+ }
108+ />
109+ </ span >
110+ </ ShapeActions >
111+ </ ShapeCardHeader >
112+ < Shape
113+ width = "300px"
114+ height = "300px"
115+ name = { shape . name }
116+ id = { `${ getShapeFileName ( shape . name ) } -id` }
117+ backgroundColor = "#eb3d86"
118+ showShadow = { shape . showAdvanced }
119+ />
120+
121+ < ShapeCardSwitch >
122+ < label htmlFor = { `${ getShapeFileName ( shape . name ) } -form` } >
123+ < span > Show Clip-Path Info</ span > { " " }
124+ < Switch
125+ onChange = { ( ) => handleSwicth ( shape . name ) }
126+ checked = { shape . showAdvanced }
127+ id = { `${ getShapeFileName ( shape . name ) } -form` }
128+ />
129+ </ label >
130+ </ ShapeCardSwitch >
131+
132+ { shape . showAdvanced && (
133+ < ShapeDetailsItems >
134+ < span >
135+ < b > Clip-Path:</ b > { " " }
136+ < code >
137+ < b > { shape . formula } </ b >
138+ </ code >
139+ </ span > { " " }
140+ < span title = "Copy" >
141+ < CopyIcon
142+ size = { 24 }
143+ onClick = { ( event ) => performCopy ( event , shape . formula ) }
144+ />
145+ </ span >
146+ </ ShapeDetailsItems >
147+ ) }
148+ </ ShapeCard >
149+ </ React . Fragment >
150+ ) ) }
151+ </ ShapeCards >
152+ </ ShapePallete >
153+ ) }
154+ </ >
145155 ) ;
146156} ;
147157
0 commit comments