@@ -16,45 +16,48 @@ interface RawCommand {
16
16
arguments ?: string [ ] ;
17
17
}
18
18
19
+ interface RawPermission {
20
+ name ?: string ;
21
+ permissions ?: string [ ] ;
22
+ descriptions ?: string [ ] ;
23
+ }
24
+
19
25
export default function DynamicCommandsTable ( ) {
20
26
const [ commands , setCommands ] = useState < Command [ ] > ( [ ] ) ;
21
27
const [ loading , setLoading ] = useState ( true ) ;
22
28
const [ error , setError ] = useState < string | null > ( null ) ;
23
29
24
30
useEffect ( ( ) => {
25
- fetch (
26
- "https://raw.githubusercontent.com/EternalCodeTeam/EternalCore/refs/heads/master/raw_commands_docs.json"
27
- )
31
+ fetch ( "https://raw.githubusercontent.com/EternalCodeTeam/EternalCore/refs/heads/master/raw_eternalcore_documentation.json" )
28
32
. then ( ( res ) => {
29
33
if ( ! res . ok ) throw new Error ( "Failed to fetch commands" ) ;
30
34
return res . json ( ) ;
31
35
} )
32
- . then ( ( data : unknown ) => {
33
- if ( ! Array . isArray ( data ) ) {
36
+ . then ( ( data : any ) => {
37
+ if ( ! data || typeof data !== "object" || ( ! Array . isArray ( data . commands ) && ! Array . isArray ( data . permissions ) ) ) {
34
38
setError ( "Invalid data formatting received from server" ) ;
35
39
return ;
36
40
}
37
41
38
- const processedCommands = data . map ( ( cmd : unknown ) => {
39
- const rawCmd = cmd as RawCommand ;
40
- return {
41
- name : rawCmd . name || "Unknown" ,
42
- permission :
43
- Array . isArray ( rawCmd . permissions ) && rawCmd . permissions . length > 0
44
- ? rawCmd . permissions [ 0 ]
45
- : "-" ,
46
- description :
47
- Array . isArray ( rawCmd . descriptions ) && rawCmd . descriptions . length > 0
48
- ? rawCmd . descriptions [ 0 ]
49
- : "-" ,
50
- arguments :
51
- Array . isArray ( rawCmd . arguments ) && rawCmd . arguments . length > 0
52
- ? rawCmd . arguments . join ( ", " )
53
- : "-" ,
54
- } ;
55
- } ) ;
42
+ const commandsData = ( data . commands || [ ] ) . map ( ( cmd : RawCommand ) : Command => ( {
43
+ name : `/${ cmd . name ?. trim ( ) || "unknown" } ` ,
44
+ permission : cmd . permissions ?. [ 0 ] || "-" ,
45
+ description : cmd . descriptions ?. [ 0 ] || "-" ,
46
+ arguments : cmd . arguments ?. join ( ", " ) || "-" ,
47
+ } ) ) ;
48
+
49
+ const permissionsData = ( data . permissions || [ ] ) . map ( ( perm : RawPermission ) : Command => ( {
50
+ name : perm . name ?. trim ( ) || "Unknown" ,
51
+ permission : perm . permissions ?. [ 0 ] || "-" ,
52
+ description : perm . descriptions ?. [ 0 ] || "-" ,
53
+ arguments : "-" ,
54
+ } ) ) ;
55
+
56
+ const combined = [ ...commandsData , ...permissionsData ] . sort ( ( a , b ) =>
57
+ a . name . replace ( / ^ \/ / , "" ) . localeCompare ( b . name . replace ( / ^ \/ / , "" ) , "pl" , { sensitivity : "base" } )
58
+ ) ;
56
59
57
- setCommands ( processedCommands ) ;
60
+ setCommands ( combined ) ;
58
61
} )
59
62
. catch ( ( e ) => {
60
63
setError ( ( e as Error ) . message ) ;
@@ -67,27 +70,25 @@ export default function DynamicCommandsTable() {
67
70
if ( ! commands . length ) return < div > No commands found.</ div > ;
68
71
69
72
return (
70
- < div >
71
- < table >
72
- < thead >
73
- < tr >
74
- < th > Name</ th >
75
- < th > Permission</ th >
76
- < th > Description</ th >
77
- < th > Arguments</ th >
73
+ < table >
74
+ < thead >
75
+ < tr >
76
+ < th > Source</ th >
77
+ < th > Permission</ th >
78
+ < th > Description</ th >
79
+ < th > Arguments</ th >
80
+ </ tr >
81
+ </ thead >
82
+ < tbody >
83
+ { commands . map ( ( c ) => (
84
+ < tr key = { `${ c . name } -${ c . permission } ` } >
85
+ < td > { c . name } </ td >
86
+ < td > { c . permission } </ td >
87
+ < td > { c . description } </ td >
88
+ < td > { c . arguments } </ td >
78
89
</ tr >
79
- </ thead >
80
- < tbody >
81
- { commands . map ( ( c ) => (
82
- < tr key = { c . name } >
83
- < td > { c . name } </ td >
84
- < td > { c . permission } </ td >
85
- < td > { c . description } </ td >
86
- < td > { c . arguments } </ td >
87
- </ tr >
88
- ) ) }
89
- </ tbody >
90
- </ table >
91
- </ div >
90
+ ) ) }
91
+ </ tbody >
92
+ </ table >
92
93
) ;
93
94
}
0 commit comments