feat: initial frontend commit
This commit is contained in:
parent
6612ed6df6
commit
e1cdb7af79
18 changed files with 4146 additions and 0 deletions
38
modules/frontend/src/App.tsx
Normal file
38
modules/frontend/src/App.tsx
Normal file
|
|
@ -0,0 +1,38 @@
|
|||
import React, { useEffect, useState } from "react";
|
||||
import { fetchItems } from "./services/api";
|
||||
import type { Item } from "./services/api";
|
||||
import ItemTemplate from "./components/ItemTemplate";
|
||||
|
||||
const App: React.FC = () => {
|
||||
const [items, setItems] = useState<Item[]>([]);
|
||||
const [loading, setLoading] = useState(true);
|
||||
const [error, setError] = useState<string | null>(null);
|
||||
|
||||
useEffect(() => {
|
||||
const getData = async () => {
|
||||
try {
|
||||
const data = await fetchItems();
|
||||
setItems(data);
|
||||
} catch (err) {
|
||||
setError("Failed to fetch items.");
|
||||
} finally {
|
||||
setLoading(false);
|
||||
}
|
||||
};
|
||||
getData();
|
||||
}, []);
|
||||
|
||||
if (loading) return <div>Loading...</div>;
|
||||
if (error) return <div>{error}</div>;
|
||||
|
||||
return (
|
||||
<div style={{ padding: "2rem" }}>
|
||||
<h1>Items List</h1>
|
||||
{items.map((item) => (
|
||||
<ItemTemplate key={item.id} item={item} />
|
||||
))}
|
||||
</div>
|
||||
);
|
||||
};
|
||||
|
||||
export default App;
|
||||
Loading…
Add table
Add a link
Reference in a new issue