Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fetch data from API #101

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
17 changes: 10 additions & 7 deletions car-ui-react/src/components/Elements/ProductCard.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,28 +2,31 @@ import React from 'react';


export const ProductCard = ({product}) => {
const {carId, brand, model, year, color, mileage, price, quantity, tax, poster, in_stock} = product;
const {carId, brand, model, year, color, mileage, price, quantity, tax, in_stock} = product;

return (
<div className="m-3 max-w-sm bg-white rounded-lg border border-gray-200 shadow-md dark:bg-gray-800 dark:border-gray-700">
<a href="/" className="relative" >
{/* <span className="absolute top-4 left-2 px-2 bg-orange-500 bg-opacity-90 text-white rounded">Best Seller</span> */}
<img className="rounded-t-lg w-full h-64" src={poster} alt="" />
</a>
<div className="p-5">
<a href="/">
<h5 className="mb-2 text-2xl font-bold tracking-tight text-gray-900 dark:text-white">{brand} {model}</h5>
</a>
<p className="mb-3 font-normal text-gray-700 dark:text-gray-400">{color}</p>
<p className="mb-3 font-normal text-gray-700 dark:text-gray-400">Color : {color}</p>

<p className="mb-3 font-normal text-black dark:text-gray-400">
<span>mileage: </span><span>{mileage}</span>
<span>Year : </span><span>{year}</span>
</p>

<p className="mb-3 font-normal text-black dark:text-gray-400">
<span>Mileage : </span><span>{mileage}</span>
</p>
<p className="mb-3 font-normal text-black dark:text-gray-400">
<span>quantity: </span><span>{quantity}</span>
<span>Quantity : </span><span>{quantity}</span>
</p>
<p className="mb-3 font-normal text-black dark:text-gray-400">
<span>tax: </span><span>{tax}</span>
<span>Tax : </span><span>{tax}</span>
</p>

<div className="flex items-center my-2">
Expand All @@ -36,7 +39,7 @@ export const ProductCard = ({product}) => {

<p className="flex justify-between items-center">
<span className="text-2xl dark:text-gray-200">
<span>INR </span><span>{price}</span>
<span></span><span>{price}</span>
</span>
{/* <button className="inline-flex items-center py-2 px-3 text-sm font-medium text-center text-white bg-blue-700 rounded-lg hover:bg-blue-800"/> */}
<button className='inline-flex items-center py-2 px-3 text-sm font-medium text-center text-white bg-blue-700 rounded-lg hover:bg-blue-800'>Add To Cart +</button>
Expand Down
4 changes: 2 additions & 2 deletions car-ui-react/src/pages/Products/ProductsList.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ export const ProductsList = () => {

useEffect(() => {
async function fetchProducts() {
const response = await fetch("http://localhost:8000/products");
const response = await fetch("https://my.api.mockaroo.com/model_random.json?key=dcbc8750");
const data = await response.json()
setProducts(data);
}
Expand All @@ -25,7 +25,7 @@ export const ProductsList = () => {
</Link>
<div className="my-5 flex justify-between">
<span className="text-2xl font-semibold dark:text-slate-100 mb-5">
All Cars (10)
All Cars ({products.length})
</span>
<span>
<button
Expand Down
6 changes: 6 additions & 0 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.