Skip to content

Commit

Permalink
Refactor image loading logic in createCard function
Browse files Browse the repository at this point in the history
  • Loading branch information
BumpyClock committed Apr 11, 2024
1 parent 28f6e1a commit ea96a84
Show file tree
Hide file tree
Showing 5 changed files with 34 additions and 20 deletions.
Binary file modified .DS_Store
Binary file not shown.
37 changes: 21 additions & 16 deletions src/scripts.js
Original file line number Diff line number Diff line change
Expand Up @@ -192,21 +192,25 @@ function loadSubscribedFeeds() {
: refreshFeeds();
}

function refreshFeeds() {
const { subscribedFeeds } = getSubscribedFeeds();
const serviceWorker = navigator.serviceWorker.controller;
if (!serviceWorker) {
console.error("Service worker is not active or not controlled.");
return;
async function refreshFeeds() {
try {
const { subscribedFeeds } = await getSubscribedFeeds();
const serviceWorker = navigator.serviceWorker.controller;
if (!serviceWorker) {
throw new Error("Service worker is not active or not controlled.");
}
feedList.subscribedFeeds = subscribedFeeds;
lastRefreshed = new Date().getTime();
serviceWorker.postMessage({
action: "fetchRSS",
feedUrls: feedList.subscribedFeeds
});
} catch (error) {
console.error("Failed to refresh feeds:", error);
}
feedList.subscribedFeeds = subscribedFeeds;
lastRefreshed = new Date().getTime();
serviceWorker.postMessage({
action: "fetchRSS",
feedUrls: feedList.subscribedFeeds
});
}


function discoverFeeds() {
const serviceWorker = navigator.serviceWorker.controller;
if (serviceWorker) {
Expand Down Expand Up @@ -235,12 +239,13 @@ async function updateDisplayOnNewTab() {
}

function initializeMasonry() {
msnry = new Masonry(feedContainer, {
msnry = new Masonry(feedContainer, {
itemSelector: ".card",
columnWidth: ".card",
gutter: 24,
fitWidth: true
});
transitionDuration: '0.25s', // set the transition duration
stagger: 30 // set the stagger delay
});
document.querySelectorAll(".masonry-item").forEach(item => {
item.addEventListener("load", () => {
msnry.layout();
Expand All @@ -250,7 +255,7 @@ function initializeMasonry() {
});
const debouncedLayout = debounce(() => {
msnry.layout();
}, 300);
}, 100);
window.addEventListener("resize", debouncedLayout);
}

Expand Down
5 changes: 3 additions & 2 deletions src/scripts/cards.js
Original file line number Diff line number Diff line change
Expand Up @@ -12,12 +12,13 @@ function sanitizeHTML(html) {
}

function createImageContainer(thumbnailUrl, siteTitle) {
const imageProxyURL = "https://digests-imgproxy-a4crwf5b7a-uw.a.run.app/unsafe/rs:fit:0:300:0/g:no/plain/" + thumbnailUrl;
const imageContainer = createElement('div', { className: 'image-container loading' });
const cardbg = createElement('div', { className: 'card-bg' });

if (thumbnailUrl) {
imageContainer.innerHTML = `<img data-src="${thumbnailUrl}" id="thumbnail-image" alt="${siteTitle} Thumbnail" class="thumbnail-image lazyload masonry-item">`;
cardbg.innerHTML = `<div class=noise></div><img data-src="${thumbnailUrl}" alt="${siteTitle} Thumbnail" class="card-bg lazyload">`;
imageContainer.innerHTML = `<img data-src="${imageProxyURL}" id="thumbnail-image" alt="${siteTitle} Thumbnail" class="thumbnail-image lazyload masonry-item">`;
cardbg.innerHTML = `<div class=noise></div><img data-src="${imageProxyURL}" alt="${siteTitle} Thumbnail" class="card-bg lazyload">`;

}

Expand Down
4 changes: 2 additions & 2 deletions src/scripts/modal.js
Original file line number Diff line number Diff line change
Expand Up @@ -14,9 +14,9 @@ async function showReaderView(url) {

const html = await response.text();
console.log("response", html);
const pure = DOMPurify.sanitize(html);
// const pure = DOMPurify.sanitize(html);
const parser = new DOMParser();
const doc = parser.parseFromString(pure, "text/html");
const doc = parser.parseFromString(html, "text/html");
const reader = new Readability(doc);
article = reader.parse();
const item = findItemFromUrl(getFeedItems(), url);
Expand Down
8 changes: 8 additions & 0 deletions src/styles.css
Original file line number Diff line number Diff line change
Expand Up @@ -116,6 +116,7 @@ body {
z-index: -2;
filter: brightness(.7);
background-repeat: no-repeat;
object-fit: cover;
background-size: cover;
transition: all .1s linear
}
Expand Down Expand Up @@ -674,6 +675,13 @@ body {
position: relative;
border-radius: 7px
}

cite {
display:block;
text-align: center;
opacity:.7;
font-size: .9rem;
}
.reader-view-modal hr.solid {
border-top: 1px solid #bbb
}
Expand Down

0 comments on commit ea96a84

Please sign in to comment.