import { useState, useEffect } from 'react' import { Tag, Calendar, ExternalLink, ChevronDown, ChevronUp, Loader2, Heart, Coffee } from 'lucide-react' import { useTranslation } from '../../i18n' import apiClient from '../../api/client' const REPO = 'mauriceboe/NOMAD' const PER_PAGE = 10 export default function GitHubPanel() { const { t, language } = useTranslation() const [releases, setReleases] = useState([]) const [loading, setLoading] = useState(true) const [error, setError] = useState(null) const [expanded, setExpanded] = useState({}) const [page, setPage] = useState(1) const [hasMore, setHasMore] = useState(true) const [loadingMore, setLoadingMore] = useState(false) const fetchReleases = async (pageNum = 1, append = false) => { try { const res = await apiClient.get(`/auth/github-releases`, { params: { per_page: PER_PAGE, page: pageNum } }) const data = res.data setReleases(prev => append ? [...prev, ...data] : data) setHasMore(data.length === PER_PAGE) } catch (err: unknown) { setError(err instanceof Error ? err.message : 'Unknown error') } } useEffect(() => { setLoading(true) fetchReleases(1).finally(() => setLoading(false)) }, []) const handleLoadMore = async () => { const next = page + 1 setLoadingMore(true) await fetchReleases(next, true) setPage(next) setLoadingMore(false) } const toggleExpand = (id) => { setExpanded(prev => ({ ...prev, [id]: !prev[id] })) } const formatDate = (dateStr) => { const d = new Date(dateStr) return d.toLocaleDateString(language === 'de' ? 'de-DE' : 'en-US', { day: 'numeric', month: 'short', year: 'numeric' }) } // Simple markdown-to-html for release notes (handles headers, bold, lists, links) const renderBody = (body) => { if (!body) return null const lines = body.split('\n') const elements = [] let listItems = [] const flushList = () => { if (listItems.length > 0) { elements.push(
$1')
.replace(/\[([^\]]+)\]\(([^)]+)\)/g, '$1')
}
for (const line of lines) {
const trimmed = line.trim()
if (!trimmed) { flushList(); continue }
if (trimmed.startsWith('### ')) {
flushList()
elements.push(
{t('admin.github.error')}
{error}
{t('admin.github.subtitle').replace('{repo}', REPO)}
{release.name}
)}