-
Notifications
You must be signed in to change notification settings - Fork 0
GPT-32: Amplify dashboard #17
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
Changes from 4 commits
d7d7322
069bb7b
0c6d332
dbac852
af4e02f
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,72 +1,62 @@ | ||
| import React from "react" | ||
| import React, { useState, useEffect } from "react" | ||
| import ItemCard from "../components/ItemCard"; | ||
| import { generateClient } from 'aws-amplify/data'; | ||
| import type { Schema } from '../../amplify/data/resource'; | ||
| import type { ItemInputs } from "../types/item"; | ||
|
|
||
| const client = generateClient<Schema>(); | ||
|
|
||
| const Dashboard: React.FC = () => { | ||
| const mockItems = [ | ||
| { | ||
| itemImageUrl: "https://static.nike.com/a/images/c_limit,w_592,f_auto/t_product_v1/02d73bf0-bd26-47db-8e10-7bf55eaeef3e/NIKE+AVA+ROVER.png", | ||
| itemName: "Nike Ava Rover", | ||
| barcode: "1234567890123", | ||
| description: "description abjaskfdjksadfklaf.", | ||
| category: "Shoes", | ||
| storeName: "Store1", | ||
| isDiscount: true, | ||
| itemPrice: 120.0, | ||
| discountedPrice: 90.0, | ||
| }, | ||
| { | ||
| itemImageUrl: "https://static.nike.com/a/images/c_limit,w_592,f_auto/t_product_v1/057c2bbd-d065-44eb-913f-51dd4f98d680/AIR+FORCE+1+%2707.png", | ||
| itemName: "Nike Air Force 1", | ||
| barcode: "9876543210987", | ||
| description: "description 2", | ||
| category: "Shoes", | ||
| storeName: "Store 1", | ||
| isDiscount: false, | ||
| itemPrice: 180.0, | ||
| }, | ||
| { | ||
| itemImageUrl: "https://static.nike.com/a/images/c_limit,w_592,f_auto/t_product_v1/48675f08-6956-46ce-a6e4-7f44b602b4b4/NIKE+DUNK+LOW+RETRO.png", | ||
| itemName: "Nike Dunk Low Retro", | ||
| barcode: "5555555555555", | ||
| description: "description of a shoe jhskdfhaksdhfkdsafasdfsadf.", | ||
| category: "Shoes", | ||
| storeName: "Store 2", | ||
| isDiscount: true, | ||
| itemPrice: 20.0, | ||
| discountedPrice: 15.0, | ||
| }, | ||
| { | ||
| itemImageUrl: "https://static.nike.com/a/images/c_limit,w_592,f_auto/t_product_v1/9303732b-0301-4904-adc1-04e1e9ade540/NIKE+STRUCTURE+26.png", | ||
| itemName: "This is a long item name for testing", | ||
| barcode: "5555555555555", | ||
| description: "description of a shoe, this is a long description for testing 123abcdefghi.", | ||
| category: "Shoes", | ||
| storeName: "Store 1", | ||
| isDiscount: true, | ||
| itemPrice: 30.0, | ||
| discountedPrice: 15.0, | ||
| }, | ||
| { | ||
| itemImageUrl: "https://static.nike.com/a/images/c_limit,w_592,f_auto/t_product_v1/9303732b-0301-4904-adc1-04e1e9ade540/NIKE+STRUCTURE+26.png", | ||
| itemName: "This is a 5th duplicate item to test grids", | ||
| barcode: "5555555555555", | ||
| description: "description of a shoe, this is a long description for testing 123abcdefghi.", | ||
| category: "Shoes", | ||
| storeName: "Store 1", | ||
| isDiscount: true, | ||
| itemPrice: 30.0, | ||
| discountedPrice: 15.0, | ||
| }, | ||
| ]; | ||
| const [dashboardItems, setDashboardItems] = useState<ItemInputs[]>([]); | ||
| const [loading, setLoading] = useState(true); | ||
|
|
||
| console.log(client.models); | ||
|
||
|
|
||
| const fetchItems = async () => { | ||
| try { | ||
| setLoading(true); | ||
| const { data: items } = await client.models.Item.list(); | ||
| if (items && items.length > 0) { | ||
| setDashboardItems(items as ItemInputs[]); | ||
| } else { | ||
| setDashboardItems([]); | ||
| console.log("Issue: No items available"); | ||
| } | ||
| } catch (error) { | ||
| console.error('Error fetching stores:', error); | ||
| setDashboardItems([]); | ||
| } finally { | ||
| setLoading(false); | ||
| } | ||
| }; | ||
|
|
||
| useEffect(() => { | ||
| fetchItems(); | ||
| }, []); | ||
|
|
||
| if (loading) return <p>Loading items...</p>; | ||
|
|
||
| return ( | ||
| <main className="main"> | ||
| <section className="page-container"> | ||
| <h1 className="page-title">Dashboard</h1> | ||
| <div className="items-grid"> | ||
| {mockItems.map((item) => ( | ||
| <ItemCard key={item.barcode} item={item}/> | ||
| ))} | ||
| {dashboardItems.length === 0 ? ( | ||
| <p>No items found.</p> | ||
| ) : ( | ||
| dashboardItems.map((item) => ( | ||
|
Owner
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. You might need to double check the ItemCard component. But we might not want to pass all of the fields in, we just want to render some of it per what is described in the user story. You could extract the necessary fields needed from dashboardItems, and pass each desired field as a prop into ItemCard. |
||
| <ItemCard key={item.barcode} | ||
| itemImageUrl={item.itemImageUrl} | ||
| itemName={item.itemName} | ||
| barcode={item.barcode} | ||
| description={item.description} | ||
| category={item.category} | ||
| storeName={item.storeName} | ||
| isDiscount={item.isDiscount} | ||
| itemPrice={item.itemPrice} | ||
| discountedPrice={item.discountedPrice} /> | ||
| )) | ||
| )} | ||
| </div> | ||
| </section> | ||
| </main> | ||
|
|
||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Looking at the code now.
Maybe easier to make storeName it's own line