Feat:Added loading text to be replaced with animation after
This commit is contained in:
@@ -3,7 +3,7 @@ import Td from "./Td";
|
|||||||
|
|
||||||
const FarmList = () => {
|
const FarmList = () => {
|
||||||
const [data, setData] = useState([]);
|
const [data, setData] = useState([]);
|
||||||
|
const [loading, setLoading] = useState(true);
|
||||||
useEffect(() => {
|
useEffect(() => {
|
||||||
fetch("http://localhost:8000/api/v1/farm", {
|
fetch("http://localhost:8000/api/v1/farm", {
|
||||||
credentials: "include",
|
credentials: "include",
|
||||||
@@ -12,43 +12,48 @@ const FarmList = () => {
|
|||||||
})
|
})
|
||||||
.then((response) => response.json())
|
.then((response) => response.json())
|
||||||
.then((data) => setData(data))
|
.then((data) => setData(data))
|
||||||
|
.then(setLoading(false))
|
||||||
.catch((error) => console.error(error));
|
.catch((error) => console.error(error));
|
||||||
}, []);
|
}, []);
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<div className="relative overflow-x-auto shadow-md sm:rounded-lg">
|
<div className="relative overflow-x-auto shadow-md sm:rounded-lg">
|
||||||
<table className="w-full text-sm text-left rtl:text-right text-gray-500 dark:text-gray-400">
|
{loading ? (
|
||||||
<thead className="text-xs text-gray-700 uppercase bg-gray-50 dark:bg-gray-700 dark:text-gray-400">
|
<div>Loading...</div>
|
||||||
<tr>
|
) : (
|
||||||
<th scope="col" className="px-6 py-3">
|
<table className="w-full text-sm text-left rtl:text-right text-gray-500 dark:text-gray-400">
|
||||||
Farm name
|
<thead className="text-xs text-gray-700 uppercase bg-gray-50 dark:bg-gray-700 dark:text-gray-400">
|
||||||
</th>
|
|
||||||
<th scope="col" className="px-6 py-3">
|
|
||||||
Location
|
|
||||||
</th>
|
|
||||||
<th scope="col" className="px-6 py-3">
|
|
||||||
Type
|
|
||||||
</th>
|
|
||||||
<th scope="col" className="px-6 py-3">
|
|
||||||
Size (acres)
|
|
||||||
</th>
|
|
||||||
<th scope="col" className="px-6 py-3">
|
|
||||||
Action
|
|
||||||
</th>
|
|
||||||
</tr>
|
|
||||||
</thead>
|
|
||||||
<tbody>
|
|
||||||
{data.length > 0 ? (
|
|
||||||
data.map((item) => <Td key={item.id} children={item} />)
|
|
||||||
) : (
|
|
||||||
<tr>
|
<tr>
|
||||||
<td colSpan={5} className="text-center">
|
<th scope="col" className="px-6 py-3">
|
||||||
No data available
|
Farm name
|
||||||
</td>
|
</th>
|
||||||
|
<th scope="col" className="px-6 py-3">
|
||||||
|
Location
|
||||||
|
</th>
|
||||||
|
<th scope="col" className="px-6 py-3">
|
||||||
|
Type
|
||||||
|
</th>
|
||||||
|
<th scope="col" className="px-6 py-3">
|
||||||
|
Size (acres)
|
||||||
|
</th>
|
||||||
|
<th scope="col" className="px-6 py-3">
|
||||||
|
Action
|
||||||
|
</th>
|
||||||
</tr>
|
</tr>
|
||||||
)}
|
</thead>
|
||||||
</tbody>
|
<tbody>
|
||||||
</table>
|
{data.length > 0 ? (
|
||||||
|
data.map((item) => <Td key={item.id} children={item} />)
|
||||||
|
) : (
|
||||||
|
<tr>
|
||||||
|
<td colSpan={5} className="text-center">
|
||||||
|
No data available
|
||||||
|
</td>
|
||||||
|
</tr>
|
||||||
|
)}
|
||||||
|
</tbody>
|
||||||
|
</table>
|
||||||
|
)}
|
||||||
</div>
|
</div>
|
||||||
);
|
);
|
||||||
};
|
};
|
||||||
|
|||||||
Reference in New Issue
Block a user