Skip to content

Commit

Permalink
refactor: Remove unused code and lint fix
Browse files Browse the repository at this point in the history
  • Loading branch information
Yash committed Sep 17, 2024
1 parent 573df5a commit f6f03f3
Show file tree
Hide file tree
Showing 9 changed files with 30 additions and 47 deletions.
2 changes: 1 addition & 1 deletion src/app/page.tsx
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import Editor from "@/components/editor/Editor";
import { SnapcutEditor } from "@/components/snapcut-editor";
// import { SnapcutEditor } from "@/components/snapcut-editor";

export default function Home() {
return (
Expand Down
12 changes: 6 additions & 6 deletions src/components/editor/Editor.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,7 @@ import Viewer from './Viewer';
import Toolbar from './Toolbar';
import EditorHeader from './EditorHeader';

type Props = {}

const Editor = (props: Props) => {
const Editor = () => {
const [img, setImg] = useState<string | null>(null);

const onImageChange = (e) => {
Expand All @@ -17,9 +15,11 @@ const Editor = (props: Props) => {
};

return (
<main className="min-h-full flex flex-col flex-1 bg-gradient-to-tr from-[#004d7a]/10 to-[#00bf72]/10 " style={{
// backgroundImage: "linear-gradient(to right top, #051937, #004d7a, #008793 , #00bf72, #a8eb12)"
}}>
<main className="min-h-full flex flex-col flex-1 bg-gradient-to-tr from-[#004d7a]/10 to-[#00bf72]/10 "
// style={{
// backgroundImage: "linear-gradient(to right top, #051937, #004d7a, #008793 , #00bf72, #a8eb12)"
// }}
>
<EditorHeader />
<Viewer img={img} />
<Toolbar onImageChange={onImageChange} img={img} />
Expand Down
28 changes: 3 additions & 25 deletions src/components/editor/EditorHeader.tsx
Original file line number Diff line number Diff line change
@@ -1,32 +1,10 @@
"use client"
import { useState, useEffect, useCallback } from 'react'
import {
Moon,
Sun,
Github,
Upload,
Wand2,
Layers,
Paintbrush,
Maximize2,
CornerUpLeft,
Square,
Cloud,
Share2,
Download
} from 'lucide-react'
import Image from 'next/image'
import { toast } from 'sonner'
type Props = {}

const EditorHeader = (props: Props) => {
const [darkMode, setDarkMode] = useState(false)
const [mounted, setMounted] = useState(false)
useEffect(() => {
setMounted(true)
}, [])

const toggleDarkMode = () => setDarkMode(!darkMode)
const EditorHeader = () => {
// const toggleDarkMode = () => setDarkMode(!darkMode)

return (
<header className="flex justify-between items-center p-6 transition-colors duration-300">
Expand All @@ -49,7 +27,7 @@ const EditorHeader = (props: Props) => {
href="https://github.com/YashM20/snapcut"
target="_blank"
rel="noopener noreferrer"
className="px-4 py-2 bg-gradient-to-r from-emerald-800/80 to-emerald-700 text-white rounded-full flex items-center gap-2 hover:from-purple-700 hover:to-pink-700 transition-all duration-300 shadow-lg"
className="px-4 py-2 bg-gradient-to-r hover:from-emerald-800/80 hover:to-emerald-700 text-white rounded-full flex items-center gap-2 from-emerald-950 to-emerald-900 transition-all duration-300 shadow-lg"
>
<Github className="w-5 h-5" />
GitHub
Expand Down
6 changes: 3 additions & 3 deletions src/components/editor/Toolbar.tsx
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
"use client"
import React, { useEffect } from "react";
import Background from "./tools/background/Background";
import React from "react";
import Corners from "./tools/corners/Corners";
import Padding from "./tools/padding/Padding";
import Shadow from "./tools/shadow/Shadow";
Expand All @@ -9,6 +8,7 @@ import Resize from "./tools/resize/Resize";
import useClipboardImage from "./tools/clipboard/Clipboard";
import CopyClipboard from "./tools/clipboard/CopyClipboard";
import { UploadIcon } from "@radix-ui/react-icons";
import { Upload } from "lucide-react";


export default function Toolbar({ onImageChange, img }) {
Expand All @@ -23,7 +23,7 @@ export default function Toolbar({ onImageChange, img }) {
className="transform p-4 flex font-semibold text-lg justify-center items-center px-8 rounded-full bg-gradient-to-r from-emerald-800/80 to-emerald-700 text-white/80 ease-in-out group outline-none ring dark:ring-0 ring-emerald-100/50 hover:from-emerald-950 hover:to-emerald-900 transition-all duration-300 shadow-lg"
onClick={() => document.getElementById("file_select").click()}
>
<UploadIcon className="w-6 mr-2 stroke-[2] group-hover:-rotate-3 group-active:rotate-3" />
<Upload className="w-5 mr-4 mb-1 stroke-[2] group-hover:-rotate-3 group-active:rotate-3" />
Upload Screenshot
</button>
)}
Expand Down
6 changes: 3 additions & 3 deletions src/components/editor/Viewer.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -17,12 +17,12 @@ const Viewer = ({ img }: Props) => {
setImgH(document?.getElementById("parent-img")?.offsetHeight || 0);
setImgW(document?.getElementById("parent-img")?.offsetWidth || 0);
// }
});
}, [img]);

return (
<div className="h-[80vh] min-w-full w-full flex justify-center items-center overflow-auto ">
<div className="rounded-md overflow-hidden">
<div id="my-node" className="relative max-w-[80vw] sm:h-96 p-6 flex justify-center items-center bg-slate-300/10 ">
<div className="rounded-md overflow-hidden bg-transparent/15">
<div id="my-node" className="relative max-w-[80vw] sm:h-96 p-6 flex justify-center items-center bg-transparent ">
<Draggable>
<Image
height={200}
Expand Down
6 changes: 4 additions & 2 deletions src/components/editor/tools/background/Background.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,10 @@ import { PaintBrushIcon } from "@heroicons/react/24/outline";
import { useEffect, useState } from "react";
import ClickAwayListener from "react-click-away-listener";
import Color from "./Color";
const getColors = require("get-image-colors");
var rgb2hex = require("rgb2hex");
// const getColors = require("get-image-colors");
// var rgb2hex = require("rgb2hex");
import getColors from "get-image-colors";
import rgb2hex from "rgb2hex";

export default function Background({ img }) {
const [isVisible, setIsVisible] = useState(false);
Expand Down
4 changes: 2 additions & 2 deletions src/components/editor/tools/clipboard/Clipboard.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ export default function useClipboardImage(onImageChange) {
if (clipboardItems.items[i].type.indexOf("image") === 0) {
let blob = clipboardItems.items[i].getAsFile();
let reader = new FileReader();
reader.onload = function (evt) {
reader.onload = function () {
onImageChange({ target: { files: [new File([blob], "pasted-image.png")] } });
};
reader.readAsArrayBuffer(blob);
Expand All @@ -21,5 +21,5 @@ export default function useClipboardImage(onImageChange) {
return () => {
window.removeEventListener('paste', handlePaste);
};
}, [onImageChange]);
}, [onImageChange, handlePaste]);
}
9 changes: 5 additions & 4 deletions src/components/editor/tools/clipboard/CopyClipboard.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
"use client"
import { ArrowDownTrayIcon, ClipboardIcon } from "@heroicons/react/24/outline";
import React, { useEffect } from "react";
import { ClipboardIcon } from "@heroicons/react/24/outline";
import React from "react";
import * as htmlToImage from "html-to-image";
import { useState } from "react";
import ClickAwayListener from "react-click-away-listener";
Expand All @@ -14,7 +14,8 @@ export default function CopyClipboard() {
const [isVisible, setIsVisible] = useState(false);
const [isCopyButtonDisabled, setIsCopyButtonDisabled] =
useState(false);
const [copyFormat, setCopyFormat] = useState("png"); // png by default
// const [copyFormat, setCopyFormat] = useState("png"); // png by default
const copyFormat = "png" // png by default
// Click away handle
const handleClickAway = () => {
setIsVisible(false);
Expand Down Expand Up @@ -53,7 +54,7 @@ export default function CopyClipboard() {
toast.dismiss("start");
toast.success("Copied to Clipboard Successfully!");
setIsCopyButtonDisabled(false);
}).catch((error) => {
}).catch(() => {
toast.dismiss("start");
toast.error("Failed to Copy to Clipboard!");
setIsCopyButtonDisabled(false);
Expand Down
4 changes: 3 additions & 1 deletion src/components/editor/tools/download/Download.js
Original file line number Diff line number Diff line change
Expand Up @@ -49,11 +49,13 @@ export default function Download() {
});
});
}

useEffect(() => {
if (isVisible) {
document.getElementById(downloadFormat).checked = true;
}
}, [isVisible]);
}, [isVisible, downloadFormat]);

return (
<>
<div className="flex flex-col justify-center items-center rounded-xl cursor-pointer active:scale-95 transform transition-all ease-in-out duration-200">
Expand Down

0 comments on commit f6f03f3

Please sign in to comment.