From 02be6f9d23752b435d792f0cd39e2c7be2c3a4b9 Mon Sep 17 00:00:00 2001 From: James Acklin Date: Sat, 3 Jun 2023 14:43:37 -0400 Subject: [PATCH] notifications: breaks URLs in notification text, uses shipname fixes #190 --- ui/src/nav/notifications/Notification.tsx | 32 +++++++++++++++++++++-- 1 file changed, 30 insertions(+), 2 deletions(-) diff --git a/ui/src/nav/notifications/Notification.tsx b/ui/src/nav/notifications/Notification.tsx index 683d81ba..5ca82433 100644 --- a/ui/src/nav/notifications/Notification.tsx +++ b/ui/src/nav/notifications/Notification.tsx @@ -151,7 +151,35 @@ const NotificationContent: React.FC = ({ function renderContent(c: YarnContent) { if (typeof c === 'string') { - return {c}; + const PATP_REGEX = /(~[a-z0-9-]+)/i; + const URL_REGEX = /(http(s?):\/\/[^\s]+)/i; + const COMBO_REGEX = /(~[a-z0-9-]+|https?:\/\/[^\s]+)/i; + const parts = c.split(COMBO_REGEX); + return ( + <> + {parts.map((part, index) => { + if (part.match(URL_REGEX)) { + return ( + + {part} + + ); + } + if (part.match(PATP_REGEX)) { + return ( + + ); + } else { + return {part}; + } + })} + + ); } if ('ship' in c) { @@ -184,7 +212,7 @@ const NotificationContent: React.FC = ({ if (isReply) { return ( <> -

+

{_.map(_.slice(content, 0, 4), (c: YarnContent) => renderContent(c))}