@@ -7,7 +7,7 @@ import Card from '@/components/Card';
77import Filter from '@/components/Filter' ;
88import NewPost from '@/components/NewPost' ;
99
10- import client , { myClient } from "@/config/client" ;
10+ import client from "@/config/client" ;
1111import ModalComments from '@/components/Modal/ModalComments' ;
1212import { useSearchParams , useRouter } from 'next/navigation'
1313import CardReview from '@/components/Cards/CardReview' ;
@@ -26,10 +26,14 @@ async function loadPost() {
2626
2727export default function Home ( ) {
2828 const searchParams = useSearchParams ( )
29+ const [ categorias , setCategorias ] = useState ( [ ] ) ;
30+ const [ numComments , setNumComments ] = useState ( "" ) ;
2931 const idSearch = searchParams . get ( 'id' )
3032 const router = useRouter ( )
3133 const [ chazas , setChazas ] = useState ( [ ] )
34+ const [ names , setName ] = useState ( [ ] )
3235 const [ posts , setPosts ] = useState ( [ ] )
36+ const [ isOpen , setIsOpen ] = useState ( false )
3337 useEffect ( ( ) => {
3438
3539 client . get ( `chazas` , { next : { revalidate : true | 0 | 60 } } )
@@ -49,106 +53,56 @@ export default function Home() {
4953 setPosts ( res . data . data . data )
5054 //if (!posts) return "An error has occurred.";
5155 } )
52- } , [ ] )
5356
54- //const post = await loadPost()
55- var comments = [
56- {
57- "id" : 1 ,
58- "review" : "¡Este es un comentario genial!" ,
59- "urlImagen" : "https://www.example.com/imagen1.jpg"
60- } ,
61- {
62- "id" : 2 ,
63- "review" : "Este es otro comentario genial" ,
64- "urlImagen" : "https://www.example.com/imagen2.jpg"
65- } ,
66- {
67- "id" : 3 ,
68- "review" : "¡Esta imagen es increíble!" ,
69- "urlImagen" : "https://www.example.com/imagen3.jpg"
70- } ,
71- {
72- "id" : 4 ,
73- "review" : "¡Este es un comentario muy profundo!" ,
74- "urlImagen" : "https://www.example.com/imagen4.jpg"
75- } ,
76- {
77- "id" : 5 ,
78- "review" : "¡Esta imagen me hace reír!" ,
79- "urlImagen" : "https://www.example.com/imagen5.jpg"
80- } ,
81- {
82- "id" : 6 ,
83- "review" : "¡Esta imagen es muy triste!" ,
84- "urlImagen" : "https://www.example.com/imagen6.jpg"
85- } ,
86- {
87- "id" : 7 ,
88- "review" : "¡Esta imagen es muy hermosa!" ,
89- "urlImagen" : "https://www.example.com/imagen7.jpg"
90- } ,
91- {
92- "id" : 8 ,
93- "review" : "¡Esta imagen es muy graciosa!" ,
94- "urlImagen" : "https://www.example.com/imagen8.jpg"
95- } ,
96- {
97- "id" : 9 ,
98- "review" : "¡Esta imagen es muy inspiradora!" ,
99- "urlImagen" : "https://www.example.com/imagen9.jpg"
100- } ,
101- {
102- "id" : 10 ,
103- "review" : "¡Esta imagen es muy creativa!" ,
104- "urlImagen" : "https://www.example.com/imagen10.jpg"
105- }
106- ]
57+ client . get ( `chazas/every` , { next : { revalidate : true | 0 | 60 } } )
58+ . then ( ( res ) => {
59+ //console.log(res)
60+ if ( ! res . status == "200" ) {
61+ throw new Error ( 'Failed to fetch data' )
62+ }
63+ var data = res . data . data . data
64+ if ( data . length > 0 ) {
65+ //console.log(data)
66+ setName ( data )
67+ } else {
68+ console . log ( "No hay data" )
69+ }
70+ } )
71+ } , [ ] )
10772 return (
10873 < div id = 'home' className = 'grid grid-cols-2' >
109- { idSearch && ( < ModalComments onClose = { ( ) => { router . push ( "/" ) } } _id = { idSearch } /> )
74+ { idSearch && ( < ModalComments numComments = { numComments } setNumComments = { setNumComments } onClose = { ( ) => { router . push ( `/# ${ idSearch } ` ) } } _id = { idSearch } /> )
11075
11176 }
112- < Filter className = { "formSearch justify-items-center px-3 flex mx-auto text-center" } > </ Filter >
113- < div className = 'formSearch justify-items-center px-3' >
114- < form >
115- < label htmlFor = "default-search" className = "mb-2 text-sm font-medium text-gray-900 sr-only dark:text-white" > Buscar</ label >
116- < div className = "relative" >
117- < div className = "absolute inset-y-0 left-0 flex items-center pl-3 pointer-events-none" >
118- < svg className = "w-4 h-4 text-gray-500 dark:text-gray-400" aria-hidden = "true" xmlns = "http://www.w3.org/2000/svg" fill = "none" viewBox = "0 0 20 20" >
119- < path stroke = "currentColor" strokeLinecap = "round" strokeLinejoin = "round" strokeWidth = "2" d = "m19 19-4-4m0-7A7 7 0 1 1 1 8a7 7 0 0 1 14 0Z" />
120- </ svg >
121- </ div >
122- < input type = "search" id = "default-search" className = "block w-full p-4 pl-10 text-sm text-gray-900 border border-gray-300 rounded-lg bg-gray-50 focus:ring-blue-500 focus:border-blue-500 dark:bg-gray-700 dark:border-gray-600 dark:placeholder-gray-400 dark:text-white dark:focus:ring-blue-500 dark:focus:border-blue-500" placeholder = "Search Mockups, Logos..." required />
123- < button type = "submit" className = "text-white absolute right-2.5 bottom-2.5 bg-blue-700 hover:bg-blue-800 focus:ring-4 focus:outline-none focus:ring-blue-300 font-medium rounded-lg text-sm px-4 py-2 dark:bg-blue-600 dark:hover:bg-blue-700 dark:focus:ring-blue-800" > Buscar</ button >
124- </ div >
125- </ form >
126-
127- </ div >
128- < div className = 'newpost col-span-2 flex justify-end px-3' >
129- < NewPost > </ NewPost >
77+ < Filter posts = { posts } setPosts = { setPosts } categorias = { categorias } setCategorias = { setCategorias } />
78+ < div className = 'newpost col-span-2 flex justify-end px-3 min-[650px]:grid-cols-1' >
79+ < div className = "inline-flex rounded-md shadow-sm" role = "group" >
80+ < button onClick = { ( ) => router . refresh ( ) } type = "button" className = "text-white px-4 py-2 text-sm font-medium text-gray-900 bg-transparent border border-gray-900 rounded-l-lg hover:bg-gray-900 hover:text-white focus:z-10 focus:ring-2 focus:ring-gray-500 focus:bg-gray-900 focus:text-white dark:border-white dark:text-white dark:hover:text-white dark:hover:bg-gray-700 dark:focus:bg-gray-700" >
81+ Actualizar Publicaciones
82+ </ button >
83+ < button
84+ type = "button"
85+ onClick = { ( ) => setIsOpen ( true ) }
86+ className = "text-white px-4 py-2 text-sm font-medium text-gray-900 bg-transparent border border-gray-900 rounded-r-md hover:bg-gray-900 hover:text-white focus:z-10 focus:ring-2 focus:ring-gray-500 focus:bg-gray-900 focus:text-white dark:border-white dark:text-white dark:hover:text-white dark:hover:bg-gray-700 dark:focus:bg-gray-700"
87+ >
88+ Crear publicacíon
89+ </ button >
90+ </ div >
91+ < NewPost open = { isOpen } onClose = { ( ) => { router . push ( "/" ) ; setIsOpen ( false ) } } > </ NewPost >
13092 </ div >
131- < div className = "col-span-2 pt-3 CardProfile justify-items-center grid min-[1000px]:grid-cols-2 min-[1300px]:grid-cols-3 min-[1300px]:px-3" >
93+ { /* col-span-2 pt-3 CardProfile justify-items-center grid min-[1000px]:grid-cols-2 min-[1300px]:grid-cols-3 min-[1300px]:px-3 */ }
94+ < div className = "col-span-2 justify-items-center grid grid-cols-1 md:grid-cols-2 lg:grid-cols-3 xl:grid-cols-3" >
13295 { posts ?
13396 posts . map ( ( card ) => (
13497 < >
135- < CardReview key = { "pub" + card . _id } card = { card } idModal = { card . _id } comments = { card . reviews } className = { "ListComment pb-2" } />
136- </ >
137- )
138- )
139-
140- : null }
141- { chazas ?
142- chazas . map ( ( chaz ) => (
143- < >
144- < Card key = { "cha" + chaz . _id } card = { chaz } idModal = { chaz . _id } comments = { comments } className = { "ListComment pb-2" } > </ Card >
98+ < CardReview numComments = { numComments } setNumComments = { setNumComments } names = { names } key = { card . _id } card = { card } idModal = { card . _id } comments = { card . reviews } className = { "ListComment pb-2 md:mx-2 " } />
14599 </ >
146100 )
147101 )
148102
149103 : null }
150104 </ div >
151- < a href = "/unbiters/pricing" className = "btn-flotante text-white right-2.5 bg-blue-700 hover:bg-blue-800 focus:ring-4 focus:outline-none focus:ring-blue-300 font-medium rounded-lg text-sm px-4 py-2 dark:bg-blue-600 dark:hover:bg-blue-700 dark:focus:ring-blue-800" >
105+ < a href = "/unbiters/pricing" className = "invisible md:visible btn-flotante text-white right-2.5 bg-blue-700 hover:bg-blue-800 focus:ring-4 focus:outline-none focus:ring-blue-300 font-medium rounded-lg text-sm px-4 py-2 dark:bg-blue-600 dark:hover:bg-blue-700 dark:focus:ring-blue-800" >
152106 Explora Premium
153107 </ a >
154108
0 commit comments