-
-
Notifications
You must be signed in to change notification settings - Fork 0
refactor dynamic tables to accept initial data as props for improved data handling #216
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: master
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,7 @@ | ||
| import { fetchEternalCoreData } from "@/lib/docs/eternalcore-data"; | ||
| import DynamicCommandsTable from "./dynamic-commands-table"; | ||
|
|
||
| export default async function CommandsTableRSC() { | ||
| const { commands } = await fetchEternalCoreData(); | ||
| return <DynamicCommandsTable initialData={commands} />; | ||
| } |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,7 @@ | ||
| import { fetchEternalCoreData } from "@/lib/docs/eternalcore-data"; | ||
| import DynamicPlaceholdersTable from "./dynamic-placeholders-table"; | ||
|
|
||
| export default async function PlaceholdersTableRSC() { | ||
| const { placeholders } = await fetchEternalCoreData(); | ||
| return <DynamicPlaceholdersTable initialData={placeholders} />; | ||
| } |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,116 @@ | ||
| import "server-only"; | ||
|
|
||
| export interface CommandData { | ||
| name: string; | ||
| permission: string; | ||
| description: string; | ||
| arguments: string; | ||
| } | ||
|
|
||
| export interface PlaceholderData { | ||
| name: string; | ||
| description: string; | ||
| category: string; | ||
| example: string; | ||
| returnType: string; | ||
| requiresPlayer: boolean; | ||
| } | ||
|
|
||
| interface RawEternalCoreData { | ||
| commands?: Array<{ | ||
| name: string; | ||
| permissions?: string[]; | ||
| descriptions?: string[]; | ||
| arguments?: string[]; | ||
| }>; | ||
| permissions?: Array<{ | ||
| name: string; | ||
| permissions?: string[]; | ||
| descriptions?: string[]; | ||
| }>; | ||
| placeholders?: Array<{ | ||
| name: string; | ||
| description: string; | ||
| category?: string; | ||
| }>; | ||
| } | ||
|
|
||
| const REGEX_LEADING_SLASH = /^\//; | ||
|
|
||
| export async function fetchEternalCoreData() { | ||
| const [commandsRes, placeholdersRes] = await Promise.all([ | ||
| fetch( | ||
| "https://raw.githubusercontent.com/EternalCodeTeam/EternalCore/refs/heads/master/raw_eternalcore_documentation.json", | ||
| { | ||
| next: { | ||
| revalidate: 3600, | ||
| tags: ["eternalcore-data"], | ||
| }, | ||
| } | ||
| ), | ||
| fetch( | ||
| "https://raw.githubusercontent.com/EternalCodeTeam/EternalCore/refs/heads/master/raw_eternalcore_placeholders.json", | ||
| { | ||
| next: { | ||
| revalidate: 3600, | ||
| tags: ["eternalcore-placeholders"], | ||
| }, | ||
| } | ||
| ), | ||
| ]); | ||
|
|
||
| if (!commandsRes.ok) { | ||
| throw new Error("Failed to fetch EternalCore commands data"); | ||
| } | ||
|
|
||
| if (!placeholdersRes.ok) { | ||
| throw new Error("Failed to fetch EternalCore placeholders data"); | ||
| } | ||
|
|
||
| const commandsData = (await commandsRes.json()) as RawEternalCoreData; | ||
| // biome-ignore lint/suspicious/noExplicitAny: External data source | ||
| const placeholdersData = (await placeholdersRes.json()) as any[]; | ||
|
|
||
| const commandsList = | ||
| commandsData.commands?.map((c) => ({ | ||
| name: `/${c.name.trim()}`, | ||
| permission: c.permissions?.[0] ?? "-", | ||
| description: c.descriptions?.[0] ?? "-", | ||
| arguments: c.arguments?.join(", ") ?? "-", | ||
| })) ?? []; | ||
|
|
||
| const permsList = | ||
| commandsData.permissions?.map((p) => ({ | ||
| name: p.name || "Unknown", | ||
| permission: p.permissions?.[0] ?? "-", | ||
| description: p.descriptions?.[0] ?? "-", | ||
| arguments: "-", | ||
| })) ?? []; | ||
|
|
||
| const sortedCommands = [...commandsList, ...permsList].sort((a, b) => | ||
| a.name | ||
| .replace(REGEX_LEADING_SLASH, "") | ||
| .localeCompare(b.name.replace(REGEX_LEADING_SLASH, ""), "pl", { | ||
| sensitivity: "base", | ||
| }) | ||
| ); | ||
|
|
||
| const placeholders = | ||
| placeholdersData?.map((p) => ({ | ||
| name: p.name, | ||
| description: p.description, | ||
| category: p.category ?? "General", | ||
| example: p.example ?? "", | ||
| returnType: p.returnType ?? "String", | ||
| requiresPlayer: p.requiresPlayer ?? false, | ||
| })) ?? []; | ||
|
|
||
| const sortedPlaceholders = placeholders.sort((a, b: { name: string }) => | ||
| a.name.localeCompare(b.name) | ||
| ); | ||
|
Comment on lines
+108
to
+110
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. The explicit type annotation for the const sortedPlaceholders = placeholders.sort((a, b) =>
a.name.localeCompare(b.name)
); |
||
|
|
||
| return { | ||
| commands: sortedCommands, | ||
| placeholders: sortedPlaceholders, | ||
| }; | ||
| } | ||
Uh oh!
There was an error while loading. Please reload this page.