generated from ubiquity/ts-template
-
Notifications
You must be signed in to change notification settings - Fork 29
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
7 changed files
with
434 additions
and
76 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,48 @@ | ||
import { Octokit } from "@octokit/rest"; | ||
import { GitHubIssue } from "./github-types"; | ||
import { displayIssues } from "./scripts/display-issues"; | ||
|
||
export async function mainModule() { | ||
const container = document.getElementById("issues-container") as HTMLDivElement; | ||
if (!container) { | ||
throw new Error("Could not find issues container"); | ||
} | ||
await fetchIssues(); | ||
|
||
async function fetchIssues() { | ||
try { | ||
const cachedIssues = localStorage.getItem("githubIssues"); | ||
|
||
if (cachedIssues) { | ||
try { | ||
const issues = JSON.parse(cachedIssues); | ||
const sortedIssues = sortIssuesByComments(issues); | ||
displayIssues(container, sortedIssues); | ||
} catch (error) { | ||
console.error(error); | ||
} | ||
} | ||
|
||
const octokit = new Octokit(); | ||
|
||
const freshIssues = (await octokit.paginate("GET /repos/ubiquity/devpool-directory/issues")) as GitHubIssue[]; | ||
localStorage.setItem("githubIssues", JSON.stringify(freshIssues)); | ||
const sortedIssues = sortIssuesByComments(freshIssues); | ||
displayIssues(container, sortedIssues); | ||
} catch (error) { | ||
container.innerHTML = `<p>Error loading issues: ${error}</p>`; | ||
} | ||
} | ||
|
||
function sortIssuesByComments(issues: GitHubIssue[]) { | ||
return issues.sort((a, b) => { | ||
if (a.comments > b.comments) { | ||
return -1; | ||
} | ||
if (a.comments < b.comments) { | ||
return 1; | ||
} | ||
return 0; | ||
}); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,52 @@ | ||
import { GitHubIssue } from "../github-types"; | ||
|
||
export function displayIssues(container: HTMLDivElement, issues: GitHubIssue[]) { | ||
container.innerHTML = ""; | ||
let delay = 0; | ||
const baseDelay = 125; // Base delay in milliseconds | ||
|
||
issues.forEach((issue, index) => { | ||
const issueWrapper = document.createElement("div"); | ||
const issueElement = document.createElement("div"); | ||
issueWrapper.classList.add("issue-element-wrapper"); | ||
issueElement.classList.add("issue-element-inner"); | ||
issueWrapper.classList.add("issue-fade-in"); | ||
|
||
// Calculate the delay using an approximation of the cubic-bezier(0,1,1,1) easing function | ||
delay = baseDelay * ((index * index) / (issues.length - 1)); | ||
|
||
issueElement.style.animationDelay = `${delay}ms`; | ||
|
||
// Parse organization name and repository name from the issue's URL | ||
|
||
const urlRegex = /(https?:\/\/[^\s]+)/g; | ||
const mirrorUrls = issue.body.match(urlRegex); | ||
|
||
const urlPattern = /https:\/\/github\.com\/([^/]+)\/([^/]+)\//; | ||
const match = mirrorUrls?.shift()?.match(urlPattern); | ||
const organizationName = match?.[1]; | ||
const repositoryName = match?.[2]; | ||
|
||
issueElement.innerHTML = ` | ||
<h3>${issue.title}</h3> | ||
<p class="organization-name">${organizationName}</p> | ||
<p class="repository-name">${repositoryName}</p> | ||
`; | ||
|
||
issueElement.addEventListener("click", () => { | ||
console.log(issue); | ||
|
||
// console.log(foundUrls); | ||
// window.open(foundUrls?.shift(), "_blank"); | ||
}); | ||
|
||
issueWrapper.appendChild(issueElement); | ||
|
||
// Append the issue element after the delay | ||
setTimeout(() => { | ||
container.appendChild(issueWrapper); | ||
// Trigger the animation by adding the 'visible' class | ||
issueElement.classList.add("visible"); | ||
}, delay); | ||
}); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.