Skip to content

#1 PDF Application on GitHub that lets you edit PDFs on any device anywhere

2.2 KB
Raw Blame
import { useTranslation } from "react-i18next";
import { createToolFlow } from "@editor/components/tools/shared/createToolFlow";
import { BaseToolProps, ToolComponent } from "@editor/types/tool";
import { useBaseTool } from "@editor/hooks/tools/shared/useBaseTool";
import { useRemoveBlanksParameters } from "@editor/hooks/tools/removeBlanks/useRemoveBlanksParameters";
import { useRemoveBlanksOperation } from "@editor/hooks/tools/removeBlanks/useRemoveBlanksOperation";
import RemoveBlanksSettings from "@editor/components/tools/removeBlanks/RemoveBlanksSettings";
import { useRemoveBlanksTips } from "@editor/components/tooltips/useRemoveBlanksTips";

const RemoveBlanks = (props: BaseToolProps) => {
  const { t } = useTranslation();
  const tooltipContent = useRemoveBlanksTips();

  const base = useBaseTool(
    "remove-blanks",
    useRemoveBlanksParameters,
    useRemoveBlanksOperation,
    props,
  );

  const settingsContent = (
    <RemoveBlanksSettings
      parameters={base.params.parameters}
      onParameterChange={base.params.updateParameter}
      disabled={base.endpointLoading}
    />
  );

  const handleSettingsClick = () => {
    if (base.hasResults) {
      base.handleSettingsReset();
    }
  };

  return createToolFlow({
    files: {
      selectedFiles: base.selectedFiles,
      isCollapsed: base.hasResults,
    },
    steps: [
      {
        title: t("removeBlanks.settings.title", "Settings"),
        isCollapsed: base.settingsCollapsed,
        onCollapsedClick: handleSettingsClick,
        content: settingsContent,
        tooltip: tooltipContent,
      },
    ],
    executeButton: {
      text: t("removeBlanks.submit", "Remove blank pages"),
      loadingText: t("loading"),
      onClick: base.handleExecute,
      isVisible: !base.hasResults,
      endpointEnabled: base.endpointEnabled,
      paramsValid: base.params.validateParameters(),
    },
    review: {
      isVisible: base.hasResults,
      operation: base.operation,
      title: t("removeBlanks.results.title", "Removed Blank Pages"),
      onFileClick: base.handleThumbnailClick,
      onUndo: base.handleUndo,
    },
  });
};

RemoveBlanks.tool = () => useRemoveBlanksOperation;

export default RemoveBlanks as ToolComponent;