Hey is a decentralized and permissionless social media app built with Lens Protocol 🌿

Refactor getMentions helper (#5645)

authored by yoginth.com and committed by

GitHub ff58cb63 f769a7b8

+9 -14
+9 -14
apps/web/src/helpers/getMentions.ts
··· 1 1 import { Regex } from "@hey/data/regex"; 2 2 import type { AccountMentionFragment, PostMentionFragment } from "@hey/indexer"; 3 3 4 - const getMentions = (text: string): [] | PostMentionFragment[] => { 5 - if (!text) { 6 - return []; 7 - } 4 + const getMentions = (text: string): PostMentionFragment[] => { 5 + if (!text) return []; 8 6 9 - const mentions = text.match(Regex.mention); 10 - const processedMentions = mentions?.map((mention) => { 11 - const splited = mention.split("/"); 12 - const handleWithoutNameSpace = splited[splited.length - 1]; 7 + const mentions = text.match(Regex.mention) ?? []; 8 + 9 + return mentions.map((mention) => { 10 + const handle = mention 11 + .substring(mention.lastIndexOf("/") + 1) 12 + .toLowerCase(); 13 13 14 14 return { 15 15 account: "", 16 16 namespace: "", 17 - replace: { 18 - from: handleWithoutNameSpace.toLowerCase(), 19 - to: handleWithoutNameSpace.toLowerCase() 20 - } 17 + replace: { from: handle, to: handle } 21 18 } as AccountMentionFragment; 22 19 }); 23 - 24 - return processedMentions || []; 25 20 }; 26 21 27 22 export default getMentions;