From d92e012db5507c1eaf78fa4939ef7f4bedbe0ca6 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E3=82=A2=E3=83=AC=E3=82=AF=E3=82=B5=E3=83=B3=E3=83=80?= =?UTF-8?q?=E3=83=BC=2Eeth?= Date: Mon, 4 Dec 2023 15:30:24 +0900 Subject: [PATCH] fix: background image on every row --- src/home/authenticated-get-github-user.ts | 1 - src/home/display-github-issues.ts | 4 +-- src/home/home-controller.ts | 8 +++--- src/home/home.ts | 31 +---------------------- 4 files changed, 7 insertions(+), 37 deletions(-) diff --git a/src/home/authenticated-get-github-user.ts b/src/home/authenticated-get-github-user.ts index 71237da9..cda4751a 100644 --- a/src/home/authenticated-get-github-user.ts +++ b/src/home/authenticated-get-github-user.ts @@ -23,7 +23,6 @@ async function getActiveSessionToken(): Promise { async function getNewSessionToken(): Promise { const hash = window.location.hash; - console.trace({ hash }); const params = new URLSearchParams(hash.substr(1)); // remove the '#' and parse // access_token=eyJhbGciOiJIUzI1NiIsImtpZCI6InJCQVV5bHBBeUN5Sk1LVUIiLCJ0eXAiOiJKV1QifQ.eyJhdWQiOiJhdXRoZW50aWNhdGVkIiwiZXhwIjoxNzAxMzQ0NjY0LCJpYXQiOjE3MDEzNDEwNjQsImlzcyI6Imh0dHBzOi8vd2Z6cGV3bWx5aW96dXB1bGJ1dXIuc3VwYWJhc2UuY28vYXV0aC92MSIsInN1YiI6IjE3NmRlZjk0LWNiMGEtNGNlYi1iMWMwLTg1ODJiMDlmZmE5ZCIsImVtYWlsIjoiZ2l0aHViQHBhdmxvdmNpay5jb20iLCJwaG9uZSI6IiIsImFwcF9tZXRhZGF0YSI6eyJwcm92aWRlciI6ImdpdGh1YiIsInByb3ZpZGVycyI6WyJnaXRodWIiXX0sInVzZXJfbWV0YWRhdGEiOnsiYXZhdGFyX3VybCI6Imh0dHBzOi8vYXZhdGFycy5naXRodWJ1c2VyY29udGVudC5jb20vdS80OTc1NjcwP3Y9NCIsImVtYWlsIjoiZ2l0aHViQHBhdmxvdmNpay5jb20iLCJlbWFpbF92ZXJpZmllZCI6dHJ1ZSwiZnVsbF9uYW1lIjoi44Ki44Os44Kv44K144Oz44OA44O8LmV0aCIsImlzcyI6Imh0dHBzOi8vYXBpLmdpdGh1Yi5jb20iLCJuYW1lIjoi44Ki44Os44Kv44K144Oz44OA44O8LmV0aCIsInBob25lX3ZlcmlmaWVkIjpmYWxzZSwicHJlZmVycmVkX3VzZXJuYW1lIjoicGF2bG92Y2lrIiwicHJvdmlkZXJfaWQiOiI0OTc1NjcwIiwic3ViIjoiNDk3NTY3MCIsInVzZXJfbmFtZSI6InBhdmxvdmNpayJ9LCJyb2xlIjoiYXV0aGVudGljYXRlZCIsImFhbCI6ImFhbDEiLCJhbXIiOlt7Im1ldGhvZCI6Im9hdXRoIiwidGltZXN0YW1wIjoxNzAxMzQxMDY0fV0sInNlc3Npb25faWQiOiI0YzBlNjA5MC0zZGJmLTQ4OTMtYTRjYi1lYTlmZTIwZDQ1YjcifQ.YgLDGqngdIBCO2o041Xv0UzymdMgYQlW8GLBmdfDKkM // &expires_at=1701344664 diff --git a/src/home/display-github-issues.ts b/src/home/display-github-issues.ts index 73979e8b..5262f298 100644 --- a/src/home/display-github-issues.ts +++ b/src/home/display-github-issues.ts @@ -53,7 +53,7 @@ async function fetchIssues(container: HTMLDivElement, accessToken: string | null const issues = JSON.parse(cachedIssues); const sortedIssuesByTime = sortIssuesByTime(issues); const sortedIssuesByPriority = sortIssuesByPriority(sortedIssuesByTime); - homeController(container, sortedIssuesByPriority); + await homeController(container, sortedIssuesByPriority); } catch (error) { console.error(error); } @@ -81,7 +81,7 @@ async function fetchIssues(container: HTMLDivElement, accessToken: string | null const sortedIssuesByPriority = sortIssuesByPriority(sortedIssuesByTime); // Pass the fresh issues to the homeController - homeController(container, sortedIssuesByPriority); + await homeController(container, sortedIssuesByPriority); // Remove the 'isNew' flag before saving to localStorage const issuesToSave = freshIssues.map(({ ...issue }) => { diff --git a/src/home/home-controller.ts b/src/home/home-controller.ts index 4b209056..b55fa271 100644 --- a/src/home/home-controller.ts +++ b/src/home/home-controller.ts @@ -1,6 +1,6 @@ import { GitHubIssueWithNewFlag } from "./display-github-issues"; -export function homeController(container: HTMLDivElement, issues: GitHubIssueWithNewFlag[]) { +export async function homeController(container: HTMLDivElement, issues: GitHubIssueWithNewFlag[]) { const avatarCache: Record = JSON.parse(localStorage.getItem("avatarCache") || "{}"); const fetchInProgress = new Set(); // Track in-progress fetches const existingIssueIds = new Set(Array.from(container.querySelectorAll(".issue-element-inner")).map((element) => element.getAttribute("data-issue-id"))); @@ -8,7 +8,7 @@ export function homeController(container: HTMLDivElement, issues: GitHubIssueWit let delay = 0; const baseDelay = 1000 / 15; // Base delay in milliseconds - issues.forEach(async (issue) => { + for (const issue of issues) { if (!existingIssueIds.has(issue.id.toString())) { const issueWrapper = document.createElement("div"); const issueElement = document.createElement("div"); @@ -100,7 +100,7 @@ export function homeController(container: HTMLDivElement, issues: GitHubIssueWit } container.appendChild(issueWrapper); - container.classList.add("ready"); } - }); + } + container.classList.add("ready"); } diff --git a/src/home/home.ts b/src/home/home.ts index 981bed20..c0b791f3 100644 --- a/src/home/home.ts +++ b/src/home/home.ts @@ -9,36 +9,7 @@ displayGitHubIssues(gitHubToken) .then(authenticatedGetGitHubUser) .then((gitHubUser: null | GitHubUser) => { if (gitHubUser) { - console.trace({ gitHubUser }); displayGitHubUserInformation(gitHubUser); } }) - .catch((error) => { - console.error(error); - }); - -// const isLight = prefersLightMode(); -// if (isLight) { -// console.trace({ isLight }); -// downloadStylesheet("style/inverted-style.css"); -// } - -// function downloadStylesheet(url: string) { -// const xhr = new XMLHttpRequest(); -// xhr.open("GET", url, true); -// xhr.onreadystatechange = () => { -// if (xhr.readyState === XMLHttpRequest.DONE) { -// if (xhr.status === 200) { -// const style = document.createElement("style"); -// style.textContent = xhr.responseText; -// document.head.appendChild(style); -// } else { -// console.error("Failed to load stylesheet", url); -// } -// } -// }; -// xhr.send(); -// } -// function prefersLightMode() { -// return window.matchMedia("(prefers-color-scheme: light)").matches; -// } + .catch((error) => console.error(error));