@@ -10,7 +10,7 @@ import { saveBookmarkToStore } from "@/redux/reducers/bookmarkReducer";
1010import { toastify } from "@/helper/toastify" ;
1111import { addComment } from "@/backend/posts.api" ;
1212import { getUserDetails } from "@/backend/auth.api" ;
13- import { useCallback , useEffect , useState } from "react" ;
13+ import { useCallback , useEffect , useState , MouseEvent } from "react" ;
1414import { UserBookMarkType , FormatOnType } from "@/types/index" ;
1515
1616import isCtrlEnter from "@/helper/isCtrlEnter" ;
@@ -148,6 +148,36 @@ export default function SinglePost({
148148 fetchUserDetails ( ) ;
149149 } , [ fetchUserDetails ] ) ;
150150
151+ const handleClick = ( e :MouseEvent < HTMLDivElement | HTMLSpanElement > ) => {
152+ const element = e . target as HTMLDivElement | HTMLSpanElement ;
153+ const spanElement = element . querySelector ( 'span' ) ;
154+ let currentSelectedElement :HTMLSpanElement | HTMLDivElement | null = null ;
155+ if ( spanElement ) {
156+ currentSelectedElement = spanElement ;
157+ } else {
158+ currentSelectedElement = element ;
159+ }
160+ if ( currentSelectedElement && currentSelectedElement . textContent ) {
161+ const prevValue = currentSelectedElement . textContent ;
162+ navigator . clipboard . writeText ( currentSelectedElement . textContent ) . then ( ( ) => {
163+ if ( currentSelectedElement ) {
164+ currentSelectedElement . textContent = 'Copied' ;
165+ currentSelectedElement . classList . remove ( 'bg-slate-950/[0.4]' ) ;
166+ currentSelectedElement . classList . add ( 'bg-black' ) ;
167+ setTimeout ( ( ) => {
168+ if ( currentSelectedElement ) {
169+ currentSelectedElement . textContent = prevValue ;
170+ currentSelectedElement . classList . remove ( 'bg-black' ) ;
171+ currentSelectedElement . classList . add ( 'bg-slate-950/[0.4]' ) ;
172+ }
173+ } , 1000 ) ;
174+ }
175+ } ) . catch ( console . log )
176+ }
177+
178+ }
179+ const colors = singlePost ?. colors && typeof singlePost ?. colors === 'string' && JSON . parse ( singlePost . colors )
180+
151181 return (
152182 < div
153183 className = { ` ${ width
@@ -189,9 +219,9 @@ export default function SinglePost({
189219 ) : null }
190220 </ Link >
191221
192- { singlePost ?. colors && singlePost ?. colors . length > 0 ? (
222+ { colors && Object . keys ( colors ) . length > 0 ? (
193223 < div className = "my-2 flex flex-row justify-between items-center w-full" >
194- { singlePost ? .colors . map ( ( color : string , index : number ) => {
224+ { /* {JSON.parse( singlePost.colors) .map((color: string, index: number) => {
195225 return (
196226 <div
197227 key={index}
@@ -202,7 +232,37 @@ export default function SinglePost({
202232 }}
203233 ></div>
204234 );
205- } ) }
235+ }) } */ }
236+ < div className = "w-full h-[200px] bg-tranparent mx-auto flex mb-3.5 gap-1" >
237+ < div
238+ className = "cursor-pointer w-full flex justify-center items-center group"
239+ style = { { backgroundColor :typeof colors . color01 === 'string' && colors . color01 || '' } }
240+ onClick = { handleClick }
241+ >
242+ < span className = "bg-slate-950/[0.4] text-xs px-0.5 opacity-0 transition ease-out duration-300 group-hover:opacity-100 group-hover:ease-in group-hover:scale-110" onClick = { handleClick } > { colors . color01 } </ span >
243+ </ div >
244+ < div
245+ className = "cursor-pointer w-full flex justify-center items-center group "
246+ style = { { backgroundColor :typeof colors . color02 === 'string' && colors . color02 || '' } }
247+ onClick = { handleClick }
248+ >
249+ < span className = "bg-slate-950/[0.4] text-xs px-0.5 opacity-0 transition ease-out duration-300 group-hover:opacity-100 group-hover:ease-in group-hover:scale-110" > { colors . color02 } </ span >
250+ </ div >
251+ < div
252+ className = "cursor-pointer w-full flex justify-center items-center group gap-2"
253+ style = { { backgroundColor :typeof colors . color03 === 'string' && colors . color03 || '' } }
254+ onClick = { handleClick }
255+ >
256+ < span className = "bg-slate-950/[0.4] text-xs px-0.5 opacity-0 transition ease-out duration-300 group-hover:opacity-100 group-hover:ease-in group-hover:scale-110" > { colors . color03 } </ span >
257+ </ div >
258+ < div
259+ className = "cursor-pointer w-full flex justify-center items-center group"
260+ style = { { backgroundColor :typeof colors . color04 === 'string' && colors . color04 || '' } }
261+ onClick = { handleClick }
262+ >
263+ < span className = "bg-slate-950/[0.4] text-xs px-0.5 opacity-0 transition ease-out duration-300 group-hover:opacity-100 group-hover:ease-in group-hover:scale-110" > { colors . color04 } </ span >
264+ </ div >
265+ </ div >
206266 </ div >
207267 ) : null }
208268
0 commit comments