Skip to content

Commit

Permalink
Use method to get emoji titles.
Browse files Browse the repository at this point in the history
  • Loading branch information
mross-ua committed Nov 23, 2023
1 parent 7772d27 commit aa63d1d
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 8 deletions.
4 changes: 2 additions & 2 deletions components/scoreboard/ScoreboardEmojiButton.vue
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
<script setup lang="ts">
import { emojiTitles } from '~~/data/emoji';
import { getEmojiTitle } from '~~/data/emoji';
const props = defineProps<{
id: string
Expand All @@ -9,7 +9,7 @@ const emit = defineEmits<{
(e: "emote", payload: string): void;
}>();
const emojiTitle = computed(() => emojiTitles[props.id]);
const emojiTitle = computed(() => getEmojiTitle(props.id));
</script>

<template>
Expand Down
16 changes: 10 additions & 6 deletions data/emoji.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,3 @@
const titularizeRegex = new RegExp(/[_-]/g);

export const emojis = [
'angry_face',
'angry_face_with_horns',
Expand Down Expand Up @@ -124,8 +122,14 @@ export const emojis = [
'softball',
];

export const emojiTitles: any = {};
const titularizeRegex = new RegExp(/[_-]/g);

const emojiTitles = emojis.reduce<Record<string, string>>((accumulator, currentValue) => {
accumulator[currentValue] = currentValue.replace(titularizeRegex, ' ');

return accumulator;
}, { });

emojis.forEach(emoji => {
emojiTitles[emoji] = emoji.replace(titularizeRegex, ' ');
});
export function getEmojiTitle(emojiName: string): string {
return emojiTitles[emojiName];
}

0 comments on commit aa63d1d

Please sign in to comment.