Files
Stirling-PDF/frontend/src/core/components/fileManager/CompactFileDetails.tsx
T

Ignoring revisions in .git-blame-ignore-revs. Click here to bypass and see the normal blame view.

147 lines
4.9 KiB
TypeScript
Raw Normal View History

import React from "react";
import { Stack, Box, Text, Button, ActionIcon, Center } from "@mantine/core";
import PictureAsPdfIcon from "@mui/icons-material/PictureAsPdf";
import ChevronLeftIcon from "@mui/icons-material/ChevronLeft";
import ChevronRightIcon from "@mui/icons-material/ChevronRight";
import { useTranslation } from "react-i18next";
import { getFileSize } from "@app/utils/fileUtils";
import { StirlingFileStub } from "@app/types/fileContext";
import { PrivateContent } from "@app/components/shared/PrivateContent";
2025-08-08 15:15:09 +01:00
interface CompactFileDetailsProps {
2025-09-16 15:08:11 +01:00
currentFile: StirlingFileStub | null;
2025-08-08 15:15:09 +01:00
thumbnail: string | null;
2025-09-16 15:08:11 +01:00
selectedFiles: StirlingFileStub[];
2025-08-08 15:15:09 +01:00
currentFileIndex: number;
numberOfFiles: number;
isAnimating: boolean;
onPrevious: () => void;
onNext: () => void;
onOpenFiles: () => void;
}
const CompactFileDetails: React.FC<CompactFileDetailsProps> = ({
currentFile,
thumbnail,
selectedFiles,
currentFileIndex,
numberOfFiles,
isAnimating,
onPrevious,
onNext,
onOpenFiles,
2025-08-08 15:15:09 +01:00
}) => {
const { t } = useTranslation();
const hasSelection = selectedFiles.length > 0;
const hasMultipleFiles = numberOfFiles > 1;
2026-03-25 11:00:40 +00:00
const showOwner = Boolean(
currentFile && (currentFile.remoteOwnedByCurrentUser === false || currentFile.remoteSharedViaLink),
2026-03-25 11:00:40 +00:00
);
const ownerLabel = currentFile ? currentFile.remoteOwnerUsername || t("fileManager.ownerUnknown", "Unknown") : "";
2025-08-08 15:15:09 +01:00
return (
<Stack gap="xs" style={{ height: "100%" }}>
2025-08-08 15:15:09 +01:00
{/* Compact mobile layout */}
<Box style={{ display: "flex", gap: "0.75rem", alignItems: "center" }}>
2025-08-08 15:15:09 +01:00
{/* Small preview */}
<Box
style={{
width: "7.5rem",
height: "9.375rem",
flexShrink: 0,
position: "relative",
display: "flex",
alignItems: "center",
justifyContent: "center",
}}
>
2025-08-08 15:15:09 +01:00
{currentFile && thumbnail ? (
<PrivateContent>
<img
src={thumbnail}
alt={currentFile.name}
style={{
maxWidth: "100%",
maxHeight: "100%",
objectFit: "contain",
borderRadius: "0.25rem",
boxShadow: "0 2px 4px rgba(0, 0, 0, 0.1)",
}}
/>
</PrivateContent>
2025-08-08 15:15:09 +01:00
) : currentFile ? (
<Center
style={{
width: "100%",
height: "100%",
backgroundColor: "var(--mantine-color-gray-1)",
borderRadius: 4,
}}
>
<PictureAsPdfIcon style={{ fontSize: 20, color: "var(--mantine-color-gray-6)" }} />
2025-08-08 15:15:09 +01:00
</Center>
) : null}
</Box>
2025-08-08 15:15:09 +01:00
{/* File info */}
<Box style={{ flex: 1, minWidth: 0 }}>
<Text size="sm" fw={500} truncate>
<PrivateContent>{currentFile ? currentFile.name : "No file selected"}</PrivateContent>
2025-08-08 15:15:09 +01:00
</Text>
<Text size="xs" c="dimmed">
{currentFile ? getFileSize(currentFile) : ""}
2025-08-08 15:15:09 +01:00
{selectedFiles.length > 1 && ` • ${selectedFiles.length} files`}
2025-09-16 15:08:11 +01:00
{currentFile && ` • v${currentFile.versionNumber || 1}`}
2025-08-08 15:15:09 +01:00
</Text>
{hasMultipleFiles && (
<Text size="xs" c="blue">
{currentFileIndex + 1} of {selectedFiles.length}
</Text>
)}
2025-09-16 15:08:11 +01:00
{/* Compact tool chain for mobile */}
{currentFile?.toolHistory && currentFile.toolHistory.length > 0 && (
<Text size="xs" c="dimmed">
{currentFile.toolHistory.map((tool) => t(`home.${tool.toolId}.title`, tool.toolId)).join(" → ")}
2025-09-16 15:08:11 +01:00
</Text>
)}
2026-03-25 11:00:40 +00:00
{currentFile && showOwner && (
<Text size="xs" c="dimmed">
{t("fileManager.owner", "Owner")}: {ownerLabel}
2026-03-25 11:00:40 +00:00
</Text>
)}
2025-08-08 15:15:09 +01:00
</Box>
2025-08-08 15:15:09 +01:00
{/* Navigation arrows for multiple files */}
{hasMultipleFiles && (
<Box style={{ display: "flex", gap: "0.25rem" }}>
<ActionIcon variant="subtle" size="sm" onClick={onPrevious} disabled={isAnimating}>
2025-08-08 15:15:09 +01:00
<ChevronLeftIcon style={{ fontSize: 16 }} />
</ActionIcon>
<ActionIcon variant="subtle" size="sm" onClick={onNext} disabled={isAnimating}>
2025-08-08 15:15:09 +01:00
<ChevronRightIcon style={{ fontSize: 16 }} />
</ActionIcon>
</Box>
)}
</Box>
2025-08-08 15:15:09 +01:00
{/* Action Button */}
<Button
size="sm"
2025-08-08 15:15:09 +01:00
onClick={onOpenFiles}
disabled={!hasSelection}
fullWidth
style={{
backgroundColor: hasSelection ? "var(--btn-open-file)" : "var(--mantine-color-gray-4)",
color: "white",
2025-08-08 15:15:09 +01:00
}}
>
{selectedFiles.length > 1
? t("fileManager.openFiles", `Open ${selectedFiles.length} Files`)
: t("fileManager.openFile", "Open File")}
2025-08-08 15:15:09 +01:00
</Button>
</Stack>
);
};
export default CompactFileDetails;