mirror of
https://github.com/purrgrammer/grimoire.git
synced 2026-04-10 07:27:23 +02:00
Refactor: extract emoji shortcode regex to constant
Move the emoji shortcode matching pattern to EMOJI_SHORTCODE_REGEX constant in emoji-helpers.ts for reuse across reaction renderers.
This commit is contained in:
@@ -4,6 +4,7 @@ import { Heart, ThumbsUp, ThumbsDown, Flame, Smile } from "lucide-react";
|
||||
import { useNostrEvent } from "@/hooks/useNostrEvent";
|
||||
import { UserName } from "../UserName";
|
||||
import { RichText } from "../RichText";
|
||||
import { EMOJI_SHORTCODE_REGEX } from "@/lib/emoji-helpers";
|
||||
|
||||
/**
|
||||
* Compact preview for Kind 7 (Reaction)
|
||||
@@ -26,7 +27,7 @@ export function ReactionCompactPreview({ event }: { event: NostrEvent }) {
|
||||
|
||||
// Parse reaction content for custom emoji
|
||||
const parsedReaction = useMemo(() => {
|
||||
const match = reaction.match(/^:([a-zA-Z0-9_-]+):$/);
|
||||
const match = reaction.match(EMOJI_SHORTCODE_REGEX);
|
||||
if (match && customEmojis[match[1]]) {
|
||||
return {
|
||||
type: "custom" as const,
|
||||
|
||||
@@ -6,6 +6,7 @@ import { NostrEvent } from "@/types/nostr";
|
||||
import { KindRenderer } from "./index";
|
||||
import { EventCardSkeleton } from "@/components/ui/skeleton";
|
||||
import { parseReplaceableAddress } from "applesauce-core/helpers/pointers";
|
||||
import { EMOJI_SHORTCODE_REGEX } from "@/lib/emoji-helpers";
|
||||
|
||||
/**
|
||||
* Renderer for Kind 7 - Reactions
|
||||
@@ -32,7 +33,7 @@ export function Kind7Renderer({ event }: BaseEventProps) {
|
||||
// Parse reaction content to detect custom emoji shortcodes
|
||||
// Format: :shortcode: in the content
|
||||
const parsedReaction = useMemo(() => {
|
||||
const match = reaction.match(/^:([a-zA-Z0-9_-]+):$/);
|
||||
const match = reaction.match(EMOJI_SHORTCODE_REGEX);
|
||||
if (match && customEmojis[match[1]]) {
|
||||
return {
|
||||
type: "custom" as const,
|
||||
|
||||
@@ -1,6 +1,12 @@
|
||||
import { getOrComputeCachedValue } from "applesauce-core/helpers";
|
||||
import type { NostrEvent } from "@/types/nostr";
|
||||
|
||||
/**
|
||||
* Regex pattern to match NIP-30 custom emoji shortcodes like :shortcode:
|
||||
* Supports alphanumeric characters, underscores, and dashes
|
||||
*/
|
||||
export const EMOJI_SHORTCODE_REGEX = /^:([a-zA-Z0-9_-]+):$/;
|
||||
|
||||
/**
|
||||
* Represents a parsed emoji tag from NIP-30
|
||||
*/
|
||||
|
||||
Reference in New Issue
Block a user