mirror of
https://github.com/hex248/sprint.git
synced 2026-02-08 18:33:01 +00:00
refetchIssues function
This commit is contained in:
@@ -80,6 +80,10 @@ function Index() {
|
|||||||
void refetchOrganisations();
|
void refetchOrganisations();
|
||||||
}, [user.id]);
|
}, [user.id]);
|
||||||
|
|
||||||
|
useEffect(() => {
|
||||||
|
setSelectedOrganisation((prev) => prev || organisations[0] || null);
|
||||||
|
}, [organisations]);
|
||||||
|
|
||||||
const refetchProjects = async (organisationId: number, options?: { selectProjectId?: number }) => {
|
const refetchProjects = async (organisationId: number, options?: { selectProjectId?: number }) => {
|
||||||
try {
|
try {
|
||||||
const res = await fetch(
|
const res = await fetch(
|
||||||
@@ -126,24 +130,30 @@ function Index() {
|
|||||||
void refetchProjects(selectedOrganisation.Organisation.id);
|
void refetchProjects(selectedOrganisation.Organisation.id);
|
||||||
}, [selectedOrganisation]);
|
}, [selectedOrganisation]);
|
||||||
|
|
||||||
|
useEffect(() => {
|
||||||
|
setSelectedProject((prev) => prev || projects[0] || null);
|
||||||
|
}, [projects]);
|
||||||
|
|
||||||
|
const refetchIssues = async (projectKey: string) => {
|
||||||
|
try {
|
||||||
|
const res = await fetch(`${serverURL}/issues/${projectKey}`, {
|
||||||
|
headers: getAuthHeaders(),
|
||||||
|
});
|
||||||
|
const data = (await res.json()) as IssueResponse[];
|
||||||
|
setIssues(data);
|
||||||
|
} catch (err) {
|
||||||
|
console.error("error fetching issues:", err);
|
||||||
|
setIssues([]);
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
// fetch issues when project is selected
|
// fetch issues when project is selected
|
||||||
useEffect(() => {
|
useEffect(() => {
|
||||||
if (!selectedProject) return;
|
if (!selectedProject) return;
|
||||||
|
|
||||||
fetch(`${serverURL}/issues/${selectedProject.Project.key}`, { headers: getAuthHeaders() })
|
void refetchIssues(selectedProject.Project.key);
|
||||||
.then((res) => res.json())
|
|
||||||
.then((data: IssueResponse[]) => {
|
|
||||||
setIssues(data);
|
|
||||||
})
|
|
||||||
.catch((err) => {
|
|
||||||
console.error("error fetching issues:", err);
|
|
||||||
});
|
|
||||||
}, [selectedProject]);
|
}, [selectedProject]);
|
||||||
|
|
||||||
useEffect(() => {
|
|
||||||
setSelectedProject((prev) => prev || projects[0] || null);
|
|
||||||
}, [projects]);
|
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<main className="w-full h-full p-1">
|
<main className="w-full h-full p-1">
|
||||||
{/* header area */}
|
{/* header area */}
|
||||||
|
|||||||
Reference in New Issue
Block a user