From 3deaf12878389af8ed85174e1bfee28c5a0c10b2 Mon Sep 17 00:00:00 2001 From: Aaron Liu Date: Tue, 20 May 2025 11:57:46 +0800 Subject: [PATCH] fix: cannot enter folder in gallery view (https://github.com/cloudreve/Cloudreve/issues/2375) --- .../FileManager/Explorer/Explorer.tsx | 1 + .../Explorer/GalleryView/GalleryImage.tsx | 70 ++++++------------- .../Explorer/GalleryView/GalleryView.tsx | 36 +++------- 3 files changed, 32 insertions(+), 75 deletions(-) diff --git a/src/component/FileManager/Explorer/Explorer.tsx b/src/component/FileManager/Explorer/Explorer.tsx index 4a5df60..36d9f88 100644 --- a/src/component/FileManager/Explorer/Explorer.tsx +++ b/src/component/FileManager/Explorer/Explorer.tsx @@ -41,6 +41,7 @@ export interface FileBlockProps { index?: number; search?: SearchParam; columns?: ListViewColumn[]; + boxHeight?: number; } const Explorer = () => { diff --git a/src/component/FileManager/Explorer/GalleryView/GalleryImage.tsx b/src/component/FileManager/Explorer/GalleryView/GalleryImage.tsx index 57bc53b..7a87a4f 100644 --- a/src/component/FileManager/Explorer/GalleryView/GalleryImage.tsx +++ b/src/component/FileManager/Explorer/GalleryView/GalleryImage.tsx @@ -1,6 +1,14 @@ -import { FileBlockProps } from "../Explorer.tsx"; +import { CheckCircle } from "@mui/icons-material"; +import { Box, Fade, IconButton, ImageListItem, ImageListItemBar, lighten, styled } from "@mui/material"; import React, { memo, useCallback, useEffect, useState } from "react"; +import { TransitionGroup } from "react-transition-group"; +import { FileType, Metadata } from "../../../../api/explorer.ts"; import { useAppDispatch } from "../../../../redux/hooks.ts"; +import { fileIconClicked, loadFileThumb } from "../../../../redux/thunks/file.ts"; +import { navigateReconcile } from "../../../../redux/thunks/filemanager.ts"; +import CheckUnchecked from "../../../Icons/CheckUnchecked.tsx"; +import { FileBlockProps } from "../Explorer.tsx"; +import FileIcon from "../FileIcon.tsx"; import { LargeIconContainer, ThumbBox, @@ -8,25 +16,6 @@ import { ThumbLoadingPlaceholder, useFileBlockState, } from "../GridView/GridFile.tsx"; -import { navigateReconcile } from "../../../../redux/thunks/filemanager.ts"; -import { - Box, - Fade, - IconButton, - ImageListItem, - ImageListItemBar, - lighten, - styled, -} from "@mui/material"; -import { - fileIconClicked, - loadFileThumb, -} from "../../../../redux/thunks/file.ts"; -import FileIcon from "../FileIcon.tsx"; -import { TransitionGroup } from "react-transition-group"; -import { FileType, Metadata } from "../../../../api/explorer.ts"; -import CheckUnchecked from "../../../Icons/CheckUnchecked.tsx"; -import { CheckCircle } from "@mui/icons-material"; const StyledImageListItem = styled(ImageListItem)<{ transparent?: boolean; @@ -38,12 +27,7 @@ const StyledImageListItem = styled(ImageListItem)<{ pointerEvents: disabled ? "none" : "auto", cursor: "pointer", boxShadow: isDropOver ? `0 0 0 2px ${theme.palette.primary.light}` : "none", - transition: theme.transitions.create([ - "height", - "width", - "opacity", - "box-shadow", - ]), + transition: theme.transitions.create(["height", "width", "opacity", "box-shadow"]), }; }); @@ -74,9 +58,7 @@ const GalleryImage = memo((props: FileBlockProps) => { const [hovered, setHovered] = useState(false); // undefined: not loaded, null: no thumb - const [thumbSrc, setThumbSrc] = useState( - noThumb ? null : undefined, - ); + const [thumbSrc, setThumbSrc] = useState(noThumb ? null : undefined); const [imageLoading, setImageLoading] = useState(true); const tryLoadThumbSrc = useCallback(async () => { @@ -105,10 +87,7 @@ const GalleryImage = memo((props: FileBlockProps) => { return; } - if ( - (file.metadata && file.metadata[Metadata.thumbDisabled] !== undefined) || - showLock - ) { + if ((file.metadata && file.metadata[Metadata.thumbDisabled] !== undefined) || showLock) { // No thumb available setThumbSrc(null); return; @@ -127,7 +106,7 @@ const GalleryImage = memo((props: FileBlockProps) => { return ( { - isSelected - ? lighten(theme.palette.primary.light, 0.85) - : "initial", + backgroundColor: (theme) => (isSelected ? lighten(theme.palette.primary.light, 0.85) : "initial"), transition: (theme) => theme.transitions.create(["padding"], { duration: theme.transitions.duration.shortest, @@ -182,12 +158,12 @@ const GalleryImage = memo((props: FileBlockProps) => { { + state.fileManager[fmIndex].list?.files, - ); - const pagination = useAppSelector( - (state) => state.fileManager[fmIndex].list?.pagination, - ); - const search_params = useAppSelector( - (state) => state.fileManager[fmIndex]?.search_params, - ); - const galleryWidth = useAppSelector( - (state) => state.fileManager[fmIndex].galleryWidth, - ); + const files = useAppSelector((state) => state.fileManager[fmIndex].list?.files); + const pagination = useAppSelector((state) => state.fileManager[fmIndex].list?.pagination); + const search_params = useAppSelector((state) => state.fileManager[fmIndex]?.search_params); + const galleryWidth = useAppSelector((state) => state.fileManager[fmIndex].galleryWidth); const mergedRef = useCallback( (val: any) => { @@ -79,6 +64,7 @@ const GalleryView = React.forwardRef( const resizeGallery = useCallback( (containerWidth: number, boxSize: number) => { + console.log(containerWidth / boxSize); const boxCount = Math.floor(containerWidth / boxSize); const newCols = Math.max(1, boxCount); const boxHeight = containerWidth / newCols; @@ -99,12 +85,11 @@ const GalleryView = React.forwardRef( }, [galleryWidth]); return ( - + (