Skip to content
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

feat(explorer): front page #3255

Merged
merged 15 commits into from
Oct 9, 2024
Merged
Prev Previous commit
Next Next commit
add disableFrontPage flag
karooolis committed Oct 8, 2024
commit c9b1ec0724a52c1e7ad87f0d0c52327f595fc3bd
6 changes: 1 addition & 5 deletions packages/explorer/src/app/(explorer)/[chainName]/page.tsx
Original file line number Diff line number Diff line change
@@ -7,9 +7,5 @@ type Props = {
};

export default async function ChainPage({ params }: Props) {
const { chainName } = params;
const worldAddress = process.env.WORLD_ADDRESS;

if (worldAddress) return redirect(`/${chainName}/worlds/${worldAddress}`);
return redirect(`/${chainName}/worlds`);
return redirect(`/${params.chainName}/worlds`);
}
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import { notFound, redirect } from "next/navigation";
import { Address } from "viem";
import { supportedChains, validateChainName } from "../../../../common";
import { WorldsForm } from "./WorldsForm";
@@ -36,6 +37,12 @@ type Props = {
};

export default async function WorldsPage({ params }: Props) {
const worldAddress = process.env.WORLD_ADDRESS;
const disableFrontPage = process.env.DISABLE_FRONT_PAGE === "1";

if (worldAddress) return redirect(`/${params.chainName}/worlds/${worldAddress}`);
if (!worldAddress && disableFrontPage) return notFound();

const worlds = await fetchWorlds(params.chainName);
return <WorldsForm worlds={worlds} />;
}
3 changes: 0 additions & 3 deletions packages/explorer/src/app/(explorer)/page.tsx
Original file line number Diff line number Diff line change
@@ -7,9 +7,6 @@ export default function IndexPage() {
const chainId = Number(process.env.CHAIN_ID);
validateChainId(chainId);

const worldAddress = process.env.WORLD_ADDRESS;
const chainName = chainIdToName[chainId] ?? "anvil";

if (worldAddress) return redirect(`/${chainName}/worlds/${worldAddress}`);
return redirect(`/${chainName}/worlds`);
}
16 changes: 12 additions & 4 deletions packages/explorer/src/bin/explorer.ts
Original file line number Diff line number Diff line change
@@ -56,14 +56,20 @@ const argv = yargs(process.argv.slice(2))
type: "string",
default: process.env.WORLD_ADDRESS,
},
disableFrontPage: {
alias: "f",
description: "Disable the entry page and redirect to the Explorer",
type: "boolean",
default: true,
},
})
.check((argv) => {
validateChainId(Number(argv.chainId));
return true;
})
.parseSync();

const { port, hostname, chainId, indexerDatabase, worldsFile, dev } = argv;
const { port, hostname, chainId, indexerDatabase, worldsFile, dev, disableFrontPage } = argv;
const indexerDatabasePath = path.join(packageRoot, indexerDatabase);

let worldAddress = argv.worldAddress;
@@ -76,6 +82,7 @@ async function startExplorer() {
CHAIN_ID: chainId.toString(),
WORLD_ADDRESS: worldAddress?.toString(),
INDEXER_DATABASE: indexerDatabasePath,
DISABLE_FRONT_PAGE: disableFrontPage ? "1" : "0",
};

if (dev) {
@@ -173,8 +180,9 @@ process.on("exit", () => {
});

async function main() {
// If world address is not provided, try to read it from worlds.json
if (!worldAddress) {
// If world address is not provided, try to read it from worldsFile.
// Provided worldAddress or worldsFile is only required if entry page is disabled.
if (disableFrontPage && !worldAddress) {
worldAddress = await readWorldsJson();

// If world address is still not found, throw an error
@@ -184,7 +192,7 @@ async function main() {
);
}

// only watch worlds.json if world address was not provided with --worldAddress
// only watch worldsFile if world address was not provided with --worldAddress
watchWorldsJson();
}