Skip to content
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: 17 additions & 0 deletions client/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 client/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@
"dependencies": {
"react": "^19.2.0",
"react-dom": "^19.2.0",
"react-hook-form": "^7.68.0",
"react-router-dom": "^7.10.1"
},
"devDependencies": {
Expand Down
103 changes: 83 additions & 20 deletions client/src/App.css
Original file line number Diff line number Diff line change
@@ -1,31 +1,94 @@
/* client/src/App.css */

/* ✅ stop accidental horizontal scroll */
html, body, #root {
height: 100%;
width: 100%;
overflow-x: hidden;
}

* { box-sizing: border-box; }
img { max-width: 100%; display: block; }

/* ---------------------------
Theme tokens (Light + Dark)
---------------------------- */

:root {
--primary-action-color: #4A7A7B;
--background-color: #F5F5DC;
--secondary-background-color: #8E6161;
--text-icons-color: #34231b;
--accents-alerts-color: #B30000;
--radius: 18px;
--shadow: 0 18px 45px rgba(0, 0, 0, 0.28);
--shadow-soft: 0 10px 28px rgba(0, 0, 0, 0.20);

--primary: #7c5cff;
--primary2: #29d6c8;
--danger: #ff4d6d;
}

#root {
min-height: 100vh;
width: 100%;
margin: 0 auto;
max-width: 1280px;
}
/* Light = warm + clean */
:root[data-theme="light"] {
--bg: #f7f4ea;
--bg2: #f1ecdd;

--surface: rgba(255, 255, 255, 0.86);
--surface2: rgba(255, 255, 255, 0.72);

--border: rgba(17, 24, 39, 0.12);

--text: rgba(17, 24, 39, 0.92);
--muted: rgba(17, 24, 39, 0.62);

--inputBg: rgba(255, 255, 255, 0.95);
--inputBorder: rgba(17, 24, 39, 0.14);

--pillBg: rgba(124, 92, 255, 0.10);
--pillBorder: rgba(124, 92, 255, 0.18);
}

/* Dark = calm + premium */
:root[data-theme="dark"] {
--bg: #0b1020;
--bg2: #0f1730;

--surface: rgba(255, 255, 255, 0.06);
--surface2: rgba(255, 255, 255, 0.09);

--border: rgba(255, 255, 255, 0.12);

--text: rgba(255, 255, 255, 0.92);
--muted: rgba(255, 255, 255, 0.68);

--inputBg: rgba(0, 0, 0, 0.22);
--inputBorder: rgba(255, 255, 255, 0.16);

--pillBg: rgba(124, 92, 255, 0.16);
--pillBorder: rgba(124, 92, 255, 0.24);
}

body {
display: flex;
min-width: 320px;
min-height: 100vh;
margin: 0;
padding: 0;
background: var(--background-color);
justify-content: center;
color: var(--text);
font-family: system-ui, -apple-system, Segoe UI, Roboto, Arial, sans-serif;

/* ✅ calm gradient background for both themes */
background:
radial-gradient(900px 500px at 10% -10%, rgba(124, 92, 255, 0.22), transparent 60%),
radial-gradient(900px 500px at 90% 10%, rgba(41, 214, 200, 0.18), transparent 55%),
linear-gradient(180deg, var(--bg), var(--bg2));
}

.app-container {
.app-shell {
min-height: 100vh;
width: 100%;
display: flex;
flex-direction: column;
}
}

.app-main {
flex: 1;
display: flex;
justify-content: center;
}

.app-inner {
width: min(1100px, 100%);
padding: 26px 16px 40px;
}
144 changes: 123 additions & 21 deletions client/src/App.tsx
Original file line number Diff line number Diff line change
@@ -1,27 +1,129 @@
import React, { useCallback, useEffect, useMemo, useState } from 'react';
import './App.css';

import Header from './components/header/Header'
import CreatePantryItemContainer from './components/create-container/CreatePantryItemContainer'
import Footer from './components/footer/Footer'
import PantryItemContainer from './components/pantry/PantryItemContainer'
import Header from './components/header/Header';
import Footer from './components/footer/Footer';

import PantryItemContainer from './components/pantry/PantryItemContainer';
import type { PantryItemType } from './components/pantry/PantryItem';
import CreatePantryItemContainer from './components/create-container/CreatePantryItemContainer';
import type { FormFields } from './components/create-container/CreatePantryItemForm';

import './App.css'

function App() {

const API_BASE = 'http://localhost:3000'

const App = () => {
const [items, setItems] = useState<PantryItemType[]>([]);
const [loading, setLoading] = useState<boolean>(true);
const [error, setError] = useState<string>('');
const [busyName, setBusyName] = useState<string>(''); // disables update/delete per-card

const fetchItems = useCallback(async () => {
setLoading(true);
setError('');
try {
const res = await fetch(API_BASE);
if (!res.ok) throw new Error(`Fetch failed: ${res.status}`);
const data = await res.json();
if (!Array.isArray(data)) throw new Error('Unexpected inventory response format');
setItems(data);
} catch (e) {
console.error(e);
setError('Could not load pantry items. Make sure the backend is running.');
} finally {
setLoading(false);
}
}, []);

useEffect(() => {
void fetchItems();
}, [fetchItems]);

const onCreated = useCallback((newItem: FormFields) => {
// put newest on top
setItems((prev) => [newItem as PantryItemType, ...prev]);
}, []);

const onDelete = useCallback(async (name: string) => {
const ok = window.confirm(`Delete "${name}" from your pantry?`);
if (!ok) return;

setBusyName(name);
setError('');
try {
const res = await fetch(`${API_BASE}/${encodeURIComponent(name)}`, { method: 'DELETE' });
if (!res.ok) throw new Error(`Delete failed: ${res.status}`);

setItems((prev) => prev.filter((x) => x.name !== name));
} catch (e) {
console.error(e);
setError('Delete failed. Check server route + item name.');
} finally {
setBusyName('');
}
}, []);

const onUpdate = useCallback(async (name: string) => {

const raw = window.prompt(`New quantity for "${name}"?`);
if (raw === null) return;

const nextQty = Number(raw);
if (!Number.isFinite(nextQty) || nextQty < 1) {
window.alert('Quantity must be a number >= 1');
return;
}

setBusyName(name);
setError('');
try {
const res = await fetch(`${API_BASE}/${encodeURIComponent(name)}`, {
method: 'PATCH',
headers: { 'Content-Type': 'application/json' },
body: JSON.stringify({ quantity: nextQty }),
});

if (!res.ok) throw new Error(`Update failed: ${res.status}`);

const updated = await res.json();

setItems((prev) => prev.map((x) => (x.name === name ? updated : x)));
} catch (e) {
console.error(e);
setError('Update failed. Check server route + request body.');
} finally {
setBusyName('');
}
}, []);

const containerProps = useMemo(
() => ({
items,
loading,
error,
onUpdate: (name: string) => onUpdate(name),
onDelete: (name: string) => onDelete(name),
}),
[items, loading, error, onUpdate, onDelete]
);

return (
<>
<div className="app-container">
< Header />
< CreatePantryItemContainer />
< PantryItemContainer />
< Footer />

</div>

</>
)
}

export default App
<div className="app-shell">
<Header />

<main className="app-main">
<div className="app-inner">
<CreatePantryItemContainer onCreated={onCreated} />

<PantryItemContainer
{...containerProps}
/>
</div>
</main>

<Footer />
</div>
);
};

export default App;
Original file line number Diff line number Diff line change
@@ -1,14 +1,43 @@
import React from 'react';
import './createContainer.css';
import CreatePantryItemForm from './CreatePantryItemForm';
import CreatePantryItemForm, {FormFields } from './CreatePantryItemForm';

const CreatePantryItemContainer = () => {
type Props = {
onCreated: (newItem: FormFields) => void;
};

const CreatePantryItemContainer = ({ onCreated }: Props) => {
return (
<>
<div className='create-container'>
<CreatePantryItemForm />
<section className="create-container">
<div className="create-card">
<div className="create-head">
<h2 className="create-title">Add pantry item</h2>
<p className="create-subtitle">Fast input. Clean tracking</p>
</div>
<CreatePantryItemForm onCreated={onCreated} />
</div>
</>
</section>
);
};

export default CreatePantryItemContainer;






// import './createContainer.css';
// import CreatePantryItemForm from './CreatePantryItemForm';

// const CreatePantryItemContainer = () => {
// return (
// <>
// <div className='create-container'>
// <CreatePantryItemForm />
// </div>
// </>
// );
// };

// export default CreatePantryItemContainer;
Loading