+
Admin Panel
+
+ {users.map((user) => (
+
+ {user.username} - {user.role}
+
+
+ ))
+ }
+
+ )
+}
\ No newline at end of file
diff --git a/frontend/src/pages/GroceryList.jsx b/frontend/src/pages/GroceryList.jsx
index e69de29..2cee0c5 100644
--- a/frontend/src/pages/GroceryList.jsx
+++ b/frontend/src/pages/GroceryList.jsx
@@ -0,0 +1,103 @@
+import { useContext, useEffect, useState } from "react";
+import { addItem, getList, markBought } from "../api/list";
+import { AuthContext } from "../context/AuthContext";
+
+export default function GroceryList() {
+ const { role, username } = useContext(AuthContext);
+
+ const [items, setItems] = useState([]);
+ const [itemName, setItemName] = useState("");
+ const [quantity, setQuantity] = useState(1);
+ const [loading, setLoading] = useState(true);
+ const [error, setError] = useState("");
+
+ // Load list
+ const loadItems = async () => {
+ try {
+ setLoading(true);
+ const response = await getList();
+ setItems(response.data);
+ setLoading(false);
+ } catch (err) {
+ setError("Failed to load grocery list");
+ setLoading(false);
+ }
+ };
+
+ useEffect(() => {
+ loadItems();
+ }, []);
+
+ // Add item (editor/admin)
+ const handleAdd = async (e) => {
+ e.preventDefault();
+ try {
+ await addItem(itemName, quantity);
+ setItemName("");
+ setQuantity(1);
+ loadItems();
+ } catch (err) {
+ console.log(err);
+ setError("Failed to add item");
+ }
+ };
+
+ // Mark bought (editor/admin)
+ const handleBought = async (id) => {
+ try {
+ await markBought(id);
+ loadItems();
+ } catch (err) {
+ setError("Failed to mark item as bought");
+ }
+ };
+
+ if (loading) return Loading...
;
+ if (error) return
+
Grocery List
+
Logged in as: {username} ({role})
+
+ {/* Add Item Section (editor/admin only) */}
+ {(role === "editor" || role === "admin") && (
+
+ )}
+
+ {/* Grocery List */}
+
+ {items.map((item) => (
+ -
+ {item.item_name} — {item.quantity}
+
+ {(role === "editor" || role === "admin") && (
+
+ )}
+
+ ))}
+
+
+ );
+}
diff --git a/frontend/src/pages/Login.jsx b/frontend/src/pages/Login.jsx
index e69de29..e8d1d2d 100644
--- a/frontend/src/pages/Login.jsx
+++ b/frontend/src/pages/Login.jsx
@@ -0,0 +1,44 @@
+import { useContext, useState } from "react";
+import { loginRequest } from "../api/auth";
+import { AuthContext } from "../context/AuthContext";
+
+export default function Login() {
+ const { login } = useContext(AuthContext);
+ const [username, setUsername] = useState("");
+ const [password, setPassword] = useState("");
+ const [error, setError] = useState("");
+
+ const submit = async (e) => {
+ e.preventDefault();
+ setError("");
+ try {
+ const data = await loginRequest(username, password);
+ login(data);
+ window.location.href = "/";
+ } catch (err) {
+ setError("Invalid username or password");
+ }
+ };
+
+
+ return (
+