feat: fetch user info
All checks were successful
Build and Deploy Go App / build (push) Successful in 6m46s
Build and Deploy Go App / deploy (push) Successful in 2m54s

This commit is contained in:
nihonium 2025-10-11 04:25:57 +03:00
parent 28c38ca1a0
commit 8e44b8b7b4
Signed by: nihonium
GPG key ID: 0251623741027CFC
16 changed files with 1254 additions and 13 deletions

View file

@ -1,36 +1,37 @@
import React, { useEffect, useState } from "react";
import { fetchItems } from "./services/api";
import type { Item } from "./services/api";
import ItemTemplate from "./components/ItemTemplate";
import { DefaultService } from "./api/services/DefaultService"; // adjust path if needed
import type { User } from "./api/models/User"; // adjust path if needed
const App: React.FC = () => {
const [items, setItems] = useState<Item[]>([]);
const [user, setUser] = useState<User | null>(null);
const [loading, setLoading] = useState(true);
const [error, setError] = useState<string | null>(null);
useEffect(() => {
const getData = async () => {
const getUserInfo = async () => {
try {
const data = await fetchItems();
setItems(data);
const userInfo = await DefaultService.getUsers("1", "all");
setUser(userInfo);
} catch (err) {
setError("Failed to fetch items.");
console.error(err);
setError("Failed to fetch user info.");
} finally {
setLoading(false);
}
};
getData();
getUserInfo();
}, []);
if (loading) return <div>Loading...</div>;
if (error) return <div>{error}</div>;
if (!user) return <div>No user found.</div>;
return (
<div style={{ padding: "2rem" }}>
<h1>Items List</h1>
{items.map((item) => (
<ItemTemplate key={item.id} item={item} />
))}
<h1>User Info</h1>
<p><strong>ID:</strong> {user.id}</p>
<p><strong>Name:</strong> {user.name}</p>
<p><strong>Email:</strong> {user.email}</p>
</div>
);
};