import { type ReactNode } from 'react' import { Tag, Calendar, ExternalLink, ChevronDown, ChevronUp, Heart, Coffee, Bug, Lightbulb, BookOpen } from 'lucide-react' import { useTranslation } from '../../../i18n' import { useGithubReleases } from '../../../components/Admin/useGithubReleases' import { escapeReleaseHtml as escapeHtml, parseReleaseNotes } from '../../../utils/releaseNotes' import { MAdminButton, MAdminCard } from './MAdminUi' import { withoutDonationsInApp } from '../../../utils/donations' import MSkeleton from '../../components/MSkeleton' const REPO = 'liketrek/TREK' // Support / community link cards (design: brand-tinted icon tile + title/sub). // Brand hex stays as content identity; every surface/border uses --m-* tokens. interface LinkCard { href: string color: string icon: ReactNode title: string sub: string } export default function MAdminGitHubPanel({ isPrerelease = false }: { isPrerelease?: boolean }) { const { t } = useTranslation() const { releases, shownReleases, loading, error, expanded, toggleExpand, hasMore, loadingMore, handleLoadMore, formatDate, } = useGithubReleases({ isPrerelease, fillPages: true }) // Simple markdown-to-html for release notes (handles headers, bold, lists, links) const renderBody = (body: string | null) => { if (!body) return null // `[label](url)` → anchor, exactly as /\[([^\]]+)\]\(([^)]+)\)/g did. Written as a // scan because that pattern backtracks from both ends: `[^\]]` matches `[` and // `[^)]` matches `(`, so a run of either made the engine retry the whole match from // every one of them, reading to the end each time. Release bodies come off the // GitHub API. Both parts are one-or-more, so `[](url)` and `[label]()` stay plain // text; the label ends at the first `]`, the url at the first `)`. const linkify = (text: string) => { let out = '' let cursor = 0 let search = 0 for (;;) { const open = text.indexOf('[', search) if (open === -1) break const close = text.indexOf(']', open + 1) if (close === -1) break // no `]` left: no later `[` can match either // Every `[` up to `close` shares that first `]`, so they fail together. if (close === open + 1 || text[close + 1] !== '(') { search = close + 1 continue } const end = text.indexOf(')', close + 2) if (end === -1) break // no `)` left: no later `(` can close either if (end === close + 2) { search = close + 1 continue } const label = text.slice(open + 1, close) const url = text.slice(close + 2, end) const safeUrl = url.startsWith('http://') || url.startsWith('https://') ? url : '#' out += `${text.slice(cursor, open)}${label}` cursor = end + 1 search = end + 1 } return out + text.slice(cursor) } const inlineFormat = (text: string) => { return linkify( escapeHtml(text) .replace(/\*\*(.+?)\*\*/g, '$1') .replace(/`(.+?)`/g, '$1') ) } return parseReleaseNotes(body).map((block, idx) => { if (block.kind === 'ul') { return ( ) } if (block.kind === 'h5') { return (
{block.text}
); } if (block.kind === 'h4') { return (

{block.text}

) } if (block.kind === 'h3') { return (

{block.text}

) } return (

) }) } const discordIcon = ( ) const cards: LinkCard[] = withoutDonationsInApp([ { href: 'https://ko-fi.com/mauriceboe', color: '#ff5e5b', icon: , title: 'Ko-fi', sub: t('admin.github.support') }, { href: 'https://buymeacoffee.com/mauriceboe', color: '#ffdd00', icon: , title: 'Buy Me a Coffee', sub: t('admin.github.support') }, { href: 'https://discord.gg/NhZBDSd4qW', color: '#5865F2', icon: discordIcon, title: 'Discord', sub: 'Join the community' }, { href: 'https://github.com/liketrek/TREK/issues/new?template=bug_report.yml', color: '#ef4444', icon: , title: t('settings.about.reportBug'), sub: t('settings.about.reportBugHint') }, { href: 'https://github.com/liketrek/TREK/discussions/new?category=feature-requests', color: '#f59e0b', icon: , title: t('settings.about.featureRequest'), sub: t('settings.about.featureRequestHint') }, { href: 'https://github.com/liketrek/TREK/wiki', color: '#6366f1', icon: , title: 'Wiki', sub: t('settings.about.wikiHint') }, ]) return (

{/* Support / community cards */}
{cards.map((card) => ( {card.icon}
{card.title}
{card.sub}
))}
{/* Loading / Error / Releases */} {loading ? ( ) : error && releases.length === 0 ? (

{t('admin.github.error')}

{error}

) : (

{t('admin.github.title')}

{t('admin.github.subtitle').replace('{repo}', REPO)}

GitHub
{/* Timeline */}
{/* Timeline line */}
{shownReleases.map((release, idx) => { const isLatest = idx === 0 const isExpanded = expanded[release.id] return (
{/* Timeline dot */}
{/* Release content */}
{release.tag_name} {isLatest && ( {t('admin.github.latest')} )} {release.prerelease && ( {t('admin.github.prerelease')} )}
{release.name && release.name !== release.tag_name && (

{release.name}

)}
{formatDate(release.published_at || release.created_at)} {release.author && ( {t('admin.github.by')} {release.author.login} )}
{/* Expandable body */} {release.body && (
{isExpanded && (
{renderBody(release.body)}
)}
)}
) })}
{/* A failed "Load more" keeps the timeline and stays retryable */} {error && (

{t('admin.github.error')} — {error}

)} {/* Load more */} {hasMore && (
{!loadingMore && } {loadingMore ? t('admin.github.loading') : t('admin.github.loadMore')}
)}
)}
) }