Skip to content

Commit 1c50ad2

Browse files
committed
Refactor DynamicCommandsTable.
1 parent 8207770 commit 1c50ad2

File tree

2 files changed

+50
-47
lines changed

2 files changed

+50
-47
lines changed

components/docs/eternalcore/DynamicCommandsTable.tsx

Lines changed: 46 additions & 45 deletions
Original file line numberDiff line numberDiff line change
@@ -16,45 +16,48 @@ interface RawCommand {
1616
arguments?: string[];
1717
}
1818

19+
interface RawPermission {
20+
name?: string;
21+
permissions?: string[];
22+
descriptions?: string[];
23+
}
24+
1925
export default function DynamicCommandsTable() {
2026
const [commands, setCommands] = useState<Command[]>([]);
2127
const [loading, setLoading] = useState(true);
2228
const [error, setError] = useState<string | null>(null);
2329

2430
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")
2832
.then((res) => {
2933
if (!res.ok) throw new Error("Failed to fetch commands");
3034
return res.json();
3135
})
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))) {
3438
setError("Invalid data formatting received from server");
3539
return;
3640
}
3741

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+
);
5659

57-
setCommands(processedCommands);
60+
setCommands(combined);
5861
})
5962
.catch((e) => {
6063
setError((e as Error).message);
@@ -67,27 +70,25 @@ export default function DynamicCommandsTable() {
6770
if (!commands.length) return <div>No commands found.</div>;
6871

6972
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>
7889
</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>
9293
);
9394
}

content/docs/eternalcombat/features.mdx

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,8 @@ title: Features & Commands
33
description: Comprehensive guide to EternalCombat features, commands, and permissions
44
---
55

6+
import { AlertBox } from "../../../components/ui/alert-box";
7+
68
## 📋 Command Reference
79

810
### Basic Commands
@@ -92,6 +94,6 @@ description: Comprehensive guide to EternalCombat features, commands, and permis
9294
- **World-Specific Settings**: Per-world configuration
9395
- **Border Settings**: World border integration
9496

95-
<Alert type="info">
97+
<AlertBox type="info">
9698
Need help? Join our <a href="https://discord.gg/FQ7jmGBd6c">Discord server</a> or check our <a href="https://github.com/EternalCodeTeam/EternalCombat/issues">GitHub issues</a>.
97-
</Alert>
99+
</AlertBox>

0 commit comments

Comments
 (0)