Skip to content

Commit

Permalink
update branch
Browse files Browse the repository at this point in the history
  • Loading branch information
danielcgilibert committed Nov 26, 2023
1 parent 512e0d9 commit cb17288
Show file tree
Hide file tree
Showing 8 changed files with 752 additions and 4 deletions.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
import { type NextRequest } from 'next/server'
import { products } from '@/data/products.json'

export function POST(request: NextRequest) {
const searchParams = request.nextUrl.searchParams
const query = searchParams.get('search')

console.log(query)

if (!query) {
return Response.json(products)
}

// search in products array
const product = products.filter((product) =>
product.title.toLocaleLowerCase().includes(query.toLocaleLowerCase())
)

// mapping products
// const product = products.map((product) => {
// return {
// id: product.id,
// title: product.title,
// price: product.price,
// picture: product.picture,

return Response.json({ products: product })
}
93 changes: 93 additions & 0 deletions pruebas/02-bazar-universal/danielcgilibert/src/app/items/page.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,93 @@
/* eslint-disable @next/next/no-img-element */
'use client'
import { Products } from '@/types/types'
import { DollarSign, Euro, Star } from 'lucide-react'
import { useSearchParams } from 'next/navigation'
import { useEffect, useState } from 'react'

export default function Page() {
const [items, setItems] = useState<Products['products']>([])

const searchParams = useSearchParams()
const search = searchParams.get('search')

const getItems = async () => {
const res = await fetch(`/api/items?search=${search}`, {
method: 'POST',
headers: {
'Content-Type': 'application/json',
},
})
return await res.json()
}

useEffect(() => {
getItems().then((data) => setItems(data.products))
}, [])

return (
<div className='flex flex-col gap-4 max-w-4xl mx-auto pb-12 p-8 sm:p-0 '>
<h1 className='text-4xl'>Search</h1>

<div className='flex flex-col gap-4 '>
{
<>
{items.map((item) => (
<div
className='grid sm:grid-cols-[350px_auto] grid-rows-[350px] rounded-lg shadow hover:shadow-md transition-all border border-neutral-100'
key={item.id}>
<div className='border-r border-neutral-100 p-3'>
<img
src={item.thumbnail}
className='h-full w-full object-cover rounded-lg '
alt={`thumbnail of ${item.title}`}
/>
</div>

<div className='flex gap-12 flex-col justify-between py-8 px-5 '>
<main className='flex flex-col gap-8'>
<div className='flex gap-2 flex-col h-full '>
<div className='flex justify-between gap-8'>
<h2 className='text-2xl sm:text-2xl first-letter:uppercase '>
{item.title}
</h2>
<span className=' text-xl flex gap-1 items-center '>
<Euro size={22} strokeWidth={2.2} /> {item.price}
</span>
</div>

<span className='flex gap-1 '>
{[...new Array(5)].map((arr, index) => {
console.log(index, item.rating)

return index < Math.round(item.rating) ? (
<Star fill='black' size={18} />
) : (
<Star fill='white' size={18} />
)
})}
</span>
</div>

<p className='text-black/70 leading-relaxed '>
{item.description}
</p>
</main>

<footer className='flex gap-4 justify-between items-center h-full '>
<button className=' border border-neutral-300 py-2 px-5 rounded-lg uppercase '>
add to cart
</button>
<button className=' border border-neutral-300 py-2 px-5 rounded-lg uppercase '>
See more
</button>
</footer>
</div>
</div>
))}
</>
}
</div>
</div>
)
}
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,10 @@ export default function RootLayout({
}) {
return (
<html lang='en'>
<body className={inter.className}>{children}</body>
<body
className={`${inter.className} sm:max-w-4xl sm:m-auto flex flex-col sm:gap-9 py-8`}>
{children}
</body>
</html>
)
}
25 changes: 22 additions & 3 deletions pruebas/02-bazar-universal/danielcgilibert/src/app/page.tsx
Original file line number Diff line number Diff line change
@@ -1,9 +1,28 @@
'use client'
/* eslint-disable jsx-a11y/alt-text */
import { Button } from '@/components/ui/button'
import { Input } from '@/components/ui/input'
import { FormEvent } from 'react'
import { useRouter } from 'next/navigation'

export default function Home() {
const r = useRouter()

const handleSubmit = (e: FormEvent) => {
e.preventDefault()
r.push(`/items/?search=${(e.target as any).elements[0].value}`)
}
return (
<div>
<Button>Click me</Button>
</div>
<>
<header className='flex flex-col'>
<h1 className='text-6xl text-center'>Bazar online</h1>
<img src='/truck.svg' className=' max-h-[200px]' />
</header>

<form onSubmit={handleSubmit} className='flex flex-col gap-4'>
<Input type='text' placeholder='Buscar' />
<Button>Buscar</Button>
</form>
</>
)
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
import * as React from "react"

import { cn } from "@/lib/utils"

export interface InputProps
extends React.InputHTMLAttributes<HTMLInputElement> {}

const Input = React.forwardRef<HTMLInputElement, InputProps>(
({ className, type, ...props }, ref) => {
return (
<input
type={type}
className={cn(
"flex h-10 w-full rounded-md border border-input bg-background px-3 py-2 text-sm ring-offset-background file:border-0 file:bg-transparent file:text-sm file:font-medium placeholder:text-muted-foreground focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-ring focus-visible:ring-offset-2 disabled:cursor-not-allowed disabled:opacity-50",
className
)}
ref={ref}
{...props}
/>
)
}
)
Input.displayName = "Input"

export { Input }
Loading

0 comments on commit cb17288

Please sign in to comment.