mirror of
https://github.com/arsvendg/Stirling-PDF.git
synced 2026-07-16 11:23:10 +02:00
Add frontend autoformatting and set CI to require formatted code for all languages (#6052)
# Description of Changes Changes the strategy for autoformatting to reject PRs if they are not formatted correctly instead of allowing them to merge and then spawning a new PR to fix the formatting. The old strategy just caused more work for us because we'd have to manually approve the followup PR and get it merged, which required 2 reviewers so in practice it rarely got done and just meant everyone's PRs ended up containing reformatting for unrelated files, which makes code review unnecessarily difficult. If the PR's code is not formatted correctly after this PR, a comment will be added automatically to tell the author how to run the formatter script to fix their code so it can go in. This also enables autoformatting for the frontend code, using Prettier. I've enabled it for pretty much everything in the frontend folder, other than 3rd party files and files it doesn't make sense for. I also excluded Markdown because it sounds likely to be more annoying to have to autoformat the Markdown in the frontend folder but nowhere else. Open to changing this though if people disagree. > [!note] > > Advice to reviewers: The first commit contains all of the actual logic I've introduced (CI changes, Prettier config, etc.) > The second commit is just the reformatting of the entire frontend folder. > The first commit needs proper review, the second one just give it a spot-check that it's doing what you'd expect.
This commit is contained in:
@@ -1,26 +1,26 @@
|
||||
import React from 'react';
|
||||
import { Box, Center } from '@mantine/core';
|
||||
import InsertDriveFileIcon from '@mui/icons-material/InsertDriveFile';
|
||||
import { StirlingFileStub } from '@app/types/fileContext';
|
||||
import DocumentThumbnail from '@app/components/shared/filePreview/DocumentThumbnail';
|
||||
import DocumentStack from '@app/components/shared/filePreview/DocumentStack';
|
||||
import HoverOverlay from '@app/components/shared/filePreview/HoverOverlay';
|
||||
import NavigationArrows from '@app/components/shared/filePreview/NavigationArrows';
|
||||
import React from "react";
|
||||
import { Box, Center } from "@mantine/core";
|
||||
import InsertDriveFileIcon from "@mui/icons-material/InsertDriveFile";
|
||||
import { StirlingFileStub } from "@app/types/fileContext";
|
||||
import DocumentThumbnail from "@app/components/shared/filePreview/DocumentThumbnail";
|
||||
import DocumentStack from "@app/components/shared/filePreview/DocumentStack";
|
||||
import HoverOverlay from "@app/components/shared/filePreview/HoverOverlay";
|
||||
import NavigationArrows from "@app/components/shared/filePreview/NavigationArrows";
|
||||
|
||||
export interface FilePreviewProps {
|
||||
// Core file data
|
||||
file: File | StirlingFileStub | null;
|
||||
thumbnail?: string | null;
|
||||
|
||||
|
||||
// Optional features
|
||||
showStacking?: boolean;
|
||||
showHoverOverlay?: boolean;
|
||||
showNavigation?: boolean;
|
||||
|
||||
|
||||
// State
|
||||
totalFiles?: number;
|
||||
isAnimating?: boolean;
|
||||
|
||||
|
||||
// Event handlers
|
||||
onFileClick?: (file: File | StirlingFileStub | null) => void;
|
||||
onPrevious?: () => void;
|
||||
@@ -37,41 +37,38 @@ const FilePreview: React.FC<FilePreviewProps> = ({
|
||||
isAnimating = false,
|
||||
onFileClick,
|
||||
onPrevious,
|
||||
onNext
|
||||
onNext,
|
||||
}) => {
|
||||
if (!file) {
|
||||
return (
|
||||
<Box style={{ width: '100%', height: '100%' }}>
|
||||
<Center style={{ width: '100%', height: '100%' }}>
|
||||
<InsertDriveFileIcon
|
||||
style={{
|
||||
fontSize: '4rem',
|
||||
color: 'var(--mantine-color-gray-4)',
|
||||
opacity: 0.6
|
||||
}}
|
||||
<Box style={{ width: "100%", height: "100%" }}>
|
||||
<Center style={{ width: "100%", height: "100%" }}>
|
||||
<InsertDriveFileIcon
|
||||
style={{
|
||||
fontSize: "4rem",
|
||||
color: "var(--mantine-color-gray-4)",
|
||||
opacity: 0.6,
|
||||
}}
|
||||
/>
|
||||
</Center>
|
||||
</Box>
|
||||
);
|
||||
}
|
||||
|
||||
|
||||
const hasMultipleFiles = totalFiles > 1;
|
||||
|
||||
|
||||
// Animation styles
|
||||
const animationStyle = isAnimating ? {
|
||||
transition: 'all 0.3s cubic-bezier(0.4, 0, 0.2, 1)',
|
||||
transform: 'scale(0.95) translateX(1.25rem)',
|
||||
opacity: 0.7
|
||||
} : {};
|
||||
const animationStyle = isAnimating
|
||||
? {
|
||||
transition: "all 0.3s cubic-bezier(0.4, 0, 0.2, 1)",
|
||||
transform: "scale(0.95) translateX(1.25rem)",
|
||||
opacity: 0.7,
|
||||
}
|
||||
: {};
|
||||
|
||||
// Build the component composition
|
||||
let content = (
|
||||
<DocumentThumbnail
|
||||
file={file}
|
||||
thumbnail={thumbnail}
|
||||
style={animationStyle}
|
||||
onClick={() => onFileClick?.(file)}
|
||||
/>
|
||||
<DocumentThumbnail file={file} thumbnail={thumbnail} style={animationStyle} onClick={() => onFileClick?.(file)} />
|
||||
);
|
||||
|
||||
// Wrap with hover overlay if needed
|
||||
@@ -81,31 +78,19 @@ const FilePreview: React.FC<FilePreviewProps> = ({
|
||||
|
||||
// Wrap with document stack if needed
|
||||
if (showStacking) {
|
||||
content = (
|
||||
<DocumentStack totalFiles={totalFiles}>
|
||||
{content}
|
||||
</DocumentStack>
|
||||
);
|
||||
content = <DocumentStack totalFiles={totalFiles}>{content}</DocumentStack>;
|
||||
}
|
||||
|
||||
// Wrap with navigation if needed
|
||||
if (showNavigation && hasMultipleFiles && onPrevious && onNext) {
|
||||
content = (
|
||||
<NavigationArrows
|
||||
onPrevious={onPrevious}
|
||||
onNext={onNext}
|
||||
disabled={isAnimating}
|
||||
>
|
||||
<NavigationArrows onPrevious={onPrevious} onNext={onNext} disabled={isAnimating}>
|
||||
{content}
|
||||
</NavigationArrows>
|
||||
);
|
||||
}
|
||||
|
||||
return (
|
||||
<Box style={{ width: '100%', height: '100%' }}>
|
||||
{content}
|
||||
</Box>
|
||||
);
|
||||
return <Box style={{ width: "100%", height: "100%" }}>{content}</Box>;
|
||||
};
|
||||
|
||||
export default FilePreview;
|
||||
export default FilePreview;
|
||||
|
||||
Reference in New Issue
Block a user