mirror of
https://github.com/Stirling-Tools/Stirling-PDF.git
synced 2025-09-18 09:29:24 +00:00
Fix thumbnail rendering
This commit is contained in:
parent
a1d0ceef14
commit
9952842a40
@ -1,4 +1,4 @@
|
|||||||
import React, { useMemo } from "react";
|
import React, { useMemo, useState, useEffect } from "react";
|
||||||
import { Stack, Text, Box, ActionIcon, Group, Center } from "@mantine/core";
|
import { Stack, Text, Box, ActionIcon, Group, Center } from "@mantine/core";
|
||||||
import { useTranslation } from "react-i18next";
|
import { useTranslation } from "react-i18next";
|
||||||
import RotateLeftIcon from "@mui/icons-material/RotateLeft";
|
import RotateLeftIcon from "@mui/icons-material/RotateLeft";
|
||||||
@ -24,21 +24,29 @@ const RotateSettings = ({ parameters, disabled = false }: RotateSettingsProps) =
|
|||||||
}, [selectedFiles]);
|
}, [selectedFiles]);
|
||||||
|
|
||||||
// Get thumbnail for the selected file
|
// Get thumbnail for the selected file
|
||||||
const thumbnail = useMemo(() => {
|
const [thumbnail, setThumbnail] = useState<string | null>(null);
|
||||||
if (!selectedFile) return null;
|
|
||||||
|
useEffect(() => {
|
||||||
|
if (!selectedFile) {
|
||||||
|
setThumbnail(null);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
const pageId = `${selectedFile.fileId}-1`;
|
const pageId = `${selectedFile.fileId}-1`;
|
||||||
|
|
||||||
// Try to get cached thumbnail first
|
// Try to get cached thumbnail first
|
||||||
const cached = getThumbnailFromCache(pageId);
|
const cached = getThumbnailFromCache(pageId);
|
||||||
if (cached) return cached;
|
if (cached) {
|
||||||
|
setThumbnail(cached);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
// Request thumbnail if not cached
|
// Request thumbnail if not cached
|
||||||
requestThumbnail(pageId, selectedFile, 1).then(() => {
|
requestThumbnail(pageId, selectedFile, 1).then((result) => {
|
||||||
// Component will re-render when thumbnail is available
|
setThumbnail(result);
|
||||||
|
}).catch(() => {
|
||||||
|
setThumbnail(null);
|
||||||
});
|
});
|
||||||
|
|
||||||
return null;
|
|
||||||
}, [selectedFile, getThumbnailFromCache, requestThumbnail]);
|
}, [selectedFile, getThumbnailFromCache, requestThumbnail]);
|
||||||
|
|
||||||
// Calculate current angle display
|
// Calculate current angle display
|
||||||
|
Loading…
x
Reference in New Issue
Block a user