import * as React from 'react';
import {useRef, useState} from 'react';
import Popover from '@mui/material/Popover';
import Typography from '@mui/material/Typography';
import {rawEmojis} from '../app/emojis';
import Box from "@mui/material/Box";
import TextField from "@mui/material/TextField";
import {InputAdornment} from "@mui/material";
import IconButton from "@mui/material/IconButton";
import {Close} from "@mui/icons-material";
const emojisByCategory = {};
rawEmojis.forEach(emoji => {
if (!emojisByCategory[emoji.category]) {
emojisByCategory[emoji.category] = [];
}
emojisByCategory[emoji.category].push(emoji);
});
const EmojiPicker = (props) => {
const open = Boolean(props.anchorEl);
const [search, setSearch] = useState("");
const searchRef = useRef(null);
/*
FIXME Search is inefficient, somehow make it faster
useEffect(() => {
const matching = rawEmojis.filter(e => {
const searchLower = search.toLowerCase();
return e.description.toLowerCase().indexOf(searchLower) !== -1
|| matchInArray(e.aliases, searchLower)
|| matchInArray(e.tags, searchLower);
});
console.log("matching", matching.length);
}, [search]);
*/
const handleSearchClear = () => {
setSearch("");
searchRef.current?.focus();
};
return (
<>
setSearch(ev.target.value)}
type="text"
variant="standard"
fullWidth
sx={{ marginTop: 0, paddingRight: 2 }}
InputProps={{
endAdornment:
}}
/>
{Object.keys(emojisByCategory).map(category =>
)}
>
);
};
const Category = (props) => {
const showTitle = !props.search;
return (
<>
{showTitle &&
{props.title}
}
{props.emojis.map(emoji =>
props.onPick(emoji.aliases[0])}
/>
)}
>
);
};
const Emoji = (props) => {
const emoji = props.emoji;
const search = props.search;
const matches = search === ""
|| emoji.description.toLowerCase().indexOf(search) !== -1
|| matchInArray(emoji.aliases, search)
|| matchInArray(emoji.tags, search);
if (!matches) {
return null;
}
return (
{props.emoji.emoji}
);
};
const matchInArray = (arr, search) => {
if (!arr || !search) {
return false;
}
return arr.filter(s => s.indexOf(search) !== -1).length > 0;
}
export default EmojiPicker;