import { FC, useMemo } from 'react'; import { LocalizeText, NotificationAlertItem, NotificationAlertType, OpenUrl } from '../../../../api'; import { Button, Column, Flex, LayoutAvatarImageView, LayoutNotificationAlertView, LayoutNotificationAlertViewProps, Text } from '../../../../common'; const INFO_AVATAR_FIGURE = 'hr-831-61.hd-180-2.lg-270-100.sh-290-110.ha-3129-100.fa-1205-63.cc-3039-100'; interface NitroInfoAlertViewProps extends LayoutNotificationAlertViewProps { item: NotificationAlertItem; } const REPORT_ISSUES_URL = 'https://github.com/duckietm/Nitro-V3/issues'; type InfoSection = { title: string; lines: string[]; kind: 'hotel' | 'server' | 'credits' | 'generic' }; const detectKind = (title: string): InfoSection['kind'] => { const t = title.toLowerCase(); if(t.includes('hotel')) return 'hotel'; if(t.includes('server')) return 'server'; if(t.includes('credit')) return 'credits'; return 'generic'; }; const parseInfoSections = (text: string): { version: string; sections: InfoSection[] } => { const version = (text.match(/([^<]+)<\/b>/) || [ '', '' ])[1]; const stripped = text .replace(/^[^<]+<\/b>\r?\n?/, '') .replace(/Report issues at:[^]*$/, ''); const sections: InfoSection[] = []; const blocks = stripped.split(/\r?\n+/); for(const block of blocks) { if(!block.trim()) continue; const headerMatch = block.match(/([^<]+)<\/b>/); if(!headerMatch) continue; const title = headerMatch[1]; const rest = block.substring(block.indexOf('') + 4); const lines = rest.split(/\r/).map(l => l.trim().replace(/^-\s*/, '')).filter(Boolean); sections.push({ title, lines, kind: detectKind(title) }); } return { version, sections }; }; const sectionIcon: Record = { hotel: '🏨', server: 'đŸ–Ĩī¸', credits: '⭐', generic: 'â„šī¸' }; const splitLabel = (line: string): { label: string; value: string } => { const idx = line.indexOf(':'); if(idx === -1) return { label: '', value: line }; return { label: line.substring(0, idx).trim(), value: line.substring(idx + 1).trim() }; }; export const NitroInfoAlertView: FC = props => { const { item = null, title: titleProp = null, onClose = null, ...rest } = props; const { version, sections } = useMemo(() => { const text = (item && item.messages && item.messages[0]) || ''; return parseInfoSections(text); }, [ item ]); const rawTitle = titleProp || (item && item.title) || ''; const displayTitle = (rawTitle && rawTitle !== 'nitro.info.title') ? rawTitle : 'Hotel Info'; return (
{ version &&
âœĻ { version } âœĻ
}
{ sections.map((section, index) => (
{ sectionIcon[section.kind] } { section.title }
{ section.kind === 'credits' ? (
    { section.lines.map((line, i) => (
  • ★ { line }
  • )) }
) : (
    { section.lines.map((line, i) => { const { label, value } = splitLabel(line); return (
  • { label && { label } } { value }
  • ); }) }
) }
)) }
Found a bug? Help us improve!
); };