diff --git a/frontend/src/app/scripts/_components/ScriptItem.tsx b/frontend/src/app/scripts/_components/ScriptItem.tsx index a5f47b826..fd9ae9115 100644 --- a/frontend/src/app/scripts/_components/ScriptItem.tsx +++ b/frontend/src/app/scripts/_components/ScriptItem.tsx @@ -1,39 +1,29 @@ - import { Separator } from "@/components/ui/separator"; -import { extractDate } from "@/lib/time"; -import { Script, AppVersion } from "@/lib/types"; import { fetchVersions } from "@/lib/data"; +import { extractDate } from "@/lib/time"; +import { AppVersion, Script } from "@/lib/types"; import { X } from "lucide-react"; import Image from "next/image"; +import { basePath } from "@/config/siteConfig"; +import { useEffect, useState } from "react"; import { getDisplayValueFromType } from "./ScriptInfoBlocks"; import Alerts from "./ScriptItems/Alerts"; import Buttons from "./ScriptItems/Buttons"; import DefaultPassword from "./ScriptItems/DefaultPassword"; -import DefaultSettings from "./ScriptItems/DefaultSettings"; import Description from "./ScriptItems/Description"; import InstallCommand from "./ScriptItems/InstallCommand"; import InterFaces from "./ScriptItems/InterFaces"; import Tooltips from "./ScriptItems/Tooltips"; -import { basePath } from "@/config/siteConfig"; -import { useEffect, useState } from "react"; - -function ScriptItem({ - item, - setSelectedScript, -}: { - item: Script; - setSelectedScript: (script: string | null) => void; -}) { +function ScriptItem({ item, setSelectedScript }: { item: Script; setSelectedScript: (script: string | null) => void }) { const closeScript = () => { window.history.pushState({}, document.title, window.location.pathname); setSelectedScript(null); }; const [versions, setVersions] = useState([]); - useEffect(() => { fetchVersions() .then((fetchedVersions) => { @@ -68,10 +58,7 @@ function ScriptItem({ className="h-32 w-32 rounded-lg bg-accent/60 object-contain p-3 shadow-md" src={item.logo || `/${basePath}/logo.png`} width={400} - onError={(e) => - ((e.currentTarget as HTMLImageElement).src = - `/${basePath}/logo.png`) - } + onError={(e) => ((e.currentTarget as HTMLImageElement).src = `/${basePath}/logo.png`)} height={400} alt={item.name} unoptimized @@ -89,35 +76,165 @@ function ScriptItem({ Default OS: {os} {version}

-
- -
-
{versions.length === 0 ? (

Loading versions...

) : - (<> -

Version:

-

{versions.find((v) => - v.name === item.slug.replace(/[^a-z0-9]/g, '') || - v.name.includes(item.slug.replace(/[^a-z0-9]/g, '')) || - v.name.replace(/[^a-z0-9]/g, '') === item.slug.replace(/[^a-z0-9]/g, '') +

+ {(() => { + const getDisplayValueFromRAM = (ram: number) => + ram >= 1024 ? `${Math.floor(ram / 1024)}GB` : `${ram}MB`; - )?.version || "No Version information found" - }

-

Latest Version changes(Pulled from newreleases.io):

-

- {(() => { - const matchedVersion = versions.find((v) => - v.name === item.slug.replace(/[^a-z0-9]/g, '') || - v.name.includes(item.slug.replace(/[^a-z0-9]/g, '')) || - v.name.replace(/[^a-z0-9]/g, '') === item.slug.replace(/[^a-z0-9]/g, '') - ); - return matchedVersion?.date ? - extractDate(matchedVersion.date as unknown as string) : - "No date information found" - })()} -

- ) - } + const IconText = ({ icon, label }: { icon: React.ReactNode; label: string }) => ( + + {icon} + {label} + + ); + + const CPUIcon = ( + + + + + ); + + const RAMIcon = ( + + + + + ); + + const HDDIcon = ( + + + + + + ); + + const ResourceDisplay = ({ + title, + cpu, + ram, + hdd, + }: { + title: string; + cpu: number | null; + ram: number | null; + hdd: number | null; + }) => { + const getDisplayValueFromRAM = (ram: number) => + ram >= 1024 ? `${Math.floor(ram / 1024)}GB` : `${ram}MB`; + + const IconText = ({ icon, label }: { icon: React.ReactNode; label: string }) => ( + + {icon} + {label} + + ); + + const hasCPU = typeof cpu === "number" && cpu > 0; + const hasRAM = typeof ram === "number" && ram > 0; + const hasHDD = typeof hdd === "number" && hdd > 0; + + if (!hasCPU && !hasRAM && !hasHDD) return null; + + return ( +
+ {title}: + {hasCPU && ( + <> + + | + + )} + {hasRAM && ( + <> + + | + + )} + {hasHDD && } +
+ ); + }; + + const defaultSettings = item.install_methods.find((method) => method.type === "default"); + const alpineSettings = item.install_methods.find((method) => method.type === "alpine"); + return ( + <> + {defaultSettings?.resources && ( + + )} + + {alpineSettings?.resources && ( + + )} + + ); + })()}
+ + {(() => { + if (versions.length === 0) { + return

Loading versions...

; + } + + const cleanSlug = item.slug.replace(/[^a-z0-9]/gi, "").toLowerCase(); + + const matched = versions.find((v) => { + const cleanName = v.name.replace(/[^a-z0-9]/gi, "").toLowerCase(); + return cleanName === cleanSlug || cleanName.includes(cleanSlug); + }); + + if (!matched) return null; + + return ( +
+ + Version: {matched.version} ( + {extractDate( + matched.date instanceof Date ? matched.date.toISOString() : matched.date || "", + )} + + + Info + +
+ ); + })()}
@@ -134,9 +251,7 @@ function ScriptItem({
-

- How to {item.type == "misc" ? "use" : "install"} -

+

How to {item.type == "misc" ? "use" : "install"}