✨ Add ability to configure copy mode
This commit is contained in:
+28
-5
@@ -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<GitmojiPreferences>();
|
||||
const primaryFormat: CopyFormat = copyFormat === "code" ? "code" : "emoji";
|
||||
const secondaryFormat: CopyFormat =
|
||||
primaryFormat === "code" ? "emoji" : "code";
|
||||
|
||||
return (
|
||||
<List searchBarPlaceholder="Search gitmojis...">
|
||||
{gitmojis.map((gitmoji) => (
|
||||
@@ -25,8 +48,8 @@ export default function GitmojiList() {
|
||||
actions={
|
||||
<ActionPanel>
|
||||
<Action.CopyToClipboard
|
||||
title="Copy Emoji"
|
||||
content={gitmoji.emoji}
|
||||
title={`Copy ${labelFor(primaryFormat)}`}
|
||||
content={contentFor(gitmoji, primaryFormat)}
|
||||
onCopy={(content) =>
|
||||
showToast(
|
||||
Toast.Style.Success,
|
||||
@@ -36,8 +59,8 @@ export default function GitmojiList() {
|
||||
}
|
||||
/>
|
||||
<Action.CopyToClipboard
|
||||
title="Copy Code"
|
||||
content={gitmoji.code}
|
||||
title={`Copy ${labelFor(secondaryFormat)}`}
|
||||
content={contentFor(gitmoji, secondaryFormat)}
|
||||
/>
|
||||
</ActionPanel>
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user