Skip to content

Commit

Permalink
Fix gallery performance (aeharding#320)
Browse files Browse the repository at this point in the history
  • Loading branch information
aeharding authored Jul 8, 2023
1 parent f946e73 commit 4134b8b
Show file tree
Hide file tree
Showing 5 changed files with 4 additions and 55 deletions.
2 changes: 1 addition & 1 deletion src/features/feed/Feed.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -173,7 +173,7 @@ export default function Feed<I>({
fetchMore();
}}
components={{ Header: header, Footer: footer }}
increaseViewportBy={5000}
increaseViewportBy={800}
/>
</>
);
Expand Down
11 changes: 0 additions & 11 deletions src/features/gallery/GalleryImg.tsx
Original file line number Diff line number Diff line change
@@ -1,7 +1,5 @@
import React, { FocusEvent, KeyboardEvent, useContext, useRef } from "react";
import "photoswipe/dist/photoswipe.css";
import { useAppDispatch } from "../../store";
import { imageLoaded } from "./gallerySlice";
import { PostView } from "lemmy-js-client";
import { GalleryContext } from "./GalleryProvider";
import { PreparedPhotoSwipeOptions } from "photoswipe";
Expand Down Expand Up @@ -31,7 +29,6 @@ export function GalleryImg({
post,
animationType,
}: GalleryImgProps) {
const dispatch = useAppDispatch();
const loaded = useRef(false);
const imgRef = useRef<HTMLImageElement>(null);
const { open } = useContext(GalleryContext);
Expand All @@ -55,14 +52,6 @@ export function GalleryImg({
if (!src) return;

loaded.current = true;

dispatch(
imageLoaded({
src,
width: e.target.naturalWidth,
height: e.target.naturalHeight,
})
);
}}
/>
);
Expand Down
10 changes: 3 additions & 7 deletions src/features/gallery/GalleryProvider.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,6 @@ import GalleryPostActions from "./GalleryPostActions";
import { createPortal } from "react-dom";
import { PostView } from "lemmy-js-client";
import PhotoSwipeLightbox, { PreparedPhotoSwipeOptions } from "photoswipe";
import { useAppSelector } from "../../store";
import { getSafeArea, isAndroid } from "../../helpers/device";

import "photoswipe/style.css";
Expand Down Expand Up @@ -52,9 +51,6 @@ interface GalleryProviderProps {
}

export default function GalleryProvider({ children }: GalleryProviderProps) {
const imageDimensionsBySrc = useAppSelector(
(state) => state.gallery.imageDimensionsBySrc
);
const [actionContainer, setActionContainer] = useState<HTMLElement | null>(
null
);
Expand Down Expand Up @@ -90,15 +86,15 @@ export default function GalleryProvider({ children }: GalleryProviderProps) {
animationType?: PreparedPhotoSwipeOptions["showHideAnimationType"]
) => {
if (lightboxRef.current) return;
if (!imageDimensionsBySrc[img.src]) return;

setPost(post);

const instance = new PhotoSwipeLightbox({
dataSource: [
{
src: img.src,
...imageDimensionsBySrc[img.src],
height: img.naturalHeight,
width: img.naturalWidth,
},
],
showHideAnimationType: animationType ?? "fade",
Expand Down Expand Up @@ -229,7 +225,7 @@ export default function GalleryProvider({ children }: GalleryProviderProps) {
instance.init();
lightboxRef.current = instance;
},
[imageDimensionsBySrc]
[]
);

return (
Expand Down
34 changes: 0 additions & 34 deletions src/features/gallery/gallerySlice.tsx

This file was deleted.

2 changes: 0 additions & 2 deletions src/store.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@ import commentSlice from "./features/comment/commentSlice";
import communitySlice from "./features/community/communitySlice";
import userSlice from "./features/user/userSlice";
import inboxSlice from "./features/inbox/inboxSlice";
import gallerySlice from "./features/gallery/gallerySlice";
import appearanceSlice, {
fetchSettingsFromDatabase,
} from "./features/settings/appearance/appearanceSlice";
Expand All @@ -20,7 +19,6 @@ const store = configureStore({
user: userSlice,
inbox: inboxSlice,
appearance: appearanceSlice,
gallery: gallerySlice,
},
});
export type RootState = ReturnType<typeof store.getState>;
Expand Down

0 comments on commit 4134b8b

Please sign in to comment.