"use client"; import { useState } from "react"; import { useAtom, useAtomValue, useSetAtom } from "jotai"; import { batchModeAtom, compressionAtom, dontShowCloudModalAtom, noImageProcessingAtom, savedOutputPathAtom, overwriteAtom, progressAtom, scaleAtom, customWidthAtom, useCustomWidthAtom, tileSizeAtom, showSidebarAtom, selectedModelIdAtom, doubleUpscaylAtom, gpuIdAtom, saveImageAsAtom, } from "../../atoms/user-settings-atom"; import useLogger from "../hooks/use-logger"; import { BatchUpscaylPayload, DoubleUpscaylPayload, ImageUpscaylPayload, } from "@common/types/types"; import { useToast } from "@/components/ui/use-toast"; import UpscaylSteps from "./upscayl-tab/upscayl-steps"; import SettingsTab from "./settings-tab"; import Footer from "../footer"; import { NewsModal } from "../news-modal"; import Tabs from "../tabs"; import Header from "../header"; import { ChevronLeftIcon } from "lucide-react"; import { logAtom } from "@/atoms/log-atom"; import { ELECTRON_COMMANDS } from "@common/electron-commands"; import useUpscaylVersion from "../hooks/use-upscayl-version"; import useTranslation from "../hooks/use-translation"; import UpscaylLogo from "./upscayl-logo"; import SidebarToggleButton from "./sidebar-button"; const Sidebar = ({ setUpscaledImagePath, batchFolderPath, setUpscaledBatchFolderPath, dimensions, imagePath, selectImageHandler, selectFolderHandler, }: { setUpscaledImagePath: React.Dispatch>; batchFolderPath: string; setUpscaledBatchFolderPath: React.Dispatch>; dimensions: { width: number | null; height: number | null; }; imagePath: string; selectImageHandler: () => Promise; selectFolderHandler: () => Promise; }) => { const t = useTranslation(); const logit = useLogger(); const { toast } = useToast(); const version = useUpscaylVersion(); // LOCAL STATES // TODO: Add electron handler for os const [selectedModelId, setSelectedModelId] = useAtom(selectedModelIdAtom); const [doubleUpscayl, setDoubleUpscayl] = useAtom(doubleUpscaylAtom); const [gpuId, setGpuId] = useAtom(gpuIdAtom); const [saveImageAs, setSaveImageAs] = useAtom(saveImageAsAtom); const [selectedTab, setSelectedTab] = useState(0); const [showCloudModal, setShowCloudModal] = useState(false); // ATOMIC STATES const overwrite = useAtomValue(overwriteAtom); const outputPath = useAtomValue(savedOutputPathAtom); const [compression, setCompression] = useAtom(compressionAtom); const setProgress = useSetAtom(progressAtom); const [batchMode, setBatchMode] = useAtom(batchModeAtom); const logData = useAtomValue(logAtom); const [scale] = useAtom(scaleAtom); const setDontShowCloudModal = useSetAtom(dontShowCloudModalAtom); const noImageProcessing = useAtomValue(noImageProcessingAtom); const customWidth = useAtomValue(customWidthAtom); const useCustomWidth = useAtomValue(useCustomWidthAtom); const tileSize = useAtomValue(tileSizeAtom); const [showSidebar, setShowSidebar] = useAtom(showSidebarAtom); const upscaylHandler = async () => { logit("🔄 Resetting Upscaled Image Path"); setUpscaledImagePath(""); setUpscaledBatchFolderPath(""); if (imagePath !== "" || batchFolderPath !== "") { setProgress(t("APP.PROGRESS.WAIT_TITLE")); // Double Upscayl if (doubleUpscayl) { window.electron.send( ELECTRON_COMMANDS.DOUBLE_UPSCAYL, { imagePath, outputPath, model: selectedModelId, gpuId: gpuId.length === 0 ? null : gpuId, saveImageAs, scale, noImageProcessing, compression: compression.toString(), customWidth: customWidth > 0 ? customWidth.toString() : null, useCustomWidth, tileSize, }, ); logit("🏁 DOUBLE_UPSCAYL"); } else if (batchMode) { // Batch Upscayl setDoubleUpscayl(false); window.electron.send( ELECTRON_COMMANDS.FOLDER_UPSCAYL, { batchFolderPath, outputPath, model: selectedModelId, gpuId: gpuId.length === 0 ? null : gpuId, saveImageAs, scale, noImageProcessing, compression: compression.toString(), customWidth: customWidth > 0 ? customWidth.toString() : null, useCustomWidth, tileSize, }, ); logit("🏁 FOLDER_UPSCAYL"); } else { // Single Image Upscayl window.electron.send(ELECTRON_COMMANDS.UPSCAYL, { imagePath, outputPath, model: selectedModelId, gpuId: gpuId.length === 0 ? null : gpuId, saveImageAs, scale, overwrite, noImageProcessing, compression: compression.toString(), customWidth: customWidth > 0 ? customWidth.toString() : null, useCustomWidth, tileSize, }); logit("🏁 UPSCAYL"); } } else { toast({ title: t("ERRORS.NO_IMAGE_ERROR.TITLE"), description: t("ERRORS.NO_IMAGE_ERROR.DESCRIPTION"), }); logit("🚫 No valid image selected"); } }; return ( <> {/* TOP LOGO WHEN SIDEBAR IS HIDDEN */} {!showSidebar && }
{window.electron.platform === "mac" && (
)}
{selectedTab === 0 && ( )} {selectedTab === 1 && ( )}
); }; export default Sidebar;