fix: emoji render function (#1484)

* fix: emoji render function

* fix: emoji render function
This commit is contained in:
Aaryan Khandelwal 2023-07-06 16:08:49 +05:30 committed by GitHub
parent 3a2f4d55d7
commit 49f37e0346
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
8 changed files with 40 additions and 30 deletions

View File

@ -23,6 +23,7 @@ import {
import { ContrastIcon, LayerDiagonalIcon } from "components/icons"; import { ContrastIcon, LayerDiagonalIcon } from "components/icons";
// helpers // helpers
import { renderShortDate } from "helpers/date-time.helper"; import { renderShortDate } from "helpers/date-time.helper";
import { renderEmoji } from "helpers/emoji.helper";
// types // types
import { import {
IAnalyticsParams, IAnalyticsParams,
@ -221,7 +222,7 @@ export const AnalyticsSidebar: React.FC<Props> = ({
<div className="text-sm flex items-center gap-1"> <div className="text-sm flex items-center gap-1">
{project.emoji ? ( {project.emoji ? (
<span className="grid h-6 w-6 flex-shrink-0 place-items-center"> <span className="grid h-6 w-6 flex-shrink-0 place-items-center">
{String.fromCodePoint(parseInt(project.emoji))} {renderEmoji(project.emoji)}
</span> </span>
) : project.icon_prop ? ( ) : project.icon_prop ? (
<div className="h-6 w-6 grid place-items-center flex-shrink-0"> <div className="h-6 w-6 grid place-items-center flex-shrink-0">
@ -336,7 +337,7 @@ export const AnalyticsSidebar: React.FC<Props> = ({
<div className="flex items-center gap-1"> <div className="flex items-center gap-1">
{projectDetails?.emoji ? ( {projectDetails?.emoji ? (
<div className="grid h-6 w-6 flex-shrink-0 place-items-center"> <div className="grid h-6 w-6 flex-shrink-0 place-items-center">
{String.fromCodePoint(parseInt(projectDetails.emoji))} {renderEmoji(projectDetails.emoji)}
</div> </div>
) : projectDetails?.icon_prop ? ( ) : projectDetails?.icon_prop ? (
<div className="h-6 w-6 grid place-items-center flex-shrink-0"> <div className="h-6 w-6 grid place-items-center flex-shrink-0">

View File

@ -10,7 +10,7 @@ import emojis from "./emojis.json";
import icons from "./icons.json"; import icons from "./icons.json";
// helpers // helpers
import { getRecentEmojis, saveRecentEmoji } from "./helpers"; import { getRecentEmojis, saveRecentEmoji } from "./helpers";
import { getRandomEmoji } from "helpers/common.helper"; import { getRandomEmoji, renderEmoji } from "helpers/emoji.helper";
// hooks // hooks
import useOutsideClickDetector from "hooks/use-outside-click-detector"; import useOutsideClickDetector from "hooks/use-outside-click-detector";
@ -101,7 +101,7 @@ const EmojiIconPicker: React.FC<Props> = ({ label, value, onChange, onIconColorC
setIsOpen(false); setIsOpen(false);
}} }}
> >
{String.fromCodePoint(parseInt(emoji))} {renderEmoji(emoji)}
</button> </button>
))} ))}
</div> </div>
@ -121,7 +121,7 @@ const EmojiIconPicker: React.FC<Props> = ({ label, value, onChange, onIconColorC
setIsOpen(false); setIsOpen(false);
}} }}
> >
{String.fromCodePoint(parseInt(emoji))} {renderEmoji(emoji)}
</button> </button>
))} ))}
</div> </div>

View File

@ -21,7 +21,7 @@ import { XMarkIcon } from "@heroicons/react/24/outline";
import { ImagePickerPopover } from "components/core"; import { ImagePickerPopover } from "components/core";
import EmojiIconPicker from "components/emoji-icon-picker"; import EmojiIconPicker from "components/emoji-icon-picker";
// helpers // helpers
import { getRandomEmoji } from "helpers/common.helper"; import { getRandomEmoji, renderEmoji } from "helpers/emoji.helper";
// types // types
import { ICurrentUserResponse, IProject } from "types"; import { ICurrentUserResponse, IProject } from "types";
// fetch-keys // fetch-keys
@ -232,7 +232,7 @@ export const CreateProjectModal: React.FC<Props> = (props) => {
{value.name} {value.name}
</span> </span>
) : ( ) : (
String.fromCodePoint(parseInt(value)) renderEmoji(value)
) )
) : ( ) : (
"Icon" "Icon"

View File

@ -24,6 +24,7 @@ import {
// helpers // helpers
import { renderShortDateWithYearFormat } from "helpers/date-time.helper"; import { renderShortDateWithYearFormat } from "helpers/date-time.helper";
import { copyTextToClipboard, truncateText } from "helpers/string.helper"; import { copyTextToClipboard, truncateText } from "helpers/string.helper";
import { renderEmoji } from "helpers/emoji.helper";
// types // types
import type { IFavoriteProject, IProject } from "types"; import type { IFavoriteProject, IProject } from "types";
// fetch-keys // fetch-keys
@ -184,7 +185,7 @@ export const SingleProjectCard: React.FC<ProjectCardProps> = ({
<h3 className="text-1.5xl font-medium text-brand-base">{project.name}</h3> <h3 className="text-1.5xl font-medium text-brand-base">{project.name}</h3>
{project.emoji ? ( {project.emoji ? (
<span className="grid h-7 w-7 flex-shrink-0 place-items-center rounded uppercase"> <span className="grid h-7 w-7 flex-shrink-0 place-items-center rounded uppercase">
{String.fromCodePoint(parseInt(project.emoji))} {renderEmoji(project.emoji)}
</span> </span>
) : project.icon_prop ? ( ) : project.icon_prop ? (
<span <span

View File

@ -22,6 +22,7 @@ import {
} from "components/icons"; } from "components/icons";
// helpers // helpers
import { truncateText } from "helpers/string.helper"; import { truncateText } from "helpers/string.helper";
import { renderEmoji } from "helpers/emoji.helper";
// types // types
import { IProject } from "types"; import { IProject } from "types";
@ -92,7 +93,7 @@ export const SingleSidebarProject: React.FC<Props> = ({
<div className="flex items-center gap-x-2"> <div className="flex items-center gap-x-2">
{project.emoji ? ( {project.emoji ? (
<span className="grid h-7 w-7 flex-shrink-0 place-items-center rounded uppercase"> <span className="grid h-7 w-7 flex-shrink-0 place-items-center rounded uppercase">
{String.fromCodePoint(parseInt(project.emoji))} {renderEmoji(project.emoji)}
</span> </span>
) : project.icon_prop ? ( ) : project.icon_prop ? (
<div className="h-7 w-7 grid place-items-center"> <div className="h-7 w-7 grid place-items-center">

View File

@ -16,23 +16,3 @@ export const debounce = (func: any, wait: number, immediate: boolean = false) =>
if (callNow) func(...args); if (callNow) func(...args);
}; };
}; };
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

@ -0,0 +1,25 @@
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)];
};
export const renderEmoji = (emoji: string) => {
if (!emoji) return;
return isNaN(parseInt(emoji)) ? emoji : String.fromCodePoint(parseInt(emoji));
};

View File

@ -27,6 +27,8 @@ import {
DangerButton, DangerButton,
} from "components/ui"; } from "components/ui";
import { BreadcrumbItem, Breadcrumbs } from "components/breadcrumbs"; import { BreadcrumbItem, Breadcrumbs } from "components/breadcrumbs";
// helpers
import { renderEmoji } from "helpers/emoji.helper";
// types // types
import { IProject, IWorkspace } from "types"; import { IProject, IWorkspace } from "types";
import type { NextPage } from "next"; import type { NextPage } from "next";
@ -186,7 +188,7 @@ const GeneralSettings: NextPage = () => {
{value.name} {value.name}
</span> </span>
) : ( ) : (
String.fromCodePoint(parseInt(value)) renderEmoji(value)
) )
) : ( ) : (
"Icon" "Icon"