Skip to content

Commit

Permalink
Fix build warnings (#1346)
Browse files Browse the repository at this point in the history
  • Loading branch information
aeharding authored Mar 20, 2024
1 parent c645b3b commit bdf1f06
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 11 deletions.
31 changes: 20 additions & 11 deletions src/features/media/gallery/GalleryProvider.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -12,17 +12,20 @@ import React, {
import GalleryPostActions from "./GalleryPostActions";
import { createPortal } from "react-dom";
import { PostView } from "lemmy-js-client";
import PhotoSwipeLightbox, { PreparedPhotoSwipeOptions } from "photoswipe";
import { getSafeArea, isAndroid, isNative } from "../../../helpers/device";

import "photoswipe/style.css";
import { useLocation } from "react-router";
import { StatusBar } from "@capacitor/status-bar";
import { setPostRead } from "../../post/postSlice";
import { useAppDispatch } from "../../../store";
import GalleryMedia from "./GalleryMedia";
import ImageMoreActions from "./ImageMoreActions";

import type { PreparedPhotoSwipeOptions } from "photoswipe";
import type ZoomLevel from "photoswipe/dist/types/slide/zoom-level";
import PhotoSwipeLightbox from "photoswipe/lightbox";

import "photoswipe/style.css";

interface IGalleryContext {
// used for determining whether page needs to be scrolled up first
Expand Down Expand Up @@ -71,14 +74,16 @@ export default function GalleryProvider({ children }: GalleryProviderProps) {
useEffect(() => {
if (!lightboxRef.current) return;

lightboxRef.current.close();
lightboxRef.current.pswp?.close();
}, [location.pathname]);

const close = useCallback(() => {
if (!lightboxRef.current) return;

lightboxRef.current.options.showHideAnimationType = "fade";
lightboxRef.current.close();
if (lightboxRef.current.pswp)
lightboxRef.current.pswp.options.showHideAnimationType = "fade";

lightboxRef.current.pswp?.close();
}, []);

const open = useCallback(
Expand Down Expand Up @@ -181,7 +186,7 @@ export default function GalleryProvider({ children }: GalleryProviderProps) {

instance.on("tapAction", () => {
if (currZoomLevel !== zoomLevel.min) {
instance.zoomTo(zoomLevel.min, undefined, 300);
instance.pswp?.zoomTo(zoomLevel.min, undefined, 300);
currZoomLevel = zoomLevel.min;

// queueMicrotask, otherwise will be overwritten by internal photoswipe ui toggle
Expand All @@ -203,9 +208,13 @@ export default function GalleryProvider({ children }: GalleryProviderProps) {

function onZoomChange() {
if (currZoomLevel <= zoomLevel.min) {
instance.gestures.pswp.element?.classList.add("pswp--ui-visible");
instance.pswp?.gestures.pswp.element?.classList.add(
"pswp--ui-visible",
);
} else {
instance.gestures.pswp.element?.classList.remove("pswp--ui-visible");
instance.pswp?.gestures.pswp.element?.classList.remove(
"pswp--ui-visible",
);
}
}

Expand All @@ -232,7 +241,7 @@ export default function GalleryProvider({ children }: GalleryProviderProps) {
});

instance.on("uiRegister", function () {
instance.ui?.registerElement({
instance.pswp?.ui?.registerElement({
appendTo: "root",
onInit: (el) => {
setActionContainer(el);
Expand Down Expand Up @@ -315,7 +324,7 @@ export default function GalleryProvider({ children }: GalleryProviderProps) {
}

if (instance !== null) {
instance.close();
instance.pswp?.close();
}
};

Expand All @@ -339,7 +348,7 @@ export default function GalleryProvider({ children }: GalleryProviderProps) {
// Android back button logic end
// -----------------------------

instance.init();
instance.loadAndOpen(0);
lightboxRef.current = instance;
},
[dispatch],
Expand Down
2 changes: 2 additions & 0 deletions vite.config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@ export default defineConfig({
manifestFilename: "manifest.json",
manifest,
workbox: {
maximumFileSizeToCacheInBytes: 2097152 * 2,
runtimeCaching: [
{
handler: "StaleWhileRevalidate",
Expand All @@ -48,6 +49,7 @@ export default defineConfig({
// break. This breaks iOS transitions.
// Put everything into one chunk for now.
build: {
chunkSizeWarningLimit: 5_000,
rollupOptions: {
output: {
manualChunks: () => "index.js",
Expand Down

0 comments on commit bdf1f06

Please sign in to comment.