From 81dec53488183bd6514aef3217532d51392d1c5b Mon Sep 17 00:00:00 2001 From: Ludy Date: Mon, 27 Oct 2025 17:40:43 +0100 Subject: [PATCH] style(frontend): remove redundant React imports in TypeScript components (#4738) # Description of Changes This pull request removes unnecessary imports of the default React object from multiple frontend files. The changes help clean up the codebase by only importing specific React hooks where needed, rather than importing the entire React object. **Code cleanup and import optimization:** * Removed default `React` imports from component files, retaining only the necessary React hooks (such as `useEffect`, `useState`, `useMemo`, etc.) in files like `FileEditor.tsx`, `FullscreenToolList.tsx`, `ToolPanel.tsx`, `PageNumberPreview.tsx`, `AdjustContrastPreview.tsx`, `AutomationRun.tsx`, `LocalEmbedPDFWithAnnotations.tsx`, `ToolRegistryProvider.tsx`, `useTranslatedToolRegistry.tsx`, and `AdjustContrast.tsx`. [[1]](diffhunk://#diff-481d0a2d8a1714d34d21181db63a020b08dfccfbfa80bf47ac9af382dff25310L1-R1) [[2]](diffhunk://#diff-1d6e9507cb0744e03ec0e80c510874bfc5054986b0275ae3b8592eb67b5ec0f2L1-R1) [[3]](diffhunk://#diff-8ee3da71652291722dc6130f44565c098fe0f9cdf5e8ec0ba3c631be8980b13eL1-R1) [[4]](diffhunk://#diff-ecc12bf9b557e947ae2f1866d07446b19bad1fbdf143bf231dd3076b1e794826L1-R1) [[5]](diffhunk://#diff-6ba4ca6f491368b62e160639e97207f5c1d35fee77f4eebd39133630e0ecb7a1L1-R1) [[6]](diffhunk://#diff-ff7cba3dba3b1f4ec4c8758a9fbe539351f96225284d0c61cca2642ec7a8e486L1-R1) [[7]](diffhunk://#diff-d99cf54aa50d266c08844fac31c79e73a7f1714adeedb186d1decab8b9fb7f78L1-R1) [[8]](diffhunk://#diff-3467ae2b00d2ea95c360bc367adfbae124a4fb1d2627e889d12fb00e288bf508L1-R1) [[9]](diffhunk://#diff-0a3e636736c137356dd9354ff3cacbd302ebda40147545e13c62d073525d1969L1-R1) [[10]](diffhunk://#diff-2fed64bea41254c30dcc038f6b92943272bcaa771af200b8a3dc1a2cef6b5ca7L2-R2) * Removed default `React` imports from presentational and settings components that do not use JSX at the top level, such as `Workbench.tsx`, `SliderWithInput.tsx`, `AdjustContrastBasicSettings.tsx`, `AdjustContrastColorSettings.tsx`, `AdjustContrastSingleStepSettings.tsx`, `FileSummaryHeader.tsx`, `SignatureSection.tsx`, `SignatureStatusBadge.tsx`, and `ThumbnailPreview.tsx`. [[1]](diffhunk://#diff-6ffa9f7048b8e2a454ccf52b712179784cf32d42ecac9c85331c595a4cee39b4L1) [[2]](diffhunk://#diff-a1159e58f6668bc6de9595b4014fd7b8e0a19f9efa75294ba80184cfe54b601fL1) [[3]](diffhunk://#diff-ce5bbd748c15bc456e7f01180b7ff04c80c782e3d6662384f28e032af36ed3ccL1) [[4]](diffhunk://#diff-494006ec5e237eb7b3a16b9bc144a6ed49ed38c547d95b68a89f69a5af6676ceL1) [[5]](diffhunk://#diff-e61a3e2d98c9601eea868062258b925e6f6d672f49df14e3684b12f736622db4L1) [[6]](diffhunk://#diff-97df8b451114e347bb3f581ff5c91057601fb821e224479e1106493ce9479dcdL1) [[7]](diffhunk://#diff-cc070bfc4dc892a4e9a2be725c9f27ab66bdbc821a525fad10e14b27096d4e5aL1) [[8]](diffhunk://#diff-c179df2634412e4938bcd686f86b3bdbd1a6039d8a8b62c44fd0c085cc58af74L1) [[9]](diffhunk://#diff-64403230a8c8e90135bd8d7cd275c40d8e22bd3a22ed642dec5451018eec3c10L1) These changes reduce unnecessary imports and make the codebase cleaner and more consistent. --- ## Checklist ### General - [ ] I have read the [Contribution Guidelines](https://github.com/Stirling-Tools/Stirling-PDF/blob/main/CONTRIBUTING.md) - [ ] I have read the [Stirling-PDF Developer Guide](https://github.com/Stirling-Tools/Stirling-PDF/blob/main/devGuide/DeveloperGuide.md) (if applicable) - [ ] I have read the [How to add new languages to Stirling-PDF](https://github.com/Stirling-Tools/Stirling-PDF/blob/main/devGuide/HowToAddNewLanguage.md) (if applicable) - [ ] I have performed a self-review of my own code - [ ] My changes generate no new warnings ### Documentation - [ ] I have updated relevant docs on [Stirling-PDF's doc repo](https://github.com/Stirling-Tools/Stirling-Tools.github.io/blob/main/docs/) (if functionality has heavily changed) - [ ] I have read the section [Add New Translation Tags](https://github.com/Stirling-Tools/Stirling-PDF/blob/main/devGuide/HowToAddNewLanguage.md#add-new-translation-tags) (for new translation tags only) ### UI Changes (if applicable) - [ ] Screenshots or videos demonstrating the UI changes are attached (e.g., as comments or direct attachments in the PR) ### Testing (if applicable) - [ ] I have tested my changes locally. Refer to the [Testing Guide](https://github.com/Stirling-Tools/Stirling-PDF/blob/main/devGuide/DeveloperGuide.md#6-testing) for more details. Co-authored-by: ConnorYoh <40631091+ConnorYoh@users.noreply.github.com> --- frontend/src/components/fileEditor/FileEditor.tsx | 2 +- frontend/src/components/layout/Workbench.tsx | 1 - .../components/shared/sliderWithInput/SliderWithInput.tsx | 1 - frontend/src/components/tools/FullscreenToolList.tsx | 6 +++--- frontend/src/components/tools/ToolPanel.tsx | 2 +- .../components/tools/addPageNumbers/PageNumberPreview.tsx | 2 +- .../tools/adjustContrast/AdjustContrastBasicSettings.tsx | 1 - .../tools/adjustContrast/AdjustContrastColorSettings.tsx | 1 - .../tools/adjustContrast/AdjustContrastPreview.tsx | 2 +- .../adjustContrast/AdjustContrastSingleStepSettings.tsx | 1 - frontend/src/components/tools/automate/AutomationRun.tsx | 2 +- .../validateSignature/reportView/FileSummaryHeader.tsx | 1 - .../tools/validateSignature/reportView/SignatureSection.tsx | 1 - .../validateSignature/reportView/SignatureStatusBadge.tsx | 1 - .../tools/validateSignature/reportView/ThumbnailPreview.tsx | 1 - .../src/components/viewer/LocalEmbedPDFWithAnnotations.tsx | 4 ++-- frontend/src/contexts/ToolRegistryProvider.tsx | 2 +- frontend/src/data/useTranslatedToolRegistry.tsx | 2 +- frontend/src/tools/AdjustContrast.tsx | 2 +- 19 files changed, 13 insertions(+), 22 deletions(-) diff --git a/frontend/src/components/fileEditor/FileEditor.tsx b/frontend/src/components/fileEditor/FileEditor.tsx index 54901902c8..8d894389e9 100644 --- a/frontend/src/components/fileEditor/FileEditor.tsx +++ b/frontend/src/components/fileEditor/FileEditor.tsx @@ -1,4 +1,4 @@ -import React, { useState, useCallback, useRef, useMemo, useEffect } from 'react'; +import { useState, useCallback, useRef, useMemo, useEffect } from 'react'; import { Text, Center, Box, LoadingOverlay, Stack } from '@mantine/core'; diff --git a/frontend/src/components/layout/Workbench.tsx b/frontend/src/components/layout/Workbench.tsx index 74356b97da..4ec7d80178 100644 --- a/frontend/src/components/layout/Workbench.tsx +++ b/frontend/src/components/layout/Workbench.tsx @@ -1,4 +1,3 @@ -import React from 'react'; import { Box } from '@mantine/core'; import { useRainbowThemeContext } from '../shared/RainbowThemeProvider'; import { useToolWorkflow } from '../../contexts/ToolWorkflowContext'; diff --git a/frontend/src/components/shared/sliderWithInput/SliderWithInput.tsx b/frontend/src/components/shared/sliderWithInput/SliderWithInput.tsx index e8e504ded1..7a91cdbe39 100644 --- a/frontend/src/components/shared/sliderWithInput/SliderWithInput.tsx +++ b/frontend/src/components/shared/sliderWithInput/SliderWithInput.tsx @@ -1,4 +1,3 @@ -import React from 'react'; import { Slider, Text, Group, NumberInput } from '@mantine/core'; interface Props { diff --git a/frontend/src/components/tools/FullscreenToolList.tsx b/frontend/src/components/tools/FullscreenToolList.tsx index ce76b73751..686fdf1826 100644 --- a/frontend/src/components/tools/FullscreenToolList.tsx +++ b/frontend/src/components/tools/FullscreenToolList.tsx @@ -1,4 +1,4 @@ -import React, { useMemo } from 'react'; +import { useMemo } from 'react'; import { Text } from '@mantine/core'; import { useTranslation } from 'react-i18next'; import { ToolRegistryEntry, getSubcategoryLabel, getSubcategoryColor, getSubcategoryIcon } from '../../data/toolsTaxonomy'; @@ -104,7 +104,7 @@ const FullscreenToolList = ({ {showRecentFavorites && ( <> {favoriteToolItems.length > 0 && ( -
0 && ( -
); -} \ No newline at end of file +} diff --git a/frontend/src/contexts/ToolRegistryProvider.tsx b/frontend/src/contexts/ToolRegistryProvider.tsx index 30a0205019..e7dc7f53b5 100644 --- a/frontend/src/contexts/ToolRegistryProvider.tsx +++ b/frontend/src/contexts/ToolRegistryProvider.tsx @@ -1,4 +1,4 @@ -import React, { useMemo } from 'react'; +import { useMemo } from 'react'; import type { ToolId } from '../types/toolId'; import type { ToolRegistry } from '../data/toolsTaxonomy'; diff --git a/frontend/src/data/useTranslatedToolRegistry.tsx b/frontend/src/data/useTranslatedToolRegistry.tsx index f50b5ed55b..f3b22dcc4e 100644 --- a/frontend/src/data/useTranslatedToolRegistry.tsx +++ b/frontend/src/data/useTranslatedToolRegistry.tsx @@ -1,4 +1,4 @@ -import React, { useMemo } from "react"; +import { useMemo } from "react"; import LocalIcon from "../components/shared/LocalIcon"; import { useTranslation } from "react-i18next"; import SplitPdfPanel from "../tools/Split"; diff --git a/frontend/src/tools/AdjustContrast.tsx b/frontend/src/tools/AdjustContrast.tsx index 0de528a40a..7e92c05419 100644 --- a/frontend/src/tools/AdjustContrast.tsx +++ b/frontend/src/tools/AdjustContrast.tsx @@ -1,5 +1,5 @@ import { useTranslation } from 'react-i18next'; -import React, { useEffect, useMemo, useState } from 'react'; +import { useEffect, useMemo, useState } from 'react'; import { createToolFlow } from '../components/tools/shared/createToolFlow'; import { BaseToolProps, ToolComponent } from '../types/tool'; import { useBaseTool } from '../hooks/tools/shared/useBaseTool';