feat(web): add ProgressCard to non-AI tool settings (Group A)

Replace Loader2 spinner buttons with ProgressCard in all 13 non-AI tool
settings components that use useToolProcessor. Each now shows upload
progress, elapsed time, and processing phase during operations.
This commit is contained in:
Siddharth Kumar Sah
2026-03-23 01:45:58 +08:00
parent 60945fd3b3
commit 5c64b306ea
13 changed files with 272 additions and 130 deletions
@@ -1,11 +1,12 @@
import { useState } from "react"; import { useState } from "react";
import { useFileStore } from "@/stores/file-store"; import { useFileStore } from "@/stores/file-store";
import { useToolProcessor } from "@/hooks/use-tool-processor"; import { useToolProcessor } from "@/hooks/use-tool-processor";
import { Download, Loader2 } from "lucide-react"; import { Download } from "lucide-react";
import { ProgressCard } from "@/components/common/progress-card";
export function BorderSettings() { export function BorderSettings() {
const { files } = useFileStore(); const { files } = useFileStore();
const { processFiles, processing, error, downloadUrl, originalSize, processedSize } = const { processFiles, processing, error, downloadUrl, originalSize, processedSize, progress } =
useToolProcessor("border"); useToolProcessor("border");
const [borderWidth, setBorderWidth] = useState(10); const [borderWidth, setBorderWidth] = useState(10);
@@ -68,14 +69,24 @@ export function BorderSettings() {
</div> </div>
)} )}
<button {processing ? (
onClick={handleProcess} <ProgressCard
disabled={!hasFile || processing} active={processing}
className="w-full py-2.5 rounded-lg bg-primary text-primary-foreground font-medium disabled:opacity-50 disabled:cursor-not-allowed flex items-center justify-center gap-2" phase={progress.phase === "idle" ? "uploading" : progress.phase}
> label="Adding border"
{processing && <Loader2 className="h-4 w-4 animate-spin" />} stage={progress.stage}
{processing ? "Processing..." : "Apply Border"} percent={progress.percent}
</button> elapsed={progress.elapsed}
/>
) : (
<button
onClick={handleProcess}
disabled={!hasFile || processing}
className="w-full py-2.5 rounded-lg bg-primary text-primary-foreground font-medium disabled:opacity-50 disabled:cursor-not-allowed flex items-center justify-center gap-2"
>
Add Border
</button>
)}
{downloadUrl && ( {downloadUrl && (
<a href={downloadUrl} download className="w-full py-2.5 rounded-lg border border-primary text-primary font-medium flex items-center justify-center gap-2 hover:bg-primary/5"> <a href={downloadUrl} download className="w-full py-2.5 rounded-lg border border-primary text-primary font-medium flex items-center justify-center gap-2 hover:bg-primary/5">
@@ -1,7 +1,8 @@
import { useState } from "react"; import { useState } from "react";
import { useFileStore } from "@/stores/file-store"; import { useFileStore } from "@/stores/file-store";
import { useToolProcessor } from "@/hooks/use-tool-processor"; import { useToolProcessor } from "@/hooks/use-tool-processor";
import { Download, Loader2 } from "lucide-react"; import { Download } from "lucide-react";
import { ProgressCard } from "@/components/common/progress-card";
type Tab = "basic" | "channels" | "effects"; type Tab = "basic" | "channels" | "effects";
type Effect = "none" | "grayscale" | "sepia" | "invert"; type Effect = "none" | "grayscale" | "sepia" | "invert";
@@ -13,7 +14,7 @@ interface ColorSettingsProps {
export function ColorSettings({ toolId }: ColorSettingsProps) { export function ColorSettings({ toolId }: ColorSettingsProps) {
const { files } = useFileStore(); const { files } = useFileStore();
const { processFiles, processing, error, downloadUrl, originalSize, processedSize } = const { processFiles, processing, error, downloadUrl, originalSize, processedSize, progress } =
useToolProcessor(toolId); useToolProcessor(toolId);
const [tab, setTab] = useState<Tab>(() => { const [tab, setTab] = useState<Tab>(() => {
@@ -199,14 +200,24 @@ export function ColorSettings({ toolId }: ColorSettingsProps) {
)} )}
{/* Process */} {/* Process */}
<button {processing ? (
type="submit" <ProgressCard
disabled={!hasFile || !hasChanges || processing} active={processing}
className="w-full py-2.5 rounded-lg bg-primary text-primary-foreground font-medium disabled:opacity-50 disabled:cursor-not-allowed flex items-center justify-center gap-2" phase={progress.phase === "idle" ? "uploading" : progress.phase}
> label="Adjusting colors"
{processing && <Loader2 className="h-4 w-4 animate-spin" />} stage={progress.stage}
{processing ? "Processing..." : "Apply Adjustments"} percent={progress.percent}
</button> elapsed={progress.elapsed}
/>
) : (
<button
type="submit"
disabled={!hasFile || !hasChanges || processing}
className="w-full py-2.5 rounded-lg bg-primary text-primary-foreground font-medium disabled:opacity-50 disabled:cursor-not-allowed flex items-center justify-center gap-2"
>
Apply
</button>
)}
{/* Download */} {/* Download */}
{downloadUrl && ( {downloadUrl && (
@@ -1,13 +1,14 @@
import { useState } from "react"; import { useState } from "react";
import { useFileStore } from "@/stores/file-store"; import { useFileStore } from "@/stores/file-store";
import { useToolProcessor } from "@/hooks/use-tool-processor"; import { useToolProcessor } from "@/hooks/use-tool-processor";
import { Download, Loader2 } from "lucide-react"; import { Download } from "lucide-react";
import { ProgressCard } from "@/components/common/progress-card";
type CompressMode = "quality" | "targetSize"; type CompressMode = "quality" | "targetSize";
export function CompressSettings() { export function CompressSettings() {
const { files } = useFileStore(); const { files } = useFileStore();
const { processFiles, processing, error, downloadUrl, originalSize, processedSize } = const { processFiles, processing, error, downloadUrl, originalSize, processedSize, progress } =
useToolProcessor("compress"); useToolProcessor("compress");
const [mode, setMode] = useState<CompressMode>("quality"); const [mode, setMode] = useState<CompressMode>("quality");
@@ -108,14 +109,24 @@ export function CompressSettings() {
)} )}
{/* Process */} {/* Process */}
<button {processing ? (
type="submit" <ProgressCard
disabled={!hasFile || !canProcess || processing} active={processing}
className="w-full py-2.5 rounded-lg bg-primary text-primary-foreground font-medium disabled:opacity-50 disabled:cursor-not-allowed flex items-center justify-center gap-2" phase={progress.phase === "idle" ? "uploading" : progress.phase}
> label="Compressing"
{processing && <Loader2 className="h-4 w-4 animate-spin" />} stage={progress.stage}
{processing ? "Compressing..." : "Compress"} percent={progress.percent}
</button> elapsed={progress.elapsed}
/>
) : (
<button
type="submit"
disabled={!hasFile || !canProcess || processing}
className="w-full py-2.5 rounded-lg bg-primary text-primary-foreground font-medium disabled:opacity-50 disabled:cursor-not-allowed flex items-center justify-center gap-2"
>
Compress
</button>
)}
{/* Download */} {/* Download */}
{downloadUrl && ( {downloadUrl && (
@@ -1,14 +1,15 @@
import { useState } from "react"; import { useState } from "react";
import { useFileStore } from "@/stores/file-store"; import { useFileStore } from "@/stores/file-store";
import { useToolProcessor } from "@/hooks/use-tool-processor"; import { useToolProcessor } from "@/hooks/use-tool-processor";
import { Download, Loader2 } from "lucide-react"; import { Download } from "lucide-react";
import { ProgressCard } from "@/components/common/progress-card";
const OUTPUT_FORMATS = ["jpg", "png", "webp", "avif", "tiff", "gif"] as const; const OUTPUT_FORMATS = ["jpg", "png", "webp", "avif", "tiff", "gif"] as const;
const LOSSY_FORMATS = new Set(["jpg", "webp", "avif"]); const LOSSY_FORMATS = new Set(["jpg", "webp", "avif"]);
export function ConvertSettings() { export function ConvertSettings() {
const { files } = useFileStore(); const { files } = useFileStore();
const { processFiles, processing, error, downloadUrl, originalSize, processedSize } = const { processFiles, processing, error, downloadUrl, originalSize, processedSize, progress } =
useToolProcessor("convert"); useToolProcessor("convert");
const [format, setFormat] = useState<string>("png"); const [format, setFormat] = useState<string>("png");
@@ -102,14 +103,24 @@ export function ConvertSettings() {
)} )}
{/* Process */} {/* Process */}
<button {processing ? (
type="submit" <ProgressCard
disabled={!hasFile || processing} active={processing}
className="w-full py-2.5 rounded-lg bg-primary text-primary-foreground font-medium disabled:opacity-50 disabled:cursor-not-allowed flex items-center justify-center gap-2" phase={progress.phase === "idle" ? "uploading" : progress.phase}
> label="Converting"
{processing && <Loader2 className="h-4 w-4 animate-spin" />} stage={progress.stage}
{processing ? "Converting..." : `Convert to ${format.toUpperCase()}`} percent={progress.percent}
</button> elapsed={progress.elapsed}
/>
) : (
<button
type="submit"
disabled={!hasFile || processing}
className="w-full py-2.5 rounded-lg bg-primary text-primary-foreground font-medium disabled:opacity-50 disabled:cursor-not-allowed flex items-center justify-center gap-2"
>
Convert
</button>
)}
{/* Download */} {/* Download */}
{downloadUrl && ( {downloadUrl && (
+21 -10
View File
@@ -1,7 +1,8 @@
import { useState } from "react"; import { useState } from "react";
import { useFileStore } from "@/stores/file-store"; import { useFileStore } from "@/stores/file-store";
import { useToolProcessor } from "@/hooks/use-tool-processor"; import { useToolProcessor } from "@/hooks/use-tool-processor";
import { Download, Loader2 } from "lucide-react"; import { Download } from "lucide-react";
import { ProgressCard } from "@/components/common/progress-card";
const ASPECT_PRESETS = [ const ASPECT_PRESETS = [
{ label: "1:1", w: 1, h: 1 }, { label: "1:1", w: 1, h: 1 },
@@ -13,7 +14,7 @@ const ASPECT_PRESETS = [
export function CropSettings() { export function CropSettings() {
const { files } = useFileStore(); const { files } = useFileStore();
const { processFiles, processing, error, downloadUrl, originalSize, processedSize } = const { processFiles, processing, error, downloadUrl, originalSize, processedSize, progress } =
useToolProcessor("crop"); useToolProcessor("crop");
const [left, setLeft] = useState("0"); const [left, setLeft] = useState("0");
@@ -125,14 +126,24 @@ export function CropSettings() {
)} )}
{/* Process */} {/* Process */}
<button {processing ? (
type="submit" <ProgressCard
disabled={!hasFile || !hasSize || processing} active={processing}
className="w-full py-2.5 rounded-lg bg-primary text-primary-foreground font-medium disabled:opacity-50 disabled:cursor-not-allowed flex items-center justify-center gap-2" phase={progress.phase === "idle" ? "uploading" : progress.phase}
> label="Cropping"
{processing && <Loader2 className="h-4 w-4 animate-spin" />} stage={progress.stage}
{processing ? "Processing..." : "Crop"} percent={progress.percent}
</button> elapsed={progress.elapsed}
/>
) : (
<button
type="submit"
disabled={!hasFile || !hasSize || processing}
className="w-full py-2.5 rounded-lg bg-primary text-primary-foreground font-medium disabled:opacity-50 disabled:cursor-not-allowed flex items-center justify-center gap-2"
>
Crop
</button>
)}
{/* Download */} {/* Download */}
{downloadUrl && ( {downloadUrl && (
@@ -1,11 +1,12 @@
import { useState } from "react"; import { useState } from "react";
import { useFileStore } from "@/stores/file-store"; import { useFileStore } from "@/stores/file-store";
import { useToolProcessor } from "@/hooks/use-tool-processor"; import { useToolProcessor } from "@/hooks/use-tool-processor";
import { Download, Loader2 } from "lucide-react"; import { Download } from "lucide-react";
import { ProgressCard } from "@/components/common/progress-card";
export function GifToolsSettings() { export function GifToolsSettings() {
const { files } = useFileStore(); const { files } = useFileStore();
const { processFiles, processing, error, downloadUrl, originalSize, processedSize } = const { processFiles, processing, error, downloadUrl, originalSize, processedSize, progress } =
useToolProcessor("gif-tools"); useToolProcessor("gif-tools");
const [mode, setMode] = useState<"resize" | "extract">("resize"); const [mode, setMode] = useState<"resize" | "extract">("resize");
@@ -86,14 +87,24 @@ export function GifToolsSettings() {
</div> </div>
)} )}
<button {processing ? (
onClick={handleProcess} <ProgressCard
disabled={!hasFile || processing} active={processing}
className="w-full py-2.5 rounded-lg bg-primary text-primary-foreground font-medium disabled:opacity-50 disabled:cursor-not-allowed flex items-center justify-center gap-2" phase={progress.phase === "idle" ? "uploading" : progress.phase}
> label="Processing GIF"
{processing && <Loader2 className="h-4 w-4 animate-spin" />} stage={progress.stage}
{processing ? "Processing..." : "Process GIF"} percent={progress.percent}
</button> elapsed={progress.elapsed}
/>
) : (
<button
onClick={handleProcess}
disabled={!hasFile || processing}
className="w-full py-2.5 rounded-lg bg-primary text-primary-foreground font-medium disabled:opacity-50 disabled:cursor-not-allowed flex items-center justify-center gap-2"
>
Process
</button>
)}
{downloadUrl && ( {downloadUrl && (
<a href={downloadUrl} download className="w-full py-2.5 rounded-lg border border-primary text-primary font-medium flex items-center justify-center gap-2 hover:bg-primary/5"> <a href={downloadUrl} download className="w-full py-2.5 rounded-lg border border-primary text-primary font-medium flex items-center justify-center gap-2 hover:bg-primary/5">
@@ -1,11 +1,12 @@
import { useState } from "react"; import { useState } from "react";
import { useFileStore } from "@/stores/file-store"; import { useFileStore } from "@/stores/file-store";
import { useToolProcessor } from "@/hooks/use-tool-processor"; import { useToolProcessor } from "@/hooks/use-tool-processor";
import { Download, Loader2 } from "lucide-react"; import { Download } from "lucide-react";
import { ProgressCard } from "@/components/common/progress-card";
export function ReplaceColorSettings() { export function ReplaceColorSettings() {
const { files } = useFileStore(); const { files } = useFileStore();
const { processFiles, processing, error, downloadUrl, originalSize, processedSize } = const { processFiles, processing, error, downloadUrl, originalSize, processedSize, progress } =
useToolProcessor("replace-color"); useToolProcessor("replace-color");
const [sourceColor, setSourceColor] = useState("#FF0000"); const [sourceColor, setSourceColor] = useState("#FF0000");
@@ -65,14 +66,24 @@ export function ReplaceColorSettings() {
</div> </div>
)} )}
<button {processing ? (
onClick={handleProcess} <ProgressCard
disabled={!hasFile || processing} active={processing}
className="w-full py-2.5 rounded-lg bg-primary text-primary-foreground font-medium disabled:opacity-50 disabled:cursor-not-allowed flex items-center justify-center gap-2" phase={progress.phase === "idle" ? "uploading" : progress.phase}
> label="Replacing color"
{processing && <Loader2 className="h-4 w-4 animate-spin" />} stage={progress.stage}
{processing ? "Processing..." : "Replace Color"} percent={progress.percent}
</button> elapsed={progress.elapsed}
/>
) : (
<button
onClick={handleProcess}
disabled={!hasFile || processing}
className="w-full py-2.5 rounded-lg bg-primary text-primary-foreground font-medium disabled:opacity-50 disabled:cursor-not-allowed flex items-center justify-center gap-2"
>
Replace Color
</button>
)}
{downloadUrl && ( {downloadUrl && (
<a href={downloadUrl} download className="w-full py-2.5 rounded-lg border border-primary text-primary font-medium flex items-center justify-center gap-2 hover:bg-primary/5"> <a href={downloadUrl} download className="w-full py-2.5 rounded-lg border border-primary text-primary font-medium flex items-center justify-center gap-2 hover:bg-primary/5">
@@ -2,13 +2,14 @@ import { useState } from "react";
import { SOCIAL_MEDIA_PRESETS } from "@stirling-image/shared"; import { SOCIAL_MEDIA_PRESETS } from "@stirling-image/shared";
import { useFileStore } from "@/stores/file-store"; import { useFileStore } from "@/stores/file-store";
import { useToolProcessor } from "@/hooks/use-tool-processor"; import { useToolProcessor } from "@/hooks/use-tool-processor";
import { Download, Link, Unlink, Loader2 } from "lucide-react"; import { Download, Link, Unlink } from "lucide-react";
import { ProgressCard } from "@/components/common/progress-card";
type FitMode = "contain" | "cover" | "fill" | "inside" | "outside"; type FitMode = "contain" | "cover" | "fill" | "inside" | "outside";
export function ResizeSettings() { export function ResizeSettings() {
const { files } = useFileStore(); const { files } = useFileStore();
const { processFiles, processing, error, downloadUrl, originalSize, processedSize } = const { processFiles, processing, error, downloadUrl, originalSize, processedSize, progress } =
useToolProcessor("resize"); useToolProcessor("resize");
const [mode, setMode] = useState<"pixels" | "percentage">("pixels"); const [mode, setMode] = useState<"pixels" | "percentage">("pixels");
@@ -187,14 +188,24 @@ export function ResizeSettings() {
)} )}
{/* Process button */} {/* Process button */}
<button {processing ? (
type="submit" <ProgressCard
disabled={!hasFile || processing} active={processing}
className="w-full py-2.5 rounded-lg bg-primary text-primary-foreground font-medium disabled:opacity-50 disabled:cursor-not-allowed flex items-center justify-center gap-2" phase={progress.phase === "idle" ? "uploading" : progress.phase}
> label="Resizing"
{processing && <Loader2 className="h-4 w-4 animate-spin" />} stage={progress.stage}
{processing ? "Processing..." : "Resize"} percent={progress.percent}
</button> elapsed={progress.elapsed}
/>
) : (
<button
type="submit"
disabled={!hasFile || processing}
className="w-full py-2.5 rounded-lg bg-primary text-primary-foreground font-medium disabled:opacity-50 disabled:cursor-not-allowed flex items-center justify-center gap-2"
>
Resize
</button>
)}
{/* Download */} {/* Download */}
{downloadUrl && ( {downloadUrl && (
@@ -3,16 +3,16 @@ import { useFileStore } from "@/stores/file-store";
import { useToolProcessor } from "@/hooks/use-tool-processor"; import { useToolProcessor } from "@/hooks/use-tool-processor";
import { import {
Download, Download,
Loader2,
RotateCcw, RotateCcw,
RotateCw, RotateCw,
FlipHorizontal, FlipHorizontal,
FlipVertical, FlipVertical,
} from "lucide-react"; } from "lucide-react";
import { ProgressCard } from "@/components/common/progress-card";
export function RotateSettings() { export function RotateSettings() {
const { files } = useFileStore(); const { files } = useFileStore();
const { processFiles, processing, error, downloadUrl, originalSize, processedSize } = const { processFiles, processing, error, downloadUrl, originalSize, processedSize, progress } =
useToolProcessor("rotate"); useToolProcessor("rotate");
const [angle, setAngle] = useState(0); const [angle, setAngle] = useState(0);
@@ -122,14 +122,24 @@ export function RotateSettings() {
)} )}
{/* Process */} {/* Process */}
<button {processing ? (
type="submit" <ProgressCard
disabled={!hasFile || !hasChanges || processing} active={processing}
className="w-full py-2.5 rounded-lg bg-primary text-primary-foreground font-medium disabled:opacity-50 disabled:cursor-not-allowed flex items-center justify-center gap-2" phase={progress.phase === "idle" ? "uploading" : progress.phase}
> label="Rotating"
{processing && <Loader2 className="h-4 w-4 animate-spin" />} stage={progress.stage}
{processing ? "Processing..." : "Rotate / Flip"} percent={progress.percent}
</button> elapsed={progress.elapsed}
/>
) : (
<button
type="submit"
disabled={!hasFile || !hasChanges || processing}
className="w-full py-2.5 rounded-lg bg-primary text-primary-foreground font-medium disabled:opacity-50 disabled:cursor-not-allowed flex items-center justify-center gap-2"
>
Rotate
</button>
)}
{/* Download */} {/* Download */}
{downloadUrl && ( {downloadUrl && (
@@ -1,7 +1,8 @@
import { useState } from "react"; import { useState } from "react";
import { useFileStore } from "@/stores/file-store"; import { useFileStore } from "@/stores/file-store";
import { useToolProcessor } from "@/hooks/use-tool-processor"; import { useToolProcessor } from "@/hooks/use-tool-processor";
import { Download, Loader2 } from "lucide-react"; import { Download } from "lucide-react";
import { ProgressCard } from "@/components/common/progress-card";
const ASPECT_PRESETS = [ const ASPECT_PRESETS = [
{ label: "1:1 Square", w: 1080, h: 1080 }, { label: "1:1 Square", w: 1080, h: 1080 },
@@ -14,7 +15,7 @@ const ASPECT_PRESETS = [
export function SmartCropSettings() { export function SmartCropSettings() {
const { files } = useFileStore(); const { files } = useFileStore();
const { processFiles, processing, error, downloadUrl, originalSize, processedSize } = const { processFiles, processing, error, downloadUrl, originalSize, processedSize, progress } =
useToolProcessor("smart-crop"); useToolProcessor("smart-crop");
const [width, setWidth] = useState("1080"); const [width, setWidth] = useState("1080");
@@ -106,14 +107,24 @@ export function SmartCropSettings() {
)} )}
{/* Process button */} {/* Process button */}
<button {processing ? (
onClick={handleProcess} <ProgressCard
disabled={!hasFile || !canProcess || processing} active={processing}
className="w-full py-2.5 rounded-lg bg-primary text-primary-foreground font-medium disabled:opacity-50 disabled:cursor-not-allowed flex items-center justify-center gap-2" phase={progress.phase === "idle" ? "uploading" : progress.phase}
> label="Smart cropping"
{processing && <Loader2 className="h-4 w-4 animate-spin" />} stage={progress.stage}
{processing ? "Smart Cropping..." : "Smart Crop"} percent={progress.percent}
</button> elapsed={progress.elapsed}
/>
) : (
<button
onClick={handleProcess}
disabled={!hasFile || !canProcess || processing}
className="w-full py-2.5 rounded-lg bg-primary text-primary-foreground font-medium disabled:opacity-50 disabled:cursor-not-allowed flex items-center justify-center gap-2"
>
Smart Crop
</button>
)}
{/* Download */} {/* Download */}
{downloadUrl && ( {downloadUrl && (
@@ -1,11 +1,12 @@
import { useState } from "react"; import { useState } from "react";
import { useFileStore } from "@/stores/file-store"; import { useFileStore } from "@/stores/file-store";
import { useToolProcessor } from "@/hooks/use-tool-processor"; import { useToolProcessor } from "@/hooks/use-tool-processor";
import { Download, Loader2 } from "lucide-react"; import { Download } from "lucide-react";
import { ProgressCard } from "@/components/common/progress-card";
export function StripMetadataSettings() { export function StripMetadataSettings() {
const { files } = useFileStore(); const { files } = useFileStore();
const { processFiles, processing, error, downloadUrl, originalSize, processedSize } = const { processFiles, processing, error, downloadUrl, originalSize, processedSize, progress } =
useToolProcessor("strip-metadata"); useToolProcessor("strip-metadata");
const [stripAll, setStripAll] = useState(true); const [stripAll, setStripAll] = useState(true);
@@ -112,14 +113,24 @@ export function StripMetadataSettings() {
)} )}
{/* Process */} {/* Process */}
<button {processing ? (
type="submit" <ProgressCard
disabled={!hasFile || processing} active={processing}
className="w-full py-2.5 rounded-lg bg-primary text-primary-foreground font-medium disabled:opacity-50 disabled:cursor-not-allowed flex items-center justify-center gap-2" phase={progress.phase === "idle" ? "uploading" : progress.phase}
> label="Stripping metadata"
{processing && <Loader2 className="h-4 w-4 animate-spin" />} stage={progress.stage}
{processing ? "Processing..." : "Strip Metadata"} percent={progress.percent}
</button> elapsed={progress.elapsed}
/>
) : (
<button
type="submit"
disabled={!hasFile || processing}
className="w-full py-2.5 rounded-lg bg-primary text-primary-foreground font-medium disabled:opacity-50 disabled:cursor-not-allowed flex items-center justify-center gap-2"
>
Strip Metadata
</button>
)}
{/* Download */} {/* Download */}
{downloadUrl && ( {downloadUrl && (
@@ -1,11 +1,12 @@
import { useState } from "react"; import { useState } from "react";
import { useFileStore } from "@/stores/file-store"; import { useFileStore } from "@/stores/file-store";
import { useToolProcessor } from "@/hooks/use-tool-processor"; import { useToolProcessor } from "@/hooks/use-tool-processor";
import { Download, Loader2 } from "lucide-react"; import { Download } from "lucide-react";
import { ProgressCard } from "@/components/common/progress-card";
export function TextOverlaySettings() { export function TextOverlaySettings() {
const { files } = useFileStore(); const { files } = useFileStore();
const { processFiles, processing, error, downloadUrl, originalSize, processedSize } = const { processFiles, processing, error, downloadUrl, originalSize, processedSize, progress } =
useToolProcessor("text-overlay"); useToolProcessor("text-overlay");
const [text, setText] = useState("Your Text Here"); const [text, setText] = useState("Your Text Here");
@@ -86,14 +87,24 @@ export function TextOverlaySettings() {
</div> </div>
)} )}
<button {processing ? (
onClick={handleProcess} <ProgressCard
disabled={!hasFile || processing || !text} active={processing}
className="w-full py-2.5 rounded-lg bg-primary text-primary-foreground font-medium disabled:opacity-50 disabled:cursor-not-allowed flex items-center justify-center gap-2" phase={progress.phase === "idle" ? "uploading" : progress.phase}
> label="Adding text"
{processing && <Loader2 className="h-4 w-4 animate-spin" />} stage={progress.stage}
{processing ? "Processing..." : "Add Text"} percent={progress.percent}
</button> elapsed={progress.elapsed}
/>
) : (
<button
onClick={handleProcess}
disabled={!hasFile || processing || !text}
className="w-full py-2.5 rounded-lg bg-primary text-primary-foreground font-medium disabled:opacity-50 disabled:cursor-not-allowed flex items-center justify-center gap-2"
>
Add Text
</button>
)}
{downloadUrl && ( {downloadUrl && (
<a href={downloadUrl} download className="w-full py-2.5 rounded-lg border border-primary text-primary font-medium flex items-center justify-center gap-2 hover:bg-primary/5"> <a href={downloadUrl} download className="w-full py-2.5 rounded-lg border border-primary text-primary font-medium flex items-center justify-center gap-2 hover:bg-primary/5">
@@ -1,13 +1,14 @@
import { useState } from "react"; import { useState } from "react";
import { useFileStore } from "@/stores/file-store"; import { useFileStore } from "@/stores/file-store";
import { useToolProcessor } from "@/hooks/use-tool-processor"; import { useToolProcessor } from "@/hooks/use-tool-processor";
import { Download, Loader2 } from "lucide-react"; import { Download } from "lucide-react";
import { ProgressCard } from "@/components/common/progress-card";
type Position = "center" | "top-left" | "top-right" | "bottom-left" | "bottom-right" | "tiled"; type Position = "center" | "top-left" | "top-right" | "bottom-left" | "bottom-right" | "tiled";
export function WatermarkTextSettings() { export function WatermarkTextSettings() {
const { files } = useFileStore(); const { files } = useFileStore();
const { processFiles, processing, error, downloadUrl, originalSize, processedSize } = const { processFiles, processing, error, downloadUrl, originalSize, processedSize, progress } =
useToolProcessor("watermark-text"); useToolProcessor("watermark-text");
const [text, setText] = useState("Sample Watermark"); const [text, setText] = useState("Sample Watermark");
@@ -90,14 +91,24 @@ export function WatermarkTextSettings() {
</div> </div>
)} )}
<button {processing ? (
onClick={handleProcess} <ProgressCard
disabled={!hasFile || processing || !text} active={processing}
className="w-full py-2.5 rounded-lg bg-primary text-primary-foreground font-medium disabled:opacity-50 disabled:cursor-not-allowed flex items-center justify-center gap-2" phase={progress.phase === "idle" ? "uploading" : progress.phase}
> label="Adding watermark"
{processing && <Loader2 className="h-4 w-4 animate-spin" />} stage={progress.stage}
{processing ? "Processing..." : "Add Watermark"} percent={progress.percent}
</button> elapsed={progress.elapsed}
/>
) : (
<button
onClick={handleProcess}
disabled={!hasFile || processing || !text}
className="w-full py-2.5 rounded-lg bg-primary text-primary-foreground font-medium disabled:opacity-50 disabled:cursor-not-allowed flex items-center justify-center gap-2"
>
Add Watermark
</button>
)}
{downloadUrl && ( {downloadUrl && (
<a href={downloadUrl} download className="w-full py-2.5 rounded-lg border border-primary text-primary font-medium flex items-center justify-center gap-2 hover:bg-primary/5"> <a href={downloadUrl} download className="w-full py-2.5 rounded-lg border border-primary text-primary font-medium flex items-center justify-center gap-2 hover:bg-primary/5">