mirror of
https://github.com/hex248/sprint.git
synced 2026-02-08 10:33:01 +00:00
better usage of issues/all data
This commit is contained in:
23
src/Home.tsx
23
src/Home.tsx
@@ -1,29 +1,40 @@
|
|||||||
import { useState } from "react";
|
import { useState } from "react";
|
||||||
import { Button } from "@/components/ui/button";
|
import { Button } from "@/components/ui/button";
|
||||||
|
|
||||||
|
function Issue({ issue }: { issue: any }) {
|
||||||
|
return (
|
||||||
|
<div className="w-sm p-4 border">
|
||||||
|
[{issue.id}] {issue.title}
|
||||||
|
</div>
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
function Home() {
|
function Home() {
|
||||||
const [issues, setIssues] = useState([]);
|
const [issues, setIssues] = useState([]);
|
||||||
const [serverURL, setServerURL] = useState("http://localhost:3000");
|
const [serverURL, setServerURL] = useState("http://localhost:3000");
|
||||||
|
|
||||||
async function getIssues() {
|
async function getIssues() {
|
||||||
const res = await fetch(`${serverURL}/issues/all`);
|
const res = await fetch(`${serverURL}/issues/all`);
|
||||||
|
const data = await res.json();
|
||||||
|
setIssues(data);
|
||||||
}
|
}
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<main className="w-full h-[100vh] flex flex-col items-center justify-center gap-4 p-4">
|
<main className="w-full h-[100vh] flex flex-col items-center justify-center gap-4 p-4">
|
||||||
<h1>Issue Project Manager</h1>
|
<h1>Issue Project Manager</h1>
|
||||||
|
|
||||||
<Button onClick={getIssues} className={""}>
|
<Button onClick={getIssues} className={""}>
|
||||||
get issues
|
{issues.length > 0 ? "re-fetch issues" : "fetch issues"}
|
||||||
</Button>
|
</Button>
|
||||||
|
|
||||||
<div>Issues count: {issues.length}</div>
|
|
||||||
{issues.length > 0 && (
|
{issues.length > 0 && (
|
||||||
<ul>
|
<>
|
||||||
{issues.map((issue: any) => (
|
{issues.map((issue: any) => (
|
||||||
<li key={issue.id}>{issue.title}</li>
|
<Issue key={issue.id} issue={issue} />
|
||||||
))}
|
))}
|
||||||
</ul>
|
<pre className="w-2xl max-h-96 overflow-auto p-4 border bg-">
|
||||||
|
{JSON.stringify(issues, null, 2)}
|
||||||
|
</pre>
|
||||||
|
</>
|
||||||
)}
|
)}
|
||||||
</main>
|
</main>
|
||||||
);
|
);
|
||||||
|
|||||||
Reference in New Issue
Block a user