Skip to content

Commit

Permalink
fix: background image on every row
Browse files Browse the repository at this point in the history
  • Loading branch information
0x4007 committed Dec 4, 2023
1 parent 2218d97 commit d92e012
Show file tree
Hide file tree
Showing 4 changed files with 7 additions and 37 deletions.
1 change: 0 additions & 1 deletion src/home/authenticated-get-github-user.ts
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,6 @@ async function getActiveSessionToken(): Promise<string | null> {

async function getNewSessionToken(): Promise<string | null> {
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
Expand Down
4 changes: 2 additions & 2 deletions src/home/display-github-issues.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}
Expand Down Expand Up @@ -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 }) => {
Expand Down
8 changes: 4 additions & 4 deletions src/home/home-controller.ts
Original file line number Diff line number Diff line change
@@ -1,14 +1,14 @@
import { GitHubIssueWithNewFlag } from "./display-github-issues";

export function homeController(container: HTMLDivElement, issues: GitHubIssueWithNewFlag[]) {
export async function homeController(container: HTMLDivElement, issues: GitHubIssueWithNewFlag[]) {
const avatarCache: Record<string, string> = 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")));

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");
Expand Down Expand Up @@ -100,7 +100,7 @@ export function homeController(container: HTMLDivElement, issues: GitHubIssueWit
}

container.appendChild(issueWrapper);
container.classList.add("ready");
}
});
}
container.classList.add("ready");
}
31 changes: 1 addition & 30 deletions src/home/home.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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));

0 comments on commit d92e012

Please sign in to comment.