diff --git a/package.json b/package.json index edb9078..47a4407 100644 --- a/package.json +++ b/package.json @@ -18,7 +18,20 @@ "mode": "view" } ], - "preferences": [], + "preferences": [ + { + "name": "copyFormat", + "title": "Copy Format", + "description": "What to copy to the clipboard when selecting a gitmoji.", + "required": false, + "type": "dropdown", + "data": [ + { "title": "Unicode Emoji", "value": "emoji" }, + { "title": "Gitmoji Code", "value": "code" } + ], + "default": "emoji" + } + ], "scripts": { "build": "vici build", "dev": "vici develop", diff --git a/src/gitmoji.tsx b/src/gitmoji.tsx index 773b5a7..abbdc99 100644 --- a/src/gitmoji.tsx +++ b/src/gitmoji.tsx @@ -1,5 +1,12 @@ import gitmojisData from "./gitmojis.json"; -import { Action, ActionPanel, List, showToast, Toast } from "@vicinae/api"; +import { + Action, + ActionPanel, + List, + showToast, + Toast, + getPreferenceValues, +} from "@vicinae/api"; type Gitmoji = { emoji: string; @@ -9,9 +16,25 @@ type Gitmoji = { name: string; }; +type CopyFormat = "emoji" | "code"; + +type GitmojiPreferences = { + copyFormat?: CopyFormat; +}; + const gitmojis = gitmojisData.gitmojis as Gitmoji[]; +const labelFor = (format: CopyFormat) => (format === "code" ? "Code" : "Emoji"); + +const contentFor = (gitmoji: Gitmoji, format: CopyFormat) => + format === "code" ? gitmoji.code : gitmoji.emoji; + export default function GitmojiList() { + const { copyFormat } = getPreferenceValues(); + const primaryFormat: CopyFormat = copyFormat === "code" ? "code" : "emoji"; + const secondaryFormat: CopyFormat = + primaryFormat === "code" ? "emoji" : "code"; + return ( {gitmojis.map((gitmoji) => ( @@ -25,8 +48,8 @@ export default function GitmojiList() { actions={ showToast( Toast.Style.Success, @@ -36,8 +59,8 @@ export default function GitmojiList() { } /> }