Added config controller to be used by react frontend

This commit is contained in:
Connor Yoh
2025-06-27 18:00:35 +01:00
parent 62fb5025a9
commit 248a14c571
10 changed files with 618 additions and 13 deletions
+21 -2
View File
@@ -1,9 +1,9 @@
import React, { useState } from "react";
import { useSearchParams } from "react-router-dom";
import { useTranslation } from "react-i18next";
import { Stack, Slider, Group, Text, Button, Checkbox, TextInput, Paper } from "@mantine/core";
import { Stack, Slider, Group, Text, Button, Checkbox, TextInput, Loader, Alert } from "@mantine/core";
import { FileWithUrl } from "../types/file";
import { fileStorage } from "../services/fileStorage";
import { useEndpointEnabled } from "../hooks/useEndpointConfig";
export interface CompressProps {
files?: FileWithUrl[];
@@ -36,6 +36,7 @@ const CompressPdfPanel: React.FC<CompressProps> = ({
const [selected, setSelected] = useState<boolean[]>(files.map(() => false));
const [localLoading, setLocalLoading] = useState<boolean>(false);
const { enabled: endpointEnabled, loading: endpointLoading } = useEndpointEnabled("compress-pdf");
const {
compressionLevel,
@@ -99,6 +100,24 @@ const CompressPdfPanel: React.FC<CompressProps> = ({
}
};
if (endpointLoading) {
return (
<Stack align="center" justify="center" h={200}>
<Loader size="md" />
<Text size="sm" c="dimmed">{t("loading", "Loading...")}</Text>
</Stack>
);
}
if (endpointEnabled === false) {
return (
<Stack align="center" justify="center" h={200}>
<Alert color="red" title={t("error._value", "Error")} variant="light">
{t("endpointDisabled", "This feature is currently disabled.")}
</Alert>
</Stack>
);
}
return (
<Stack>
+21 -1
View File
@@ -4,6 +4,7 @@ import { useSearchParams } from "react-router-dom";
import { useTranslation } from "react-i18next";
import { FileWithUrl } from "../types/file";
import { fileStorage } from "../services/fileStorage";
import { useEndpointEnabled } from "../hooks/useEndpointConfig";
export interface MergePdfPanelProps {
files: FileWithUrl[];
@@ -22,11 +23,11 @@ const MergePdfPanel: React.FC<MergePdfPanelProps> = ({
updateParams,
}) => {
const { t } = useTranslation();
const [searchParams] = useSearchParams();
const [selectedFiles, setSelectedFiles] = useState<boolean[]>([]);
const [downloadUrl, setLocalDownloadUrl] = useState<string | null>(null);
const [isLoading, setIsLoading] = useState(false);
const [errorMessage, setErrorMessage] = useState<string | null>(null);
const { enabled: endpointEnabled, loading: endpointLoading } = useEndpointEnabled("merge-pdfs");
useEffect(() => {
setSelectedFiles(files.map(() => true));
@@ -92,6 +93,25 @@ const MergePdfPanel: React.FC<MergePdfPanelProps> = ({
const { order, removeDuplicates } = params;
if (endpointLoading) {
return (
<Stack align="center" justify="center" h={200}>
<Loader size="md" />
<Text size="sm" c="dimmed">{t("loading", "Loading...")}</Text>
</Stack>
);
}
if (endpointEnabled === false) {
return (
<Stack align="center" justify="center" h={200}>
<Alert color="red" title={t("error._value", "Error")} variant="light">
{t("endpointDisabled", "This feature is currently disabled.")}
</Alert>
</Stack>
);
}
return (
<Stack>
<Text fw={500} size="lg">{t("merge.header")}</Text>
+41 -1
View File
@@ -7,13 +7,16 @@ import {
Checkbox,
Notification,
Stack,
Paper,
Loader,
Alert,
Text,
} from "@mantine/core";
import { useSearchParams } from "react-router-dom";
import { useTranslation } from "react-i18next";
import DownloadIcon from "@mui/icons-material/Download";
import { FileWithUrl } from "../types/file";
import { fileStorage } from "../services/fileStorage";
import { useEndpointEnabled } from "../hooks/useEndpointConfig";
export interface SplitPdfPanelProps {
file: { file: FileWithUrl; url: string } | null;
@@ -48,6 +51,23 @@ const SplitPdfPanel: React.FC<SplitPdfPanelProps> = ({
const [isLoading, setIsLoading] = useState(false);
const [errorMessage, setErrorMessage] = useState<string | null>(null);
// Map mode to endpoint name for checking
const getEndpointName = (mode: string) => {
switch (mode) {
case "byPages":
return "split-pages";
case "bySections":
return "split-pdf-by-sections";
case "bySizeOrCount":
return "split-by-size-or-count";
case "byChapters":
return "split-pdf-by-chapters";
default:
return "split-pages";
}
};
const {
mode,
pages,
@@ -62,6 +82,7 @@ const SplitPdfPanel: React.FC<SplitPdfPanelProps> = ({
} = params;
const { enabled: endpointEnabled, loading: endpointLoading } = useEndpointEnabled(getEndpointName(mode));
const handleSubmit = async (e: React.FormEvent) => {
e.preventDefault();
if (!file) {
@@ -142,6 +163,25 @@ const SplitPdfPanel: React.FC<SplitPdfPanelProps> = ({
}
};
if (endpointLoading) {
return (
<Stack align="center" justify="center" h={200}>
<Loader size="md" />
<Text size="sm" c="dimmed">{t("loading", "Loading...")}</Text>
</Stack>
);
}
if (endpointEnabled === false) {
return (
<Stack align="center" justify="center" h={200}>
<Alert color="red" title={t("error._value", "Error")} variant="light">
{t("endpointDisabled", "This feature is currently disabled.")}
</Alert>
</Stack>
);
}
return (
<form onSubmit={handleSubmit} className="app-surface p-app-md rounded-app-md">
<Stack gap="sm" mb={16}>