@@ -2,55 +2,83 @@ import { useEffect, useState } from "react";
22import { useParams } from "react-router-dom" ;
33import SyntaxHighlighter from "react-syntax-highlighter" ;
44import { nightOwl } from "react-syntax-highlighter/dist/esm/styles/hljs" ;
5+ import { Link } from "react-router-dom" ;
56
67const Hack = ( ) => {
7- const { id } = useParams ( ) ;
8- const [ hacks , setHacks ] = useState ( { } ) ;
8+ const { id } = useParams ( ) ;
9+ const [ hacks , setHacks ] = useState ( { } ) ;
910
10- useEffect ( ( ) => {
11- fetch ( `https://nexus-api-note-co-78.deno.dev/codes/hackerank/${ id } ` )
12- . then ( async ( res ) => await res . json ( ) )
13- . then ( ( [ json ] ) => setHacks ( json ) ) ;
11+ useEffect ( ( ) => {
12+ fetch ( `https://nexus-api-note-co-78.deno.dev/codes/hackerank/${ id } ` )
13+ . then ( async ( res ) => await res . json ( ) )
14+ . then ( ( [ json ] ) => setHacks ( json ) ) ;
1415
15- // console.log(hacks);
16- } , [ ] ) ;
17-
18- return (
19- < div className = " bg-gradient-to-t from-teal-950 to-black min-h-screen gap-8 text-white py-10" >
20- < div >
21- < h1 className = "text-[50px] font-extrabold lg:text-[50px] text-center" >
22- { hacks . name }
23- </ h1 >
24- < p className = "font-normal text-white/70 text-center m-4" >
25- { hacks . original }
26- </ p >
27- < h1 className = "text-[15px] font-normal lg:text-[15px] text-center" >
28- { hacks . description }
29- </ h1 >
30- </ div >
31- < div className = "grid place-content-center m-2" >
32- < button
33- onClick = { ( ) => {
34- navigator . clipboard . writeText ( hacks . solution )
35- } }
36- className = " border-2 border-white py-2 hover:bg-white hover:text-black px-3 rounded-2xl w-full text-[15px]" >
37- Copy
38- </ button >
39- </ div >
40- < div className = "grid place-items-center grid-flow-row lg:grid-flow-col lg:px-20 h-full gap-3 lg:gap-7 text-center mt-5" >
41- < div className = "bg-green-900/20 border-4 border-emerald-300 h-full w-[calc(100%-80px)] overflow-auto lg:w-full content-center rounded-2xl text-[20px] lg:text-[30px] font-bold" >
42- < div className = "text-left text-[15px] border rounded-2xl " >
43- < SyntaxHighlighter
44- language = "cpp"
45- style = { nightOwl }
46- showLineNumbers
47- >
48- { hacks . solution }
49- </ SyntaxHighlighter >
50- </ div >
51- </ div >
52- </ div >
16+ // console.log(hacks);
17+ } , [ ] ) ;
18+ const eliminar = ( ) => {
19+ // console.log(dato);
20+ fetch ( `https://nexus-api-note-co-78.deno.dev/codes/hackerank/${ id } ` , {
21+ method : "DELETE" ,
22+ } )
23+ . then ( ( res ) => {
24+ if ( ! res . ok ) {
25+ console . log ( "Problem found" ) ;
26+ return ;
27+ }
28+ return res . json ( ) ;
29+ } )
30+ . then ( ( data ) => console . log ( data ) )
31+ . catch ( ( error ) => {
32+ console . log ( error ) ;
33+ } ) ;
34+ } ;
35+ return (
36+ < div className = " bg-gradient-to-t from-teal-950 to-black min-h-screen gap-8 text-white py-10" >
37+ < div >
38+ < h1 className = "text-[50px] font-extrabold lg:text-[50px] text-center" >
39+ { hacks . name }
40+ </ h1 >
41+ < p className = "font-normal text-white/70 text-center m-4" >
42+ { hacks . original }
43+ </ p >
44+ < h1 className = "text-[15px] font-normal lg:text-[15px] text-center" >
45+ { hacks . description }
46+ </ h1 >
47+ </ div >
48+ < div className = "flex place-content-center m-2 gap-2" >
49+ < button
50+ onClick = { ( ) => {
51+ navigator . clipboard . writeText ( hacks . solution ) ;
52+ } }
53+ className = " border-2 w-fit border-white py-2 hover:bg-white hover:text-black px-3 rounded-2xl text-[15px]"
54+ >
55+ Copy
56+ </ button >
57+ < Link
58+ to = { `/hackerank/` }
59+ onClick = { ( ) => {
60+ eliminar ( ) ;
61+ } }
62+ >
63+ < div className = "border-2 border-white py-2 hover:bg-white hover:text-black px-3 rounded-2xl w-fit text-[15px]" >
64+ Eliminar
65+ </ div >
66+ </ Link >
67+ </ div >
68+ < div className = "grid place-items-center grid-flow-row lg:grid-flow-col lg:px-20 h-full gap-3 lg:gap-7 text-center mt-5" >
69+ < div className = "bg-green-900/20 border-4 border-emerald-300 h-full w-[calc(100%-80px)] overflow-auto lg:w-full content-center rounded-2xl text-[20px] lg:text-[30px] font-bold" >
70+ < div className = "text-left text-[15px] border rounded-2xl " >
71+ < SyntaxHighlighter
72+ language = "cpp"
73+ style = { nightOwl }
74+ showLineNumbers
75+ >
76+ { hacks . solution }
77+ </ SyntaxHighlighter >
78+ </ div >
5379 </ div >
54- ) ;
80+ </ div >
81+ </ div >
82+ ) ;
5583} ;
5684export default Hack ;
0 commit comments