From 5f6c38f14cf86fedfb7991feca9e114990209dbf Mon Sep 17 00:00:00 2001 From: zugdev Date: Wed, 30 Oct 2024 00:15:13 -0300 Subject: [PATCH] feat: if no issues in org redirect to home --- src/home/fetch-github/fetch-and-display-previews.ts | 12 ++++++++++-- 1 file changed, 10 insertions(+), 2 deletions(-) diff --git a/src/home/fetch-github/fetch-and-display-previews.ts b/src/home/fetch-github/fetch-and-display-previews.ts index d408a951..3d407ed2 100644 --- a/src/home/fetch-github/fetch-and-display-previews.ts +++ b/src/home/fetch-github/fetch-and-display-previews.ts @@ -53,11 +53,19 @@ function filterIssuesByOrganization(issues: GitHubIssue[]): GitHubIssue[] { // if there is no organization name in the URL, return all issues if (!urlOrgName) return issues; - // compare URL organization name with the organization name in the issue's repository URL - return issues.filter((issue) => { + // filter issues by matching the URL organization name with the issue's organization name + const filteredIssues = issues.filter((issue) => { const [issueOrgName] = issue.repository_url.split("/").slice(-2); return issueOrgName === urlOrgName; }); + + // if no issues match the organization, redirect to home + if (filteredIssues.length === 0) { + console.log(`No issues found for organization "${urlOrgName}". Redirecting to the home page.`); + window.location.href = "/"; + } + + return filteredIssues; } // checks the cache's integrity, sorts issues, checks Directory/Proposals toggle, renders them and applies avatars