From f158367eb2ca052c5ef980e1c7c26508aac12fe3 Mon Sep 17 00:00:00 2001 From: Jaydip Sanghani <91427591+jellydeck@users.noreply.github.com> Date: Thu, 30 Oct 2025 22:22:03 +0530 Subject: [PATCH] chore: fixed QR code image, cleanup of unused imports --- src/components/editor/Navbar.tsx | 211 +++++++++++++++++++------------ 1 file changed, 130 insertions(+), 81 deletions(-) diff --git a/src/components/editor/Navbar.tsx b/src/components/editor/Navbar.tsx index 8175385..5243744 100644 --- a/src/components/editor/Navbar.tsx +++ b/src/components/editor/Navbar.tsx @@ -1,10 +1,15 @@ -import { useState } from 'react'; -import { Button } from '@/components/ui/button'; -import { Slider } from '@/components/ui/slider'; -import { Card, CardContent, CardHeader } from '@/components/ui/card'; -import { Dialog, DialogContent, DialogTrigger, DialogHeader, DialogTitle } from '@/components/ui/dialog'; -import { Badge } from '@/components/ui/badge'; -import { ToggleGroup, ToggleGroupItem } from '@/components/ui/toggle-group'; +import { useState } from "react"; +import { Button } from "@/components/ui/button"; +import { Card, CardContent, CardHeader } from "@/components/ui/card"; +import { + Dialog, + DialogContent, + DialogTrigger, + DialogHeader, + DialogTitle, +} from "@/components/ui/dialog"; +import { ToggleGroup, ToggleGroupItem } from "@/components/ui/toggle-group"; +import upiQR from "/assets/upiQR.png"; import { Download, ChevronDown, @@ -16,29 +21,34 @@ import { Twitter, X, CheckCircle, - Github -} from 'lucide-react'; -import { toast } from 'sonner'; -import { useMockupStore } from '@/contexts/MockupContext'; -import html2canvas from 'html2canvas'; + Github, +} from "lucide-react"; +import { toast } from "sonner"; +import { useMockupStore } from "@/contexts/MockupContext"; +import html2canvas from "html2canvas"; export function Navbar() { const [showExportOptions, setShowExportOptions] = useState(false); - const [exportFormat, setExportFormat] = useState('PNG'); + const [exportFormat, setExportFormat] = useState("PNG"); const [quality, setQuality] = useState([2]); const [isExporting, setIsExporting] = useState(false); const [isDialogOpen, setIsDialogOpen] = useState(false); const { uploadedImage, imageBorder, fixedMargin, margin } = useMockupStore(); - const isMobile = typeof window !== 'undefined' ? window.innerWidth < 768 : false; + const isMobile = + typeof window !== "undefined" ? window.innerWidth < 768 : false; const getQualityLabel = (value) => { switch (value) { - case 1: return 'Standard (1x)'; - case 2: return 'High (2x)'; - case 3: return 'Ultra (3x)'; - default: return `${value}x`; + case 1: + return "Standard (1x)"; + case 2: + return "High (2x)"; + case 3: + return "Ultra (3x)"; + default: + return `${value}x`; } }; @@ -46,11 +56,13 @@ export function Navbar() { if (!uploadedImage) return; try { - const mockupElement = document.querySelector('[data-mockup-canvas]') as HTMLDivElement; - if (!mockupElement) throw new Error('Mockup canvas not found'); + const mockupElement = document.querySelector( + "[data-mockup-canvas]", + ) as HTMLDivElement; + if (!mockupElement) throw new Error("Mockup canvas not found"); - const imgElement = mockupElement.querySelector('img') as HTMLImageElement; - if (!imgElement) throw new Error('Image element not found'); + const imgElement = mockupElement.querySelector("img") as HTMLImageElement; + if (!imgElement) throw new Error("Image element not found"); // For fixed margin mode: capture the entire canvas (image + background margins) const canvas = await html2canvas(mockupElement, { @@ -62,13 +74,13 @@ export function Navbar() { }); const mimeType = `image/${format.toLowerCase()}`; - const imageQuality = format === 'JPEG' ? 1 : undefined; + const imageQuality = format === "JPEG" ? 1 : undefined; canvas.toBlob( (blob) => { if (blob) { const url = URL.createObjectURL(blob); - const a = document.createElement('a'); + const a = document.createElement("a"); a.href = url; a.download = `mockup-${Date.now()}.${format.toLowerCase()}`; document.body.appendChild(a); @@ -76,23 +88,21 @@ export function Navbar() { document.body.removeChild(a); URL.revokeObjectURL(url); } else { - throw new Error('Failed to create blob'); + throw new Error("Failed to create blob"); } }, mimeType, - imageQuality + imageQuality, ); - - } catch (error) { - console.error('Export error:', error); + console.error("Export error:", error); throw error; } }; const handleSingleExport = async () => { if (!uploadedImage) { - toast.error('Please upload an image first'); + toast.error("Please upload an image first"); return; } @@ -100,10 +110,10 @@ export function Navbar() { try { await exportImage(exportFormat, quality[0]); toast.success(`Successfully exported as ${exportFormat}!`, { - icon: + icon: , }); } catch (error) { - toast.error('Failed to export image. Please try again.'); + toast.error("Failed to export image. Please try again."); } finally { setIsExporting(false); } @@ -111,38 +121,40 @@ export function Navbar() { const handleAllFormatsExport = async () => { if (!uploadedImage) { - toast.error('Please upload an image first'); + toast.error("Please upload an image first"); return; } setIsExporting(true); - const formats = ['PNG', 'JPEG', 'WebP']; + const formats = ["PNG", "JPEG", "WebP"]; const qualityMultiplier = quality[0]; try { await Promise.all( - formats.map(format => exportImage(format, qualityMultiplier)) + formats.map((format) => exportImage(format, qualityMultiplier)), ); - toast.success(`Successfully exported all formats (${formats.join(', ')})!`, { - icon: - }); + toast.success( + `Successfully exported all formats (${formats.join(", ")})!`, + { + icon: , + }, + ); } catch (error) { - console.error('Export all formats error:', error); - toast.error('Failed to export some formats. Please try again.'); + console.error("Export all formats error:", error); + toast.error("Failed to export some formats. Please try again."); } finally { setIsExporting(false); } }; const ExportOptionsContent = () => ( -
-
+
+

@@ -158,7 +170,7 @@ export function Navbar() { onValueChange={(value) => value && setExportFormat(value)} className="flex gap-1 bg-sidebar/80 rounded-full ring-2 ring-secondary p-1" > - {['PNG', 'JPEG', 'WebP'].map((format) => ( + {["PNG", "JPEG", "WebP"].map((format) => ( {isExporting ? ( @@ -240,18 +252,22 @@ export function Navbar() {

-
- +
@@ -271,21 +287,18 @@ export function Navbar() {

-

+

moocup is a simple offline tool.

-

+

focus on your craft, we'll take care of rest.

-

+

you can show your support by sponsoring my work!