2024-12-23 14:38:42 -05:00
|
|
|
import { Grid } from "@project-gauntlet/api/components";
|
|
|
|
import React, { ReactNode, useState } from "react";
|
2024-10-18 12:43:53 -04:00
|
|
|
import { Clipboard, showHud } from "@project-gauntlet/api/helpers";
|
2024-12-23 14:38:42 -05:00
|
|
|
import {
|
|
|
|
GroupedBy,
|
|
|
|
BaseEmoji,
|
|
|
|
getEmojis,
|
|
|
|
getEmojisGroupedBy,
|
|
|
|
} from "unicode-emoji";
|
2024-10-18 12:43:53 -04:00
|
|
|
|
2024-12-22 12:11:24 -05:00
|
|
|
// @ts-expect-error gauntlet uses deno and not node
|
|
|
|
// eslint-disable-next-line @typescript-eslint/no-unused-vars
|
2024-10-18 12:43:53 -04:00
|
|
|
const denoCore: DenoCore = Deno[Deno.internal].core;
|
|
|
|
|
2024-12-23 14:38:42 -05:00
|
|
|
export default function EmojiPicker(): ReactNode | undefined {
|
|
|
|
const [searchText, setSearchText] = useState<string | undefined>("");
|
2024-10-18 12:43:53 -04:00
|
|
|
|
2024-12-23 14:38:42 -05:00
|
|
|
let emojiList: BaseEmoji[] | Record<GroupedBy, BaseEmoji[]>;
|
|
|
|
let isCategory = null;
|
|
|
|
if (searchText) {
|
|
|
|
emojiList = getEmojis().filter((emoji) =>
|
|
|
|
emoji.keywords.some((keyword) => keyword.includes(searchText)),
|
|
|
|
);
|
|
|
|
isCategory = false;
|
|
|
|
} else {
|
|
|
|
emojiList = getEmojisGroupedBy("category");
|
|
|
|
isCategory = true;
|
2024-12-22 16:46:54 -05:00
|
|
|
}
|
2024-10-18 12:43:53 -04:00
|
|
|
|
2024-12-23 14:38:42 -05:00
|
|
|
let emojiListLength = 0;
|
|
|
|
if (isCategory) {
|
|
|
|
const typedList = emojiList as Record<GroupedBy, BaseEmoji[]>;
|
|
|
|
for (const category in typedList) {
|
|
|
|
emojiListLength += typedList[category as GroupedBy].length;
|
|
|
|
}
|
|
|
|
} else {
|
|
|
|
emojiListLength = (emojiList as BaseEmoji[]).length;
|
2024-12-22 16:46:54 -05:00
|
|
|
}
|
2024-12-23 14:38:42 -05:00
|
|
|
console.log(emojiListLength);
|
2024-10-18 13:05:48 -04:00
|
|
|
|
2024-12-22 16:46:54 -05:00
|
|
|
return (
|
2024-12-23 14:38:42 -05:00
|
|
|
<Grid>
|
|
|
|
<Grid.SearchBar
|
|
|
|
placeholder={"Search for an emoji"}
|
|
|
|
value={searchText}
|
|
|
|
onChange={setSearchText}
|
|
|
|
/>
|
|
|
|
{isCategory
|
|
|
|
? Object.entries(emojiList).map(([category, emojis]) => (
|
|
|
|
<Grid.Section key={category} title={category}>
|
|
|
|
{emojis.map((emoji: BaseEmoji) => (
|
|
|
|
<Grid.Item
|
|
|
|
key={emoji.emoji}
|
|
|
|
title={emoji.description}
|
|
|
|
onClick={async () => {
|
|
|
|
console.log(emoji);
|
|
|
|
await Clipboard.writeText(emoji.emoji);
|
|
|
|
showHud(`${emoji.emoji} copied to clipboard`);
|
|
|
|
}}
|
|
|
|
>
|
|
|
|
<Grid.Item.Content>
|
|
|
|
<Grid.Item.Content.Paragraph>
|
|
|
|
{emoji.emoji}
|
|
|
|
</Grid.Item.Content.Paragraph>
|
|
|
|
</Grid.Item.Content>
|
|
|
|
</Grid.Item>
|
|
|
|
))}
|
|
|
|
</Grid.Section>
|
|
|
|
))
|
|
|
|
: (emojiList as BaseEmoji[]).map((emoji: BaseEmoji) => (
|
|
|
|
<Grid.Item
|
|
|
|
key={emoji.emoji}
|
|
|
|
title={emoji.description}
|
|
|
|
onClick={async () => {
|
|
|
|
console.log(emoji);
|
|
|
|
await Clipboard.writeText(emoji.emoji);
|
|
|
|
showHud(`${emoji.emoji} copied to clipboard`);
|
|
|
|
}}
|
|
|
|
>
|
|
|
|
<Grid.Item.Content>
|
|
|
|
<Grid.Item.Content.Paragraph>
|
|
|
|
{emoji.emoji}
|
|
|
|
</Grid.Item.Content.Paragraph>
|
|
|
|
</Grid.Item.Content>
|
|
|
|
</Grid.Item>
|
|
|
|
))}
|
|
|
|
</Grid>
|
2024-12-22 16:46:54 -05:00
|
|
|
);
|
|
|
|
}
|