Skip to content

Commit

Permalink
create self profile image loading
Browse files Browse the repository at this point in the history
  • Loading branch information
r-southworth committed Aug 29, 2024
1 parent 7f7e06a commit 25515e8
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 1 deletion.
9 changes: 8 additions & 1 deletion src/components/members/CreatorProfileView.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -71,11 +71,11 @@ export const CreatorProfileView: Component = () => {
});

onMount(() => {
console.log("Mount running");
setSession(User.session);
if (typeof session() === "undefined") {
alert(t("messages.signIn"));
}
lazyLoadAllImages();
});

createEffect(() => {
Expand All @@ -85,6 +85,10 @@ export const CreatorProfileView: Component = () => {
}
});

createEffect(() => {
console.log("creatorImage value:", creatorImage());
});

const resetPassword = () => {
window.location.href = `/${lang}/password/reset`;
};
Expand Down Expand Up @@ -266,6 +270,9 @@ export const CreatorProfileView: Component = () => {
);
if (imageUrls) {
setCreatorImage(imageUrls);

console.log(creatorImage());
lazyLoadAllImages();
}
}
}
Expand Down
6 changes: 6 additions & 0 deletions src/lib/imageHelper.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,9 @@ export const downloadUserImage = async (path: string) => {
};

export const lazyLoadImage = (img: HTMLImageElement) => {
console.log("Lazy loading image:", img);
const dataSrc = img.dataset.src;
console.log("Data set:", img.dataset);
// Check if the image src is already set to data-src
if (dataSrc && img.src !== dataSrc) {
console.log("Original src:", img.src);
Expand Down Expand Up @@ -96,10 +98,14 @@ export const lazyLoadImage = (img: HTMLImageElement) => {
};

export const lazyLoadAllImages = () => {
console.log("Lazy loading all images...");
const images = document.querySelectorAll("img[data-src]");
console.log("Images:", images);
console.log("Images length:", images.length);

images.forEach((img) => {
const imageElement = img as HTMLImageElement;
console.log("Image:", imageElement);

// Check if the image has already loaded (in case of caching)
if (imageElement.complete) {
Expand Down

0 comments on commit 25515e8

Please sign in to comment.