Skip to content

Commit

Permalink
Merge pull request #143 from zugdev/use-org-label
Browse files Browse the repository at this point in the history
0x4007 authored Oct 31, 2024

Verified

This commit was created on GitHub.com and signed with GitHub’s verified signature.
2 parents c6d12ae + 363dcd7 commit c4d5b58
Showing 6 changed files with 8,386 additions and 5,864 deletions.
3 changes: 3 additions & 0 deletions src/home/fetch-github/fetch-and-display-previews.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import { GitHubIssue } from "../github-types";
import { taskManager } from "../home";
import { applyAvatarsToIssues, renderGitHubIssues } from "../rendering/render-github-issues";
import { renderOrgHeaderLabel } from "../rendering/render-org-header";
import { closeModal } from "../rendering/render-preview-modal";
import { Sorting } from "../sorting/generate-sorting-buttons";
import { sortIssuesController } from "../sorting/sort-issues-controller";
@@ -65,6 +66,8 @@ function filterIssuesByOrganization(issues: GitHubIssue[]): GitHubIssue[] {
window.location.href = "/";
}

renderOrgHeaderLabel(urlOrgName);

return filteredIssues;
}

28 changes: 28 additions & 0 deletions src/home/rendering/render-org-header.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
import { organizationImageCache } from "../fetch-github/fetch-issues-full";

export function renderOrgHeaderLabel(orgName: string): void {
const brandingDiv = document.getElementById("branding");
if (!brandingDiv) return;

// Fetch the organization logo from the cache
const logoBlob = organizationImageCache.get(orgName);

if (logoBlob) {
// Convert Blob to a URL
const logoUrl = URL.createObjectURL(logoBlob);

const img = document.createElement("img");
img.src = logoUrl;
img.alt = `${orgName} Logo`;
console.log("oi");
img.id = "logo";

// Replace the existing SVG with the new image
const svgLogo = brandingDiv.querySelector("svg#logo");
if (svgLogo) brandingDiv.replaceChild(img, svgLogo);
}

// Update the organization name inside the span with class 'full'
const orgNameSpan = brandingDiv.querySelector("span.full");
if (orgNameSpan) orgNameSpan.textContent = `${orgName} | `;
}
65 changes: 36 additions & 29 deletions static/progressive-web-app.js
Original file line number Diff line number Diff line change
@@ -12,7 +12,7 @@ const urlsToCache = [
];

// Install event (caches all necessary files)
self.addEventListener("install", (event) => {
self.addEventListener("install", async (event) => {
event.waitUntil(
(async () => {
try {
@@ -28,7 +28,7 @@ self.addEventListener("install", (event) => {
});

// Activate event (deletes old caches when updated)
self.addEventListener("activate", (event) => {
self.addEventListener("activate", async (event) => {
event.waitUntil(
(async () => {
try {
@@ -64,36 +64,43 @@ self.addEventListener("fetch", (event) => {

event.respondWith(
(async () => {
try {
const cachedResponse = await caches.match(event.request);
const cachedResponse = await caches.match(event.request);

const fetchPromise = fetch(event.request)
.then(async (networkResponse) => {
if (networkResponse.ok) {
const responseClone = networkResponse.clone();
const cache = await caches.open(cacheName);
await cache.put(event.request, responseClone);
if (cachedResponse) {
// Start a network fetch in the background to update the cache, this will return early from cache
// but the fetch will still happen in the background
event.waitUntil(
(async () => {
try {
const networkResponse = await fetch(event.request);
if (networkResponse.ok) {
const responseClone = networkResponse.clone();
const cache = await caches.open(cacheName);
await cache.put(event.request, responseClone);
}
} catch (error) {
console.error("[Service Worker] Background cache update failed:", error);
}
return networkResponse;
})
.catch((error) => {
console.error("[Service Worker] Network request failed:", error);
return (
cachedResponse ||
new Response("Offline content unavailable", {
status: 503,
statusText: "Service Unavailable",
})
);
})()
);
return cachedResponse;
} else {
// Attempt to fetch from the network if no cache is available
try {
const networkResponse = await fetch(event.request);
if (networkResponse.ok) {
const responseClone = networkResponse.clone();
const cache = await caches.open(cacheName);
await cache.put(event.request, responseClone);
}
return networkResponse;
} catch (error) {
console.error("[Service Worker] Fetch failed, and no cache is available:", error);
return new Response("An error occurred", {
status: 500,
statusText: "Internal Server Error",
});

return cachedResponse || (await fetchPromise);
} catch (error) {
console.error("[Service Worker] Error handling fetch:", error);
return new Response("An error occurred", {
status: 500,
statusText: "Internal Server Error",
});
}
}
})()
);
2 changes: 2 additions & 0 deletions static/style/inverted-style.css
Original file line number Diff line number Diff line change
@@ -54,7 +54,9 @@
}
#logo {
height: 28px;
width: 24.469px;
margin-right: 8px;
object-fit: contain;
vertical-align: middle;
}
#authenticated,
2 changes: 2 additions & 0 deletions static/style/style.css
Original file line number Diff line number Diff line change
@@ -54,7 +54,9 @@
}
#logo {
height: 28px;
width: 24.469px;
margin-right: 8px;
object-fit: contain;
vertical-align: middle;
}
#authenticated,
14,150 changes: 8,315 additions & 5,835 deletions yarn.lock

Large diffs are not rendered by default.

0 comments on commit c4d5b58

Please sign in to comment.