Skip to content

Commit

Permalink
added total shopping cost & quantity functionality
Browse files Browse the repository at this point in the history
  • Loading branch information
juliamuiruri4 committed Jul 18, 2023
1 parent a0f6da8 commit e9afa68
Show file tree
Hide file tree
Showing 13 changed files with 219 additions and 216 deletions.
33 changes: 14 additions & 19 deletions full/smart-shopping-planner-app/Solution/package-lock.json

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

1 change: 1 addition & 0 deletions full/smart-shopping-planner-app/Solution/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@
"graphql": "^16.6.0",
"react": "^18.2.0",
"react-dom": "^18.2.0",
"react-loading-icons": "^1.1.0",
"react-scripts": "5.0.1",
"web-vitals": "^2.1.4"
},
Expand Down
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
42 changes: 21 additions & 21 deletions full/smart-shopping-planner-app/Solution/public/index.html
Original file line number Diff line number Diff line change
@@ -1,21 +1,19 @@
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="utf-8" />
<link rel="icon" href="%PUBLIC_URL%/favicon.ico" />
<meta name="viewport" content="width=device-width, initial-scale=1" />
<meta name="theme-color" content="#000000" />
<meta
name="description"
content="Web site created using create-react-app"
/>
<link rel="apple-touch-icon" href="%PUBLIC_URL%/logo192.png" />
<!--

<head>
<meta charset="utf-8" />
<link rel="icon" href="%PUBLIC_URL%/favicon.ico" />
<meta name="viewport" content="width=device-width, initial-scale=1" />
<meta name="theme-color" content="#000000" />
<meta name="description" content="Web site created using create-react-app" />
<link rel="apple-touch-icon" href="%PUBLIC_URL%/logo192.png" />
<!--
manifest.json provides metadata used when your web app is installed on a
user's mobile device or desktop. See https://developers.google.com/web/fundamentals/web-app-manifest/
-->
<link rel="manifest" href="%PUBLIC_URL%/manifest.json" />
<!--
<link rel="manifest" href="%PUBLIC_URL%/manifest.json" />
<!--
Notice the use of %PUBLIC_URL% in the tags above.
It will be replaced with the URL of the `public` folder during the build.
Only files inside the `public` folder can be referenced from the HTML.
Expand All @@ -24,12 +22,13 @@
work correctly both with client-side routing and a non-root public URL.
Learn how to configure a non-root public URL by running `npm run build`.
-->
<title>React App</title>
</head>
<body>
<noscript>You need to enable JavaScript to run this app.</noscript>
<div id="root"></div>
<!--
<title>Smart Shopping</title>
</head>

<body>
<noscript>You need to enable JavaScript to run this app.</noscript>
<div id="root"></div>
<!--
This HTML file is a template.
If you open it directly in the browser, you will see an empty page.
Expand All @@ -39,5 +38,6 @@
To begin the development, run `npm start` or `yarn start`.
To create a production bundle, use `npm run build` or `yarn build`.
-->
</body>
</html>
</body>

</html>
49 changes: 31 additions & 18 deletions full/smart-shopping-planner-app/Solution/src/App.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,32 +2,45 @@ import './App.css';
import CreateItem from './components/CreateItem';
import ItemList from './components/ItemList';
import PriceTag from './components/PriceTag';
import { ApolloClient, InMemoryCache, ApolloProvider } from '@apollo/client';
import { Container, Grid, Box } from '@mui/material';
import Typography from '@mui/joy/Typography';
import React, { useState } from 'react';
import { totalItems, totalCost } from './utils/Utils'
import Loading from './components/Loading';

// Apollo Client setup for GraphQL API calls to the backend server
const client = new ApolloClient({
uri: '/data-api/graphql',
cache: new InMemoryCache({
addTypename: false
})
});

function App() {
const [items, setItems] = useState([]);
const [loading, setLoading] = useState(false);

const fetchData = async () => {
setLoading(true)
try {
const response = await fetch('/data-api/api/Item');
if (!response.ok) {
throw new Error(response.statusText);
}
const data = await response.json();
setItems(data.value);
setLoading(false);
} catch (error) {
console.log(error);
setLoading(false);
}
};

return (
<ApolloProvider client={client}>
<Container maxWidth="lg" sx={{ padding:5 }}>
<Container maxWidth="lg" sx={{ padding: 5 }}>
{loading && <Loading />}
<Typography level="h1" color="info" variant='outlined'>Smart Shopping Planner</Typography>
<Grid item xs={12} md={6} sx={{ display: 'grid', gridTemplateColumns: '1fr 2fr 1fr', gap: '20px', paddingTop: '20px' }}>
{ <CreateItem />}
{ <ItemList />}
<Box>
{ <PriceTag />}
</Box>
</Grid>
<Grid item xs={12} md={6} sx={{ display: 'grid', gridTemplateColumns: '1fr 2fr 1fr', gap: '20px', paddingTop: '20px' }}>
{<CreateItem fetchData={fetchData} />}
{<ItemList fetchData={fetchData} items={items} />}
<Box>
{<PriceTag itemsNo={totalItems(items)} totalCost={totalCost(items)} />}
</Box>
</Grid>
</Container>
</ApolloProvider>
);
}

Expand Down
8 changes: 0 additions & 8 deletions full/smart-shopping-planner-app/Solution/src/App.test.js

This file was deleted.

Loading

0 comments on commit e9afa68

Please sign in to comment.