@@ -19,8 +19,9 @@ const Shape = dynamic(import("react-clip-path"), { ssr: false });
1919import Switch from "react-switch" ;
2020
2121// icons
22- import { FiCopy , FiDownload , FiHeart , FiLock } from 'react-icons/fi' ;
22+ import { FiCopy , FiDownload , FiLock } from 'react-icons/fi' ;
2323import { BiExport } from "react-icons/bi" ;
24+ import { BsFillHeartFill , BsHeart } from "react-icons/bs" ;
2425
2526// Export Shape
2627import { ExportShape } from '..' ;
@@ -100,8 +101,17 @@ const ExportIcon = styled(BiExport)`
100101 }
101102` ;
102103
103- const LikeIcon = styled ( FiHeart ) `
104+ const LikeIcon = styled ( BsHeart ) `
104105 cursor: pointer;
106+ color: red;
107+ &:hover {
108+ color: #f71b6f;
109+ }
110+ ` ;
111+
112+ const LikeFilledIcon = styled ( BsFillHeartFill ) `
113+ cursor: pointer;
114+ color: red;
105115 &:hover {
106116 color: #f71b6f;
107117 }
@@ -127,6 +137,9 @@ const ShapeList = ({ setOpen, user, data }) => {
127137 setShapes ( ...[ modifiedShapes ] ) ;
128138 } ;
129139
140+ /**
141+ * Copy the clip-path value to clipboard
142+ */
130143 async function performCopy ( event , formula ) {
131144 event . preventDefault ( ) ;
132145 try {
@@ -138,20 +151,32 @@ const ShapeList = ({ setOpen, user, data }) => {
138151 }
139152 }
140153
154+ /**
155+ * Method to execute when user clicks on the export shape
156+ */
141157 const performExport = shape => {
158+ // Check if user logged-in
142159 if ( user . length === 0 ) {
160+ // Show the login modal if user is not authenticated
143161 setOpen ( true ) ;
144162 } else {
163+ // Set the shape details to export
145164 setShapeToExport ( shape ) ;
165+ // Show the export modal
146166 setShowExportModal ( true ) ;
147167 }
148168 }
149169
170+ /**
171+ * Method to execute when user clicks on the likes
172+ */
150173 const performLike = async ( event , shapeId ) => {
174+ // Check if user logged-in
151175 if ( user . length === 0 ) {
152- showOpen ( true ) ;
176+ // Show the login modal if user is not authenticated
177+ setOpen ( true ) ;
153178 } else {
154- // Initialize likes
179+ // Good to go. Initialize likes
155180 let likes = 0 ;
156181
157182 // Check if already an entry for this user's like
@@ -181,8 +206,6 @@ const ShapeList = ({ setOpen, user, data }) => {
181206 if ( insertLike ) {
182207 // Update the count by 1
183208 likes = returnValue [ 0 ] . likes + 1 ;
184-
185- // Update the like state
186209 }
187210 } else {
188211 // If present, delete to remove like
@@ -194,8 +217,6 @@ const ShapeList = ({ setOpen, user, data }) => {
194217 if ( deleteLike ) {
195218 // update the like count decrease by 1
196219 likes = returnValue [ 0 ] . likes - 1 ;
197-
198- // update the likes state
199220 }
200221 }
201222
@@ -206,7 +227,17 @@ const ShapeList = ({ setOpen, user, data }) => {
206227 } ) ;
207228
208229 // Update the shape data in the shapes array
209-
230+ let modifiedShapes = shapes . map ( ( shape , index ) => {
231+ if ( shape [ 'shape_id' ] === shapeId ) {
232+ return {
233+ ...shape ,
234+ liked : ! shape . liked ,
235+ likes : likes
236+ } ;
237+ }
238+ return shape ;
239+ } ) ;
240+ setShapes ( ...[ modifiedShapes ] ) ;
210241 }
211242 } ;
212243
@@ -227,9 +258,16 @@ const ShapeList = ({ setOpen, user, data }) => {
227258 { shape . private && < FiLock /> }
228259 < ShapeActions >
229260 < span title = "Like" >
230- < LikeIcon
231- size = { 24 }
232- onClick = { ( event , shapeId ) => performLike ( event , shape [ 'shape_id' ] ) } />
261+ {
262+ shape . liked ?
263+ ( < LikeFilledIcon
264+ size = { 24 }
265+ onClick = { ( event , shapeId ) => performLike ( event , shape [ 'shape_id' ] ) } /> )
266+ :
267+ ( < LikeIcon
268+ size = { 24 }
269+ onClick = { ( event , shapeId ) => performLike ( event , shape [ 'shape_id' ] ) } /> )
270+ }
233271 { shape . likes }
234272 </ span > { " " }
235273 < span title = "Export" >
0 commit comments