From 9e8b3628a90d6ac1b3f4194a4ae30bd05c13f318 Mon Sep 17 00:00:00 2001 From: ruru <142723369+ruru-m07@users.noreply.github.com> Date: Sun, 19 May 2024 12:23:59 +0530 Subject: [PATCH 1/2] feat(emoji): add emoji mode toggle --- action/index.ts | 396 ++++++++++++++++++++++++++++++++++++++- app/page.tsx | 19 +- components/ui/switch.tsx | 29 +++ package.json | 1 + pnpm-lock.yaml | 44 +++++ 5 files changed, 482 insertions(+), 7 deletions(-) create mode 100644 components/ui/switch.tsx diff --git a/action/index.ts b/action/index.ts index b743d5b..fdb69a0 100644 --- a/action/index.ts +++ b/action/index.ts @@ -4,8 +4,10 @@ import { model } from "@/utils"; export const commitChange = async ({ message, + isEmojiSupport, }: { message: string | null; + isEmojiSupport: boolean; }): Promise<{ data: { text: string; @@ -28,9 +30,397 @@ export const commitChange = async ({ - Suggest 3 different commit messages to give the user some options. - For example, if the user input is "I change lib folder to utils folder", then the output should be: - \`\`\`txt refactor(lib): change lib folder to utils folder \n\`\`\`\n - \`\`\`txt refactor(deps): rename lib folder to utils \n\`\`\`\n - \`\`\`txt fix(deps): rename lib folder to utils \n\`\`\`\n + ${ + isEmojiSupport && + `\ + - Use emojis in the commit message. + - fot emoji you can use this link https://gitmoji.dev/ + - For example, if the user input is "I change lib folder to utils folder", then the output should be: + \`\`\` json + "gitmojis": [ + { + "emoji": "๐ŸŽจ", + "code": ":art:", + "description": "Improve structure / format of the code." + }, + { + "emoji": "โšก๏ธ", + "code": ":zap:", + "description": "Improve performance." + }, + { + "emoji": "๐Ÿ”ฅ", + "code": ":fire:", + "description": "Remove code or files." + }, + { + "emoji": "๐Ÿ›", + "code": ":bug:", + "description": "Fix a bug." + }, + { + "emoji": "๐Ÿš‘๏ธ", + "code": ":ambulance:", + "description": "Critical hotfix." + }, + { + "emoji": "โœจ", + "code": ":sparkles:", + "description": "Introduce new features." + }, + { + "emoji": "๐Ÿ“", + "code": ":memo:", + "description": "Add or update documentation." + }, + { + "emoji": "๐Ÿš€", + "code": ":rocket:", + "description": "Deploy stuff." + }, + { + "emoji": "๐Ÿ’„", + "code": ":lipstick:", + "description": "Add or update the UI and style files." + }, + { + "emoji": "๐ŸŽ‰", + "code": ":tada:", + "description": "Begin a project." + }, + { + "emoji": "โœ…", + "code": ":white_check_mark:", + "description": "Add, update, or pass tests." + }, + { + "emoji": "๐Ÿ”’๏ธ", + "code": ":lock:", + "description": "Fix security or privacy issues." + }, + { + "emoji": "๐Ÿ”", + "code": ":closed_lock_with_key:", + "description": "Add or update secrets." + }, + { + "emoji": "๐Ÿ”–", + "code": ":bookmark:", + "description": "Release / Version tags." + }, + { + "emoji": "๐Ÿšจ", + "code": ":rotating_light:", + "description": "Fix compiler / linter warnings." + }, + { + "emoji": "๐Ÿšง", + "code": ":construction:", + "description": "Work in progress." + }, + { + "emoji": "๐Ÿ’š", + "code": ":green_heart:", + "description": "Fix CI Build." + }, + { + "emoji": "โฌ‡๏ธ", + "code": ":arrow_down:", + "description": "Downgrade dependencies." + }, + { + "emoji": "โฌ†๏ธ", + "code": ":arrow_up:", + "description": "Upgrade dependencies." + }, + { + "emoji": "๐Ÿ“Œ", + "code": ":pushpin:", + "description": "Pin dependencies to specific versions." + }, + { + "emoji": "๐Ÿ‘ท", + "code": ":construction_worker:", + "description": "Add or update CI build system." + }, + { + "emoji": "๐Ÿ“ˆ", + "code": ":chart_with_upwards_trend:", + "description": "Add or update analytics or track code." + }, + { + "emoji": "โ™ป๏ธ", + "code": ":recycle:", + "description": "Refactor code." + }, + { + "emoji": "โž•", + "code": ":heavy_plus_sign:", + "description": "Add a dependency." + }, + { + "emoji": "โž–", + "code": ":heavy_minus_sign:", + "description": "Remove a dependency." + }, + { + "emoji": "๐Ÿ”ง", + "code": ":wrench:", + "description": "Add or update configuration files." + }, + { + "emoji": "๐Ÿ”จ", + "code": ":hammer:", + "description": "Add or update development scripts." + }, + { + "emoji": "๐ŸŒ", + "code": ":globe_with_meridians:", + "description": "Internationalization and localization." + }, + { + "emoji": "โœ๏ธ", + "code": ":pencil2:", + "description": "Fix typos." + }, + { + "emoji": "๐Ÿ’ฉ", + "code": ":poop:", + "description": "Write bad code that needs to be improved." + }, + { + "emoji": "โช๏ธ", + "code": ":rewind:", + "description": "Revert changes." + }, + { + "emoji": "๐Ÿ”€", + "code": ":twisted_rightwards_arrows:", + "description": "Merge branches." + }, + { + "emoji": "๐Ÿ“ฆ๏ธ", + "code": ":package:", + "description": "Add or update compiled files or packages." + }, + { + "emoji": "๐Ÿ‘ฝ๏ธ", + "code": ":alien:", + "description": "Update code due to external API changes." + }, + { + "emoji": "๐Ÿšš", + "code": ":truck:", + "description": "Move or rename resources (e.g.: files, paths, routes)." + }, + { + "emoji": "๐Ÿ“„", + "code": ":page_facing_up:", + "description": "Add or update license." + }, + { + "emoji": "๐Ÿ’ฅ", + "code": ":boom:", + "description": "Introduce breaking changes." + }, + { + "emoji": "๐Ÿฑ", + "code": ":bento:", + "description": "Add or update assets." + }, + { + "emoji": "โ™ฟ๏ธ", + "code": ":wheelchair:", + "description": "Improve accessibility." + }, + { + "emoji": "๐Ÿ’ก", + "code": ":bulb:", + "description": "Add or update comments in source code." + }, + { + "emoji": "๐Ÿป", + "code": ":beers:", + "description": "Write code drunkenly." + }, + { + "emoji": "๐Ÿ’ฌ", + "code": ":speech_balloon:", + "description": "Add or update text and literals." + }, + { + "emoji": "๐Ÿ—ƒ๏ธ", + "code": ":card_file_box:", + "description": "Perform database related changes." + }, + { + "emoji": "๐Ÿ”Š", + "code": ":loud_sound:", + "description": "Add or update logs." + }, + { + "emoji": "๐Ÿ”‡", + "code": ":mute:", + "description": "Remove logs." + }, + { + "emoji": "๐Ÿ‘ฅ", + "code": ":busts_in_silhouette:", + "description": "Add or update contributor(s)." + }, + { + "emoji": "๐Ÿšธ", + "code": ":children_crossing:", + "description": "Improve user experience / usability." + }, + { + "emoji": "๐Ÿ—๏ธ", + "code": ":building_construction:", + "description": "Make architectural changes." + }, + { + "emoji": "๐Ÿ“ฑ", + "code": ":iphone:", + "description": "Work on responsive design." + }, + { + "emoji": "๐Ÿคก", + "code": ":clown_face:", + "description": "Mock things." + }, + { + "emoji": "๐Ÿฅš", + "code": ":egg:", + "description": "Add or update an easter egg." + }, + { + "emoji": "๐Ÿ™ˆ", + "code": ":see_no_evil:", + "description": "Add or update a .gitignore file." + }, + { + "emoji": "๐Ÿ“ธ", + "code": ":camera_flash:", + "description": "Add or update snapshots." + }, + { + "emoji": "โš—๏ธ", + "code": ":alembic:", + "description": "Perform experiments." + }, + { + "emoji": "๐Ÿ”๏ธ", + "code": ":mag:", + "description": "Improve SEO." + }, + { + "emoji": "๐Ÿท๏ธ", + "code": ":label:", + "description": "Add or update types." + }, + { + "emoji": "๐ŸŒฑ", + "code": ":seedling:", + "description": "Add or update seed files." + }, + { + "emoji": "๐Ÿšฉ", + "code": ":triangular_flag_on_post:", + "description": "Add, update, or remove feature flags." + }, + { + "emoji": "๐Ÿฅ…", + "code": ":goal_net:", + "description": "Catch errors." + }, + { + "emoji": "๐Ÿ’ซ", + "code": ":dizzy:", + "description": "Add or update animations and transitions." + }, + { + "emoji": "๐Ÿ—‘๏ธ", + "code": ":wastebasket:", + "description": "Deprecate code that needs to be cleaned up." + }, + { + "emoji": "๐Ÿ›‚", + "code": ":passport_control:", + "description": "Work on code related to authorization, roles and permissions." + }, + { + "emoji": "๐Ÿฉน", + "code": ":adhesive_bandage:", + "description": "Simple fix for a non-critical issue." + }, + { + "emoji": "๐Ÿง", + "code": ":monocle_face:", + "description": "Data exploration/inspection." + }, + { + "emoji": "โšฐ๏ธ", + "code": ":coffin:", + "description": "Remove dead code." + }, + { + "emoji": "๐Ÿงช", + "code": ":test_tube:", + "description": "Add a failing test." + }, + { + "emoji": "๐Ÿ‘”", + "code": ":necktie:", + "description": "Add or update business logic." + }, + { + "emoji": "๐Ÿฉบ", + "code": ":stethoscope:", + "description": "Add or update healthcheck." + }, + { + "emoji": "๐Ÿงฑ", + "code": ":bricks:", + "description": "Infrastructure related changes." + }, + { + "emoji": "๐Ÿง‘โ€๐Ÿ’ป", + "code": ":technologist:", + "description": "Improve developer experience." + }, + { + "emoji": "๐Ÿ’ธ", + "code": ":money_with_wings:", + "description": "Add sponsorships or money related infrastructure." + }, + { + "emoji": "๐Ÿงต", + "code": ":thread:", + "description": "Add or update code related to multithreading or concurrency." + }, + { + "emoji": "๐Ÿฆบ", + "code": ":safety_vest:", + "description": "Add or update code related to validation." + } + ] + \`\`\` + ` + } + + ${ + isEmojiSupport + ? ` + \`\`\`txt \n โ™ป๏ธ refactor(lib): change lib folder to utils folder \n\`\`\`\n + \`\`\`txt \n โž• refactor(deps): rename lib folder to utils \n\`\`\`\n + \`\`\`txt \n โœ๏ธ fix(deps): rename lib folder to utils \n\`\`\`\n + ` + : ` + \`\`\`txt \n refactor(lib): change lib folder to utils folder \n\`\`\`\n + \`\`\`txt \n refactor(deps): rename lib folder to utils \n\`\`\`\n + \`\`\`txt \n fix(deps): rename lib folder to utils \n\`\`\`\n + ` + } `, }); diff --git a/app/page.tsx b/app/page.tsx index 4fd488d..410941d 100644 --- a/app/page.tsx +++ b/app/page.tsx @@ -15,6 +15,7 @@ import dynamic from "next/dynamic"; import ListSuggestion from "@/components/listSuggestion"; import Loader from "@/components/loader"; import { Spinner } from "@/components/ui/spinner"; +import { Switch } from "@/components/ui/switch"; const EmptyScreen = dynamic(() => import("@/components/emptyScreen"), { ssr: false, @@ -26,8 +27,9 @@ export default function Home() { const [isLoading, setIsLoading] = React.useState(false); const [error, setError] = React.useState(null); const [commitChanges, setcommitChanges] = React.useState(null); + const [isEmojiSupport, setIsEmojiSupport] = React.useState(false); const [commitMessages, setcommitMessages] = React.useState( - null, + null ); const { toast } = useToast(); @@ -48,6 +50,7 @@ export default function Home() { try { const { data, error } = await commitChange({ message: suggestion, + isEmojiSupport: isEmojiSupport, }); if (error) { @@ -62,7 +65,7 @@ export default function Home() { toastVariants({ variant: "destructive", className: "w-fit m-0 p-2 text-xs hover:bg-[#815305]/35", - }), + }) )} onClick={() => handelSubmit({ suggestion })} > @@ -73,6 +76,7 @@ export default function Home() { } else { if (data) { setcommitMessages(data.text); + console.log(data.text) setcommitChanges(suggestion); setMessage(""); } @@ -86,7 +90,7 @@ export default function Home() { const submitForm = ( e: React.FormEvent, - message: string | null, + message: string | null ): void => { e.preventDefault(); handelSubmit({ suggestion: message || "" }); @@ -100,7 +104,7 @@ export default function Home() { {error ? ( -
+

Oops! Something Went Wrong!{" "} : ( @@ -147,6 +151,13 @@ export default function Home() { required />
+
+ setIsEmojiSupport(e)} + id="emoji-mode" + /> + +
- + + + + + +

Submit

+
+
+ + + + + +

Cancel

+
+
) : (

{commitChanges}

- +
+ + + + + +

Regenerate

+
+
+ + + + + +

Edit

+
+
+
)} diff --git a/components/ui/tooltip.tsx b/components/ui/tooltip.tsx new file mode 100644 index 0000000..9e74821 --- /dev/null +++ b/components/ui/tooltip.tsx @@ -0,0 +1,30 @@ +"use client" + +import * as React from "react" +import * as TooltipPrimitive from "@radix-ui/react-tooltip" + +import { cn } from "@/lib/utils" + +const TooltipProvider = TooltipPrimitive.Provider + +const Tooltip = TooltipPrimitive.Root + +const TooltipTrigger = TooltipPrimitive.Trigger + +const TooltipContent = React.forwardRef< + React.ElementRef, + React.ComponentPropsWithoutRef +>(({ className, sideOffset = 4, ...props }, ref) => ( + +)) +TooltipContent.displayName = TooltipPrimitive.Content.displayName + +export { Tooltip, TooltipTrigger, TooltipContent, TooltipProvider }