feat: random emoji will be chosen if none provided

This commit is contained in:
Dakshesh Jain 2022-12-21 11:46:57 +05:30
parent f322bcc4b0
commit 18cf044e3b
2 changed files with 26 additions and 0 deletions

View File

@ -216,3 +216,23 @@ export const createSimilarString = (str: string) => {
return shuffled;
};
export const getRandomEmoji = () => {
const emojis = [
"8986",
"9200",
"128204",
"127773",
"127891",
"127947",
"128076",
"128077",
"128187",
"128188",
"128512",
"128522",
"128578",
];
return emojis[Math.floor(Math.random() * emojis.length)];
};

View File

@ -3,6 +3,8 @@ import React, { useEffect, useState, useRef } from "react";
import { Tab, Transition, Popover } from "@headlessui/react";
// hooks
import useOutsideClickDetector from "lib/hooks/useOutsideClickDetector";
// common
import { getRandomEmoji } from "constants/common";
// emoji
import emojis from "./emojis.json";
// helpers
@ -36,6 +38,10 @@ const EmojiIconPicker: React.FC<Props> = ({ label, value, onChange }) => {
setIsOpen(false);
});
useEffect(() => {
if (!value) onChange(getRandomEmoji());
}, [value, onChange]);
return (
<Popover className="relative" ref={ref}>
<Popover.Button