File tree Expand file tree Collapse file tree 3 files changed +59
-5
lines changed
Expand file tree Collapse file tree 3 files changed +59
-5
lines changed Original file line number Diff line number Diff line change @@ -62,6 +62,24 @@ const config: Config = {
6262
6363 staticDirectories : [ "public" ] ,
6464
65+ plugins : [
66+ async function serverRoutesPlugin ( context , options ) {
67+ return {
68+ name : "server-routes-plugin" ,
69+ async contentLoaded ( { content, actions } ) {
70+ const { createData, addRoute } = actions ;
71+
72+ // Add the dynamic route
73+ addRoute ( {
74+ path : "/servers/:id" ,
75+ component : "@site/src/pages/servers/[id].tsx" ,
76+ exact : true ,
77+ } ) ;
78+ } ,
79+ } ;
80+ } ,
81+ ] ,
82+
6583 presets : [
6684 [
6785 "classic" ,
Original file line number Diff line number Diff line change 1+ import { ServerAllData } from "@site/src/types" ;
2+ import React , { useEffect , useState } from "react" ;
3+ import { useParams } from "react-router-dom" ;
4+
5+ export default function ServerDetails ( ) {
6+ const { id } = useParams < { id : string } > ( ) ;
7+ const [ server , setServer ] = useState < ServerAllData | null > ( null ) ;
8+ const [ loading , setLoading ] = useState ( true ) ;
9+
10+ useEffect ( ( ) => {
11+ async function fetchServerData ( ) {
12+ try {
13+ const response = await fetch ( `https://api.open.mp/servers/${ id } ` ) ;
14+ if ( ! response . ok ) throw new Error ( "Server not found" ) ;
15+ const data : ServerAllData = await response . json ( ) ;
16+ setServer ( data ) ;
17+ } catch ( error ) {
18+ console . error ( "Failed to fetch server data:" , error ) ;
19+ } finally {
20+ setLoading ( false ) ;
21+ }
22+ }
23+
24+ fetchServerData ( ) ;
25+ } , [ id ] ) ;
26+
27+ if ( loading ) return < p > Loading...</ p > ;
28+ if ( ! server ) return < p > Server not found.</ p > ;
29+
30+ return (
31+ < div >
32+ < h1 > { server . core . hn } </ h1 >
33+ < p > { server . core . gm } </ p >
34+ </ div >
35+ ) ;
36+ }
Original file line number Diff line number Diff line change @@ -8,11 +8,11 @@ import React, {
88 useState
99} from "react" ;
1010import { FixedSizeList } from "react-window" ;
11- import LoadingBanner from "../components/LoadingBanner" ;
12- import ServerRow from "../components/ServerRow" ;
13- import { showToast , ToastContainer } from "../components/Toast" ;
14- import { API_ADDRESS } from "../constants" ;
15- import { CoreServerData , ServerAllData } from "../types" ;
11+ import LoadingBanner from "../../ components/LoadingBanner" ;
12+ import ServerRow from "../../ components/ServerRow" ;
13+ import { showToast , ToastContainer } from "../../ components/Toast" ;
14+ import { API_ADDRESS } from "../../ constants" ;
15+ import { CoreServerData , ServerAllData } from "../../ types" ;
1616
1717const API_SERVERS = `${ API_ADDRESS } /servers/` ;
1818
You can’t perform that action at this time.
0 commit comments