| 1 | "use client"; |
| 2 | |
| 3 | import { use, useState |
| 4 | import { useQuery } |
| 5 | import { useTranslations } |
| 6 | import { useRouter } |
| 7 | import { |
| 8 | Search, ExternalLink, |
| 9 | Code2, MessageSquare, |
| 10 | ScrollText, Calendar, |
| 11 | } from "lucide-react"; |
| 12 | import { toast } |
| 13 | import ReactMarkdown from "react-markdown |
| 14 | import remarkGfm from "remark-gfm |
| 15 | import rehypeRaw from "rehype-raw |
| 16 | import rehypeSanitize from "rehype-sanitize |
| 17 | import { authClient } |
| 18 | import { parseEggFeatures } |
| 19 | import { orpc } |
| 20 | import Loader from "@/components/loader |
| 21 | import { useIsMobile } |
| 22 | import { DitherAvatar } |
| 23 | import { |
| 24 | Dialog, |
| 25 | DialogPopup, |
| 26 | } from "@struxa/ui/components/dialog"; |
| 27 | import { |
| 28 | Sheet, |
| 29 | SheetPopup, |
| 30 | SheetHeader, |
| 31 | SheetTitle, |
| 32 | SheetPanel, |
| 33 | SheetFooter, |
| 34 | SheetClose, |
| 35 | } from "@struxa/ui/components/sheet"; |
| 36 | import { |
| 37 | Select, |
| 38 | SelectTrigger, |
| 39 | SelectValue, |
| 40 | SelectContent, |
| 41 | SelectItem, |
| 42 | } from "@struxa/ui/components/select"; |
| 43 | |
| 44 | interface ModrinthProject { |
| 45 | project_id: string; |
| 46 | slug: string; |
| 47 | title: string; |
| 48 | description: string; |
| 49 | author: string; |
| 50 | icon_url: string |
| 51 | downloads: number; |
| 52 | categories: string[] |
| 53 | date_modified: string; |
| 54 | project_type: string; |
| 55 | } |
| 56 | |
| 57 | interface ModrinthVersion { |
| 58 | id: string; |
| 59 | name: string; |
| 60 | version_number: string; |
| 61 | loaders: string[] |
| 62 | game_versions: string[] |
| 63 | date_published: string; |
| 64 | files: { |
| 65 | } |
| 66 | |
| 67 | interface ModrinthProjectDetail { |
| 68 | game_versions: string[] |
| 69 | loaders: string[] |
| 70 | categories: string[] |
| 71 | additional_categories: string[] |
| 72 | license: { |
| 73 | source_url: string |
| 74 | discord_url: string |
| 75 | issues_url: string |
| 76 | wiki_url: string |
| 77 | donation_urls: { |
| 78 | published: string; |
| 79 | updated: string; |
| 80 | client_side: string; |
| 81 | server_side: string; |
| 82 | } |
| 83 | |
| 84 | interface ModrinthMember { |
| 85 | role: string; |
| 86 | ordering: number; |
| 87 | user: { |
| 88 | } |
| 89 | |
| 90 | const MODRINTH_API = " |
| 91 | const PLUGIN_LOADERS = [ |
| 92 | const LOADER_ORDER = [ |
| 93 | const FACETS = encodeURIComponent |
| 94 | |
| 95 | const PROSE = [ |
| 96 | "text-sm text-foreground leading-relaxed", |
| 97 | "[&_h1]:text-xl [&_h1]:font-bold [&_h1]:mt-6 [&_h1]:mb-3 [&_h1]:text-foreground", |
| 98 | "[&_h2]:text-lg [&_h2]:font-semibold [&_h2]:mt-5 [&_h2]:mb-2 [&_h2]:text-foreground", |
| 99 | "[&_h3]:text-base [&_h3]:font-semibold [&_h3]:mt-4 [&_h3]:mb-2 [&_h3]:text-foreground", |
| 100 | "[&_h4]:text-sm [&_h4]:font-semibold [&_h4]:mt-3 [&_h4]:mb-1 [&_h4]:text-foreground", |
| 101 | "[&_p]:mb-3 [&_p]:leading-relaxed [&_p]:text-muted-foreground", |
| 102 | "[&_ul]:mb-3 [&_ul]:list-disc [&_ul]:pl-5 [&_ul]:space-y-1 [&_ul]:text-muted-foreground", |
| 103 | "[&_ol]:mb-3 [&_ol]:list-decimal [&_ol]:pl-5 [&_ol]:space-y-1 [&_ol]:text-muted-foreground", |
| 104 | "[&_li]:leading-relaxed", |
| 105 | "[&_code]:bg-muted [&_code]:rounded [&_code]:px-1.5 [&_code]:py-0.5 [&_code]:text-xs [&_code]:font-mono [&_code]:text-foreground", |
| 106 | "[&_pre]:bg-muted [&_pre]:rounded-lg [&_pre]:p-4 [&_pre]:overflow-x-auto [&_pre]:mb-3 [&_pre]:text-xs [&_pre]:font-mono", |
| 107 | "[&_pre_code]:bg-transparent [&_pre_code]:p-0", |
| 108 | "[&_blockquote]:border-l-2 [&_blockquote]:border-border [&_blockquote]:pl-4 [&_blockquote]:italic [&_blockquote]:text-muted-foreground [&_blockquote]:mb-3", |
| 109 | "[&_a]:text-primary [&_a]:underline [&_a]:underline-offset-2 [&_a]:decoration-primary/40 [&_a:hover]:decoration-primary", |
| 110 | "[&_img]:rounded-lg [&_img]:max-w-full [&_img]:my-3 [&_img]:align-middle", |
| 111 | "[&_p:has(>img:only-child)]:inline-block [&_p:has(>img:only-child)]:mb-2 [&_p:has(>img:only-child)]:mr-2 [&_p:has(>img:only-child)]:align-middle", |
| 112 | "[&_p:has(>a:only-child>img:only-child)]:inline-block [&_p:has(>a:only-child>img:only-child)]:mb-2 [&_p:has(>a:only-child>img:only-child)]:mr-2 [&_p:has(>a:only-child>img:only-child)]:align-middle", |
| 113 | "[&_hr]:border-border [&_hr]:my-5", |
| 114 | "[&_table]:w-full [&_table]:text-sm [&_table]:border-collapse [&_table]:mb-3", |
| 115 | "[&_th]:border [&_th]:border-border [&_th]:bg-muted [&_th]:px-3 [&_th]:py-2 [&_th]:text-left [&_th]:text-xs [&_th]:font-semibold", |
| 116 | "[&_td]:border [&_td]:border-border [&_td]:px-3 [&_td]:py-2 [&_td]:text-xs", |
| 117 | "[&_strong]:font-semibold [&_strong]:text-foreground", |
| 118 | "[&_details]:mb-3 [&_details]:rounded-lg [&_details]:border [&_details]:border-border [&_details]:p-3", |
| 119 | "[&_summary]:cursor-pointer [&_summary]:font-medium [&_summary]:text-sm", |
| 120 | ].join(" ") |
| 121 | |
| 122 | function fmtDownloads(n: |
| 123 | if (n >= |
| 124 | if (n >= |
| 125 | return String(n |
| 126 | } |
| 127 | |
| 128 | function loaderLabel(l: |
| 129 | return l.charAt |
| 130 | } |
| 131 | |
| 132 | function versionLabel(v: |
| 133 | const mc = |
| 134 | return mc ? |
| 135 | } |
| 136 | |
| 137 | function PluginIcon({ plugin |
| 138 | const dims = |
| 139 | const iconDims = |
| 140 | const rounded = |
| 141 | return ( |
| 142 | <div className={` |
| 143 | {plugin.icon_url ? |
| 144 | // eslint-disable-next-line @next/next/no-img-element |
| 145 | <img |
| 146 | src={plugin.icon_url |
| 147 | alt={plugin.title |
| 148 | className={`${dims |
| 149 | onError={(e) |
| 150 | /> |
| 151 | ) : ( |
| 152 | <Puzzle className={ |
| 153 | )} |
| 154 | </div> |
| 155 | ); |
| 156 | } |
| 157 | |
| 158 | function PluginCardSkeleton() { |
| 159 | return ( |
| 160 | <div className="flex flex-col gap-3 rounded-xl border border-border bg-card p-4 animate-pulse |
| 161 | <div className="flex items-start gap-3 |
| 162 | <div className="h-12 w-12 shrink-0 rounded-lg bg-muted |
| 163 | <div className="flex flex-1 flex-col gap-2 pt-0.5 |
| 164 | <div className="h-4 w-32 rounded bg-muted |
| 165 | <div className="h-3 w-20 rounded bg-muted |
| 166 | </div> |
| 167 | </div> |
| 168 | <div className="space-y-1.5 |
| 169 | <div className="h-3 w-full rounded bg-muted |
| 170 | <div className="h-3 w-4/5 rounded bg-muted |
| 171 | </div> |
| 172 | <div className="flex gap-1.5 |
| 173 | <div className="h-5 w-14 rounded-full bg-muted |
| 174 | <div className="h-5 w-10 rounded-full bg-muted |
| 175 | </div> |
| 176 | </div> |
| 177 | ); |
| 178 | } |
| 179 | |
| 180 | function PluginCard({ plugin |
| 181 | const t = |
| 182 | return ( |
| 183 | <button |
| 184 | type="button" |
| 185 | onClick={onClick} |
| 186 | className="group flex flex-col gap-3 rounded-xl border border-border bg-card p-4 text-left transition-colors hover:border-primary/40 hover:bg-card/80 focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-ring" |
| 187 | > |
| 188 | <div className="flex items-start gap-3 |
| 189 | <PluginIcon plugin={ |
| 190 | <div className="flex min-w-0 flex-1 flex-col gap-0.5 pt-0.5 |
| 191 | <p className="truncate text-sm font-semibold text-foreground leading-tight |
| 192 | <p className="truncate text-xs text-muted-foreground |
| 193 | </div> |
| 194 | <div className="flex items-center gap-1 shrink-0 text-[10px] text-muted-foreground |
| 195 | <Download className=" |
| 196 | {fmtDownloads(plugin.downloads |
| 197 | </div> |
| 198 | </div> |
| 199 | <p className="line-clamp-2 text-xs leading-relaxed text-muted-foreground |
| 200 | {plugin.categories.length |
| 201 | <div className="flex flex-wrap gap-1 |
| 202 | {plugin.categories.slice |
| 203 | <span key={cat |
| 204 | {cat} |
| 205 | </span> |
| 206 | ))} |
| 207 | </div> |
| 208 | )} |
| 209 | </button> |
| 210 | ); |
| 211 | } |
| 212 | |
| 213 | function VersionPicker({ |
| 214 | projectId, |
| 215 | onSelect, |
| 216 | }: { |
| 217 | projectId: string |
| 218 | onSelect: (v |
| 219 | }) { |
| 220 | const t = |
| 221 | const [allVersions, |
| 222 | const [loading, |
| 223 | const [selectedLoader, |
| 224 | const [selectedVersionId, |
| 225 | |
| 226 | useEffect(() => |
| 227 | setLoading(true); |
| 228 | setAllVersions(null); |
| 229 | setSelectedLoader(null); |
| 230 | setSelectedVersionId(null); |
| 231 | onSelect(null); |
| 232 | |
| 233 | fetch(`${MODRINTH_API} |
| 234 | .then((r) |
| 235 | .then((all) |
| 236 | const compatible = |
| 237 | (v) => |
| 238 | ); |
| 239 | const pool = |
| 240 | setAllVersions(pool); |
| 241 | |
| 242 | const counts = |
| 243 | for (const v |
| 244 | for (const l |
| 245 | if (PLUGIN_LOADERS.includes |
| 246 | |
| 247 | const bestLoader = |
| 248 | setSelectedLoader(bestLoader); |
| 249 | |
| 250 | const first = |
| 251 | if (first) { |
| 252 | }) |
| 253 | .catch(() => |
| 254 | .finally(() => |
| 255 | // eslint-disable-next-line react-hooks/exhaustive-deps |
| 256 | }, [projectId]); |
| 257 | |
| 258 | const availableLoaders = |
| 259 | ? LOADER_ORDER.filter( |
| 260 | : []; |
| 261 | |
| 262 | const filteredVersions = |
| 263 | ? allVersions.filter( |
| 264 | : (allVersions ?? |
| 265 | |
| 266 | const selectedVersion = |
| 267 | |
| 268 | function handleLoaderChange(loader |
| 269 | if (!loader) |
| 270 | setSelectedLoader(loader); |
| 271 | const versions = |
| 272 | const first = |
| 273 | setSelectedVersionId(first?.id |
| 274 | onSelect(first); |
| 275 | } |
| 276 | |
| 277 | function handleVersionChange(id |
| 278 | if (!id) |
| 279 | const v = |
| 280 | setSelectedVersionId(id); |
| 281 | onSelect(v); |
| 282 | } |
| 283 | |
| 284 | if (loading) { |
| 285 | return ( |
| 286 | <div className="flex flex-col gap-3 |
| 287 | <div className="h-9 rounded-lg bg-muted animate-pulse |
| 288 | <div className="h-9 rounded-lg bg-muted animate-pulse |
| 289 | </div> |
| 290 | ); |
| 291 | } |
| 292 | |
| 293 | if (!allVersions || |
| 294 | return <p className |
| 295 | } |
| 296 | |
| 297 | return ( |
| 298 | <div className="flex flex-col gap-3 |
| 299 | {availableLoaders.length > |
| 300 | <div className="flex flex-col gap-1.5 |
| 301 | <p className="text-xs font-medium text-muted-foreground |
| 302 | <Select value={ |
| 303 | <SelectTrigger className=" |
| 304 | <SelectValue>{selectedLoader |
| 305 | </SelectTrigger> |
| 306 | <SelectContent> |
| 307 | {availableLoaders.map(( |
| 308 | <SelectItem key={ |
| 309 | ))} |
| 310 | </SelectContent> |
| 311 | </Select> |
| 312 | </div> |
| 313 | )} |
| 314 | <div className="flex flex-col gap-1.5 |
| 315 | <p className="text-xs font-medium text-muted-foreground |
| 316 | <Select value={ |
| 317 | <SelectTrigger className=" |
| 318 | <SelectValue>{selectedVersion |
| 319 | </SelectTrigger> |
| 320 | <SelectContent> |
| 321 | {filteredVersions.map(( |
| 322 | <SelectItem key={ |
| 323 | ))} |
| 324 | </SelectContent> |
| 325 | </Select> |
| 326 | </div> |
| 327 | </div> |
| 328 | ); |
| 329 | } |
| 330 | |
| 331 | function Readme({ body |
| 332 | const t = |
| 333 | if (body === |
| 334 | return ( |
| 335 | <div className="flex flex-col gap-3 animate-pulse |
| 336 | {[...Array(6 |
| 337 | <div key={i |
| 338 | ))} |
| 339 | </div> |
| 340 | ); |
| 341 | } |
| 342 | if (!body) |
| 343 | |
| 344 | return ( |
| 345 | <div className={PROSE |
| 346 | <ReactMarkdown remarkPlugins={ |
| 347 | {body} |
| 348 | </ReactMarkdown> |
| 349 | </div> |
| 350 | ); |
| 351 | } |
| 352 | |
| 353 | const DONATE_LABELS: Record |
| 354 | "ko-fi": "Ko-fi", |
| 355 | patreon: "Patreon", |
| 356 | "open-collective": "Open Collective", |
| 357 | github: "GitHub Sponsors", |
| 358 | bmac: "Buy Me a Coffee", |
| 359 | paypal: "PayPal", |
| 360 | }; |
| 361 | |
| 362 | function timeAgo(dateStr: |
| 363 | const diff = |
| 364 | const rtf = |
| 365 | const s = |
| 366 | if (s < |
| 367 | const m = |
| 368 | if (m < |
| 369 | const h = |
| 370 | if (h < |
| 371 | const d = |
| 372 | if (d < |
| 373 | const mo = |
| 374 | if (mo < |
| 375 | return rtf.format |
| 376 | } |
| 377 | |
| 378 | function MetaSection({ title |
| 379 | return ( |
| 380 | <div className="flex flex-col gap-2 |
| 381 | <p className="text-[10px] font-semibold uppercase tracking-widest text-muted-foreground |
| 382 | {children} |
| 383 | </div> |
| 384 | ); |
| 385 | } |
| 386 | |
| 387 | function MetaLink({ href |
| 388 | return ( |
| 389 | <a |
| 390 | href={href} |
| 391 | target="_blank" |
| 392 | rel="noopener noreferrer" |
| 393 | className="flex items-center gap-2 text-xs text-foreground hover:text-primary transition-colors" |
| 394 | > |
| 395 | <Icon className=" |
| 396 | {label} |
| 397 | <ExternalLink className=" |
| 398 | </a> |
| 399 | ); |
| 400 | } |
| 401 | |
| 402 | function safeUrl(u: |
| 403 | if (!u) |
| 404 | try { |
| 405 | const p = |
| 406 | return p.protocol |
| 407 | } catch { return |
| 408 | } |
| 409 | |
| 410 | function ProjectMetadata({ |
| 411 | detail, |
| 412 | members, |
| 413 | }: { |
| 414 | detail: ModrinthProjectDetail |
| 415 | members: ModrinthMember |
| 416 | }) { |
| 417 | const t = |
| 418 | if (detail === |
| 419 | return ( |
| 420 | <div className="flex flex-col gap-4 |
| 421 | {[80, 60, 100 |
| 422 | <div key={i |
| 423 | <div className="h-2.5 w-16 rounded bg-muted animate-pulse |
| 424 | <div className="h-3 rounded bg-muted animate-pulse |
| 425 | <div className="h-3 w-3/4 rounded bg-muted animate-pulse |
| 426 | </div> |
| 427 | ))} |
| 428 | </div> |
| 429 | ); |
| 430 | } |
| 431 | |
| 432 | if (!detail) |
| 433 | |
| 434 | const links: |
| 435 | ...(safeUrl(detail |
| 436 | ...(safeUrl(detail |
| 437 | ...(safeUrl(detail |
| 438 | ...(safeUrl(detail |
| 439 | ...detail.donation_urls. |
| 440 | const url = |
| 441 | return url ? |
| 442 | }), |
| 443 | ]; |
| 444 | |
| 445 | const allCategories = |
| 446 | const sortedMembers = |
| 447 | |
| 448 | return ( |
| 449 | <div className="flex flex-col gap-5 |
| 450 | {/* Links */} |
| 451 | {links.length > |
| 452 | <MetaSection title={ |
| 453 | <div className="flex flex-col gap-1.5 |
| 454 | {links.map(( |
| 455 | </div> |
| 456 | </MetaSection> |
| 457 | )} |
| 458 | |
| 459 | {/* Tags */} |
| 460 | {allCategories.length > |
| 461 | <MetaSection title={ |
| 462 | <div className="flex flex-wrap gap-1.5 |
| 463 | {allCategories.map(( |
| 464 | <span key={cat |
| 465 | ))} |
| 466 | </div> |
| 467 | </MetaSection> |
| 468 | )} |
| 469 | |
| 470 | {/* Creators */} |
| 471 | {sortedMembers.length > |
| 472 | <MetaSection title={ |
| 473 | <div className="flex flex-col gap-2 |
| 474 | {sortedMembers.map(( |
| 475 | <div key={m |
| 476 | <div className="h-7 w-7 shrink-0 overflow-hidden rounded-full bg-muted |
| 477 | {m.user.avatar_url |
| 478 | // eslint-disable-next-line @next/next/no-img-element |
| 479 | <img src={m |
| 480 | ) : ( |
| 481 | <DitherAvatar name={ |
| 482 | )} |
| 483 | </div> |
| 484 | <div className="flex min-w-0 flex-col |
| 485 | <span className="truncate text-xs font-medium text-foreground |
| 486 | <span className="text-[10px] text-muted-foreground |
| 487 | </div> |
| 488 | </div> |
| 489 | ))} |
| 490 | </div> |
| 491 | </MetaSection> |
| 492 | )} |
| 493 | |
| 494 | {/* Details */} |
| 495 | <MetaSection title={ |
| 496 | <div className="flex flex-col gap-1.5 |
| 497 | {detail.license && |
| 498 | <div className="flex items-center gap-2 text-xs text-muted-foreground |
| 499 | <ScrollText className=" |
| 500 | {safeUrl(detail.license |
| 501 | <a href={safeUrl |
| 502 | {detail.license.name |
| 503 | </a> |
| 504 | ) : ( |
| 505 | <span>{detail.license |
| 506 | )} |
| 507 | </div> |
| 508 | )} |
| 509 | <div className="flex items-center gap-2 text-xs text-muted-foreground |
| 510 | <Calendar className=" |
| 511 | {t("publishedAgo", |
| 512 | </div> |
| 513 | <div className="flex items-center gap-2 text-xs text-muted-foreground |
| 514 | <RefreshCw className=" |
| 515 | {t("updatedAgo", |
| 516 | </div> |
| 517 | </div> |
| 518 | </MetaSection> |
| 519 | </div> |
| 520 | ); |
| 521 | } |
| 522 | |
| 523 | function PluginDetail({ |
| 524 | plugin, |
| 525 | serverId, |
| 526 | onClose, |
| 527 | }: { |
| 528 | plugin: ModrinthProject |
| 529 | serverId: string |
| 530 | onClose: () |
| 531 | }) { |
| 532 | const t = |
| 533 | const isMobile = |
| 534 | const [body, |
| 535 | const [detail, |
| 536 | const [members, |
| 537 | const [selectedVersion, |
| 538 | const [installing, |
| 539 | const [installSheetOpen, |
| 540 | |
| 541 | useEffect(() => |
| 542 | setBody(undefined); |
| 543 | setDetail(undefined); |
| 544 | setMembers(undefined); |
| 545 | Promise.all([ |
| 546 | fetch(`${MODRINTH_API} |
| 547 | fetch(`${MODRINTH_API} |
| 548 | ]) |
| 549 | .then(([proj |
| 550 | setBody(proj.body |
| 551 | setDetail(proj); |
| 552 | setMembers(mems); |
| 553 | }) |
| 554 | .catch(() => |
| 555 | }, [plugin.project_id |
| 556 | |
| 557 | async function install |
| 558 | const file = |
| 559 | if (!file) |
| 560 | setInstalling(true); |
| 561 | try { |
| 562 | const res = |
| 563 | method: "POST", |
| 564 | headers: { "Content-Type": |
| 565 | body: JSON.stringify |
| 566 | }); |
| 567 | if (!res.ok |
| 568 | toast.success(t |
| 569 | onClose(); |
| 570 | } catch (e) |
| 571 | toast.error(e |
| 572 | } finally { |
| 573 | setInstalling(false); |
| 574 | } |
| 575 | } |
| 576 | |
| 577 | const installBtn = |
| 578 | <button |
| 579 | type="button" |
| 580 | onClick={install} |
| 581 | disabled={!selectedVersion |
| 582 | className="flex w-full items-center justify-center gap-2 rounded-lg bg-primary px-4 py-2.5 text-sm font-medium text-primary-foreground transition-colors hover:bg-primary/90 disabled:pointer-events-none disabled:opacity-50" |
| 583 | > |
| 584 | {installing ? t |
| 585 | </button> |
| 586 | ); |
| 587 | |
| 588 | if (!isMobile) |
| 589 | return ( |
| 590 | <Dialog open onOpenChange |
| 591 | <DialogPopup |
| 592 | showCloseButton={false} |
| 593 | className="flex max-w-5xl h-[85vh] p-0 overflow-hidden rounded-2xl shadow-2xl" |
| 594 | > |
| 595 | <button |
| 596 | type="button" |
| 597 | aria-label={t(" |
| 598 | onClick={onClose} |
| 599 | className="absolute right-3 top-3 z-10 flex h-8 w-8 items-center justify-center rounded-lg text-muted-foreground transition-colors hover:bg-muted hover:text-foreground" |
| 600 | > |
| 601 | <X className=" |
| 602 | </button> |
| 603 | |
| 604 | {/* Left column */} |
| 605 | <div className="flex w-72 shrink-0 flex-col gap-5 overflow-y-auto border-r border-border p-6 |
| 606 | <div className="flex items-start gap-3 pr-6 |
| 607 | <PluginIcon plugin={ |
| 608 | <div className="flex min-w-0 flex-col gap-1 pt-1 |
| 609 | <p className="font-semibold text-foreground leading-tight |
| 610 | <p className="text-xs text-muted-foreground |
| 611 | <div className="flex items-center gap-1 text-xs text-muted-foreground |
| 612 | <Download className=" |
| 613 | {fmtDownloads(plugin.downloads |
| 614 | </div> |
| 615 | </div> |
| 616 | </div> |
| 617 | |
| 618 | <div className="border-t border-border |
| 619 | |
| 620 | <VersionPicker projectId={ |
| 621 | |
| 622 | {installBtn} |
| 623 | |
| 624 | <a |
| 625 | href={`https://modrinth.com/plugin/${plugin |
| 626 | target="_blank" |
| 627 | rel="noopener noreferrer" |
| 628 | className="inline-flex items-center gap-1.5 text-xs text-muted-foreground hover:text-foreground transition-colors" |
| 629 | > |
| 630 | <ExternalLink className=" |
| 631 | {t("modrinthLink") |
| 632 | </a> |
| 633 | |
| 634 | <div className="border-t border-border |
| 635 | |
| 636 | <ProjectMetadata detail={ |
| 637 | </div> |
| 638 | |
| 639 | {/* Right column - README */ |
| 640 | <div className="flex-1 overflow-y-auto p-6 |
| 641 | <Readme body={ |
| 642 | </div> |
| 643 | </DialogPopup> |
| 644 | </Dialog> |
| 645 | ); |
| 646 | } |
| 647 | |
| 648 | /* ── Mobile ── */ |
| 649 | return ( |
| 650 | <> |
| 651 | <Sheet open onOpenChange |
| 652 | <SheetPopup side=" |
| 653 | <SheetHeader> |
| 654 | <div className="flex items-center gap-3 pr-8 |
| 655 | <PluginIcon plugin={ |
| 656 | <div className="flex min-w-0 flex-col gap-0.5 |
| 657 | <SheetTitle className=" |
| 658 | <p className="text-xs text-muted-foreground |
| 659 | </div> |
| 660 | </div> |
| 661 | </SheetHeader> |
| 662 | |
| 663 | <SheetPanel className=" |
| 664 | <ProjectMetadata detail={ |
| 665 | </SheetPanel> |
| 666 | |
| 667 | <SheetFooter variant=" |
| 668 | <button |
| 669 | type="button" |
| 670 | onClick={() => |
| 671 | className="flex w-full items-center justify-center gap-2 rounded-lg bg-primary px-4 py-2.5 text-sm font-medium text-primary-foreground transition-colors hover:bg-primary/90" |
| 672 | > |
| 673 | {t("install") |
| 674 | </button> |
| 675 | </SheetFooter> |
| 676 | </SheetPopup> |
| 677 | </Sheet> |
| 678 | |
| 679 | <Sheet open={ |
| 680 | <SheetPopup side=" |
| 681 | <SheetHeader> |
| 682 | <SheetTitle>{t( |
| 683 | </SheetHeader> |
| 684 | <SheetPanel scrollFade={ |
| 685 | <VersionPicker projectId={ |
| 686 | </SheetPanel> |
| 687 | <SheetFooter variant=" |
| 688 | {installBtn} |
| 689 | </SheetFooter> |
| 690 | </SheetPopup> |
| 691 | </Sheet> |
| 692 | </> |
| 693 | ); |
| 694 | } |
| 695 | |
| 696 | export default function PluginsPage |
| 697 | const t = |
| 698 | const router = |
| 699 | const { data: |
| 700 | const { id |
| 701 | |
| 702 | const [query, |
| 703 | const [debouncedQuery, |
| 704 | const [results, |
| 705 | const [searchLoading, |
| 706 | const [selectedPlugin, |
| 707 | const debounceRef = |
| 708 | |
| 709 | useEffect(() => |
| 710 | if (!isPending && |
| 711 | }, [isPending, |
| 712 | |
| 713 | const { data: |
| 714 | |
| 715 | const eggFeatures = |
| 716 | |
| 717 | const searchSeq = |
| 718 | |
| 719 | const doSearch = |
| 720 | const seq = |
| 721 | setSearchLoading(true); |
| 722 | const url = |
| 723 | ? `${MODRINTH_API}/search?query= |
| 724 | : `${MODRINTH_API}/search?facets= |
| 725 | fetch(url) |
| 726 | .then((r) |
| 727 | .then((data) |
| 728 | .catch(() => |
| 729 | .finally(() => |
| 730 | }, []); |
| 731 | |
| 732 | useEffect(() => |
| 733 | |
| 734 | function handleQueryChange(val |
| 735 | setQuery(val); |
| 736 | clearTimeout(debounceRef.current |
| 737 | debounceRef.current = |
| 738 | setDebouncedQuery(val); |
| 739 | doSearch(val); |
| 740 | }, 300); |
| 741 | } |
| 742 | |
| 743 | const unsupported = |
| 744 | |
| 745 | useEffect(() => |
| 746 | if (unsupported) router |
| 747 | }, [unsupported, |
| 748 | |
| 749 | if (isPending || |
| 750 | |
| 751 | const sectionTitle = |
| 752 | |
| 753 | return ( |
| 754 | <> |
| 755 | <div className="flex flex-1 flex-col bg-background min-h-0 |
| 756 | <div className="flex shrink-0 items-center gap-3 border-b border-border bg-card px-4 py-2.5 |
| 757 | <div className="relative flex-1 max-w-md |
| 758 | <Search className=" |
| 759 | <input |
| 760 | type="text" |
| 761 | value={query} |
| 762 | onChange={(e) |
| 763 | placeholder={t(" |
| 764 | className="w-full rounded-lg border border-border bg-background py-1.5 pl-9 pr-3 text-sm text-foreground placeholder:text-muted-foreground focus:outline-none focus:ring-2 focus:ring-ring" |
| 765 | /> |
| 766 | </div> |
| 767 | </div> |
| 768 | |
| 769 | <div className="flex-1 overflow-y-auto p-4 |
| 770 | <p className="mb-4 text-xs font-semibold uppercase tracking-widest text-muted-foreground |
| 771 | |
| 772 | {searchLoading ? ( |
| 773 | <div className="grid grid-cols-1 gap-4 sm:grid-cols-2 lg:grid-cols-3 xl:grid-cols-4 |
| 774 | {Array.from({ |
| 775 | </div> |
| 776 | ) : results && |
| 777 | <div className="grid grid-cols-1 gap-4 sm:grid-cols-2 lg:grid-cols-3 xl:grid-cols-4 |
| 778 | {results.map(( |
| 779 | <PluginCard key={ |
| 780 | ))} |
| 781 | </div> |
| 782 | ) : ( |
| 783 | <div className="flex flex-col items-center justify-center py-16 gap-3 text-center |
| 784 | <Puzzle className=" |
| 785 | <p className="text-sm text-muted-foreground |
| 786 | </div> |
| 787 | )} |
| 788 | </div> |
| 789 | </div> |
| 790 | |
| 791 | {selectedPlugin && ( |
| 792 | <PluginDetail |
| 793 | plugin={selectedPlugin} |
| 794 | serverId={id} |
| 795 | onClose={() => |
| 796 | /> |
| 797 | )} |
| 798 | </> |
| 799 | ); |
| 800 | } |