|
| 1 | +"use client"; |
| 2 | + |
| 3 | +import { useEffect, useState } from "react"; |
| 4 | +import { Bug, Github, AlertCircle } from "lucide-react"; |
| 5 | +import { useTranslations } from "next-intl"; |
| 6 | +import { useResolvedLanguage } from "@/store"; |
| 7 | +import { cn } from "@/lib/utils"; |
| 8 | + |
| 9 | +interface BugItem { |
| 10 | + title: string; |
| 11 | + phase: string; |
| 12 | + avoid: string; |
| 13 | + description: string; |
| 14 | +} |
| 15 | + |
| 16 | +/** |
| 17 | + * BugsReport Component |
| 18 | + * Displays a list of known issues and their status, loaded from a localized markdown file. |
| 19 | + * Includes a link to report new issues on GitHub. |
| 20 | + */ |
| 21 | +export function BugsReport() { |
| 22 | + const t = useTranslations(); |
| 23 | + const locale = useResolvedLanguage(); |
| 24 | + const [bugs, setBugs] = useState<BugItem[]>([]); |
| 25 | + const [isLoading, setIsLoading] = useState(true); |
| 26 | + |
| 27 | + useEffect(() => { |
| 28 | + // Determine which file to fetch based on locale |
| 29 | + const fileLocale = locale.startsWith("es") ? "es" : "en"; |
| 30 | + |
| 31 | + setIsLoading(true); |
| 32 | + fetch(`/data/known-bugs.${fileLocale}.md`) |
| 33 | + .then((res) => { |
| 34 | + if (!res.ok) throw new Error("Failed to load bugs"); |
| 35 | + return res.text(); |
| 36 | + }) |
| 37 | + .then((text) => { |
| 38 | + const parsedBugs = parseMarkdown(text); |
| 39 | + setBugs(parsedBugs); |
| 40 | + }) |
| 41 | + .catch((err) => { |
| 42 | + console.error("Error loading bugs:", err); |
| 43 | + // If localized version fails, try English as fallback |
| 44 | + if (fileLocale !== "en") { |
| 45 | + fetch("/data/known-bugs.en.md") |
| 46 | + .then(res => res.text()) |
| 47 | + .then(text => setBugs(parseMarkdown(text))) |
| 48 | + .catch(e => console.error("Fallback error:", e)); |
| 49 | + } |
| 50 | + }) |
| 51 | + .finally(() => setIsLoading(false)); |
| 52 | + }, [locale]); |
| 53 | + |
| 54 | + /** |
| 55 | + * Parses the markdown content into a list of BugItem objects. |
| 56 | + * Expected format: |
| 57 | + * ### Title |
| 58 | + * - **Phase**: status |
| 59 | + * - **Avoid**: tip |
| 60 | + * - **Description**: details |
| 61 | + */ |
| 62 | + const parseMarkdown = (text: string): BugItem[] => { |
| 63 | + const sections = text.split("###").slice(1); |
| 64 | + return sections.map((section) => { |
| 65 | + const lines = section.split("\n"); |
| 66 | + const title = lines[0].trim(); |
| 67 | + |
| 68 | + const getValue = (key: string) => { |
| 69 | + const line = lines.find(l => l.includes(`**${key}**:`) || l.includes(`**${key}**: `)); |
| 70 | + if (!line) return ""; |
| 71 | + return line.split(`**${key}**:`)[1]?.trim() || ""; |
| 72 | + }; |
| 73 | + |
| 74 | + return { |
| 75 | + title, |
| 76 | + phase: getValue("Phase"), |
| 77 | + avoid: getValue("Avoid"), |
| 78 | + description: getValue("Description") |
| 79 | + }; |
| 80 | + }); |
| 81 | + }; |
| 82 | + |
| 83 | + if (!isLoading && bugs.length === 0) return null; |
| 84 | + |
| 85 | + return ( |
| 86 | + <section className="mt-12 p-8 bg-muted/20 dark:bg-white/5 border border-border rounded-2xl animate-in fade-in slide-in-from-bottom-2 duration-700"> |
| 87 | + <div className="flex flex-col md:flex-row md:items-center justify-between gap-6 mb-8"> |
| 88 | + <div> |
| 89 | + <h2 className="text-xl font-bold flex items-center gap-2.5"> |
| 90 | + <Bug className="w-6 h-6 text-primary" /> |
| 91 | + {t("knownBugsTitle")} |
| 92 | + </h2> |
| 93 | + <p className="text-sm text-text-secondary mt-1.5 max-w-lg"> |
| 94 | + {t("knownBugsDesc")} |
| 95 | + </p> |
| 96 | + </div> |
| 97 | + <a |
| 98 | + href="https://github.com/InledGroup/office/issues" |
| 99 | + target="_blank" |
| 100 | + rel="noopener noreferrer" |
| 101 | + className="flex items-center justify-center gap-2.5 px-6 py-3 bg-zinc-900 dark:bg-white text-white dark:text-zinc-900 rounded-xl hover:opacity-90 transition-all font-bold text-sm shadow-sm" |
| 102 | + > |
| 103 | + <Github className="w-5 h-5" /> |
| 104 | + {t("reportOnGithub")} |
| 105 | + </a> |
| 106 | + </div> |
| 107 | + |
| 108 | + <div className="grid grid-cols-1 md:grid-cols-2 lg:grid-cols-3 gap-5"> |
| 109 | + {isLoading ? ( |
| 110 | + Array.from({ length: 3 }).map((_, i) => ( |
| 111 | + <div key={i} className="h-40 bg-muted/40 animate-pulse rounded-xl" /> |
| 112 | + )) |
| 113 | + ) : ( |
| 114 | + bugs.map((bug, i) => ( |
| 115 | + <div key={i} className="p-5 bg-background border border-border rounded-xl shadow-sm hover:border-primary/40 transition-all group flex flex-col h-full"> |
| 116 | + <h3 className="font-bold text-sm mb-4 flex items-start gap-2.5 leading-snug"> |
| 117 | + <AlertCircle className="w-4 h-4 text-amber-500 shrink-0 mt-0.5" /> |
| 118 | + {bug.title} |
| 119 | + </h3> |
| 120 | + |
| 121 | + <div className="space-y-3.5 mt-auto"> |
| 122 | + <div className="flex items-center gap-2 text-[11px]"> |
| 123 | + <span className="font-bold text-text-secondary uppercase tracking-wider w-24 shrink-0">{t("bugPhase")}:</span> |
| 124 | + <span className={cn( |
| 125 | + "px-2.5 py-0.5 rounded-full font-bold", |
| 126 | + bug.phase.toLowerCase().includes("solucionado") || bug.phase.toLowerCase().includes("fixed") |
| 127 | + ? "bg-emerald-100 text-emerald-700 dark:bg-emerald-900/30 dark:text-emerald-400" |
| 128 | + : bug.phase.toLowerCase().includes("progreso") || bug.phase.toLowerCase().includes("progress") || bug.phase.toLowerCase().includes("investigando") || bug.phase.toLowerCase().includes("investigating") |
| 129 | + ? "bg-blue-100 text-blue-700 dark:bg-blue-900/30 dark:text-blue-400" |
| 130 | + : "bg-amber-100 text-amber-700 dark:bg-amber-900/30 dark:text-amber-400" |
| 131 | + )}> |
| 132 | + {bug.phase} |
| 133 | + </span> |
| 134 | + </div> |
| 135 | + |
| 136 | + <div className="flex items-start gap-2 text-[11px]"> |
| 137 | + <span className="font-bold text-text-secondary uppercase tracking-wider w-24 shrink-0">{t("bugAvoid")}:</span> |
| 138 | + <p className="text-text-secondary font-medium leading-relaxed italic"> |
| 139 | + "{bug.avoid}" |
| 140 | + </p> |
| 141 | + </div> |
| 142 | + |
| 143 | + {bug.description && ( |
| 144 | + <div className="pt-3 border-t border-border/40"> |
| 145 | + <p className="text-[11px] text-text-secondary/80 leading-relaxed italic"> |
| 146 | + {bug.description} |
| 147 | + </p> |
| 148 | + </div> |
| 149 | + )} |
| 150 | + </div> |
| 151 | + </div> |
| 152 | + )) |
| 153 | + )} |
| 154 | + </div> |
| 155 | + </section> |
| 156 | + ); |
| 157 | +} |
0 commit comments