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

Better handling of the plugin loading #70

Merged
merged 3 commits into from
Feb 20, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 5 additions & 5 deletions .github/workflows/pull_request_webapp_preview.yml
Original file line number Diff line number Diff line change
Expand Up @@ -15,12 +15,12 @@ jobs:
run: bun run build
env:
# NEXT_PUBLIC_DAO_ADDRESS: ${{secrets.DAO_ADDRESS}}
NEXT_PUBLIC_DAO_ADDRESS: 0x1234567890123456789012345678901234567890
NEXT_PUBLIC_TOKEN_ADDRESS: 0x1234567890123456789012345678901234567890
NEXT_PUBLIC_DAO_ADDRESS: "0x1234567890123456789012345678901234567890"
NEXT_PUBLIC_TOKEN_ADDRESS: "0x1234567890123456789012345678901234567890"
NEXT_PUBLIC_DELEGATION_ANNOUNCEMENTS_START_BLOCK: 1234567
NEXT_PUBLIC_TOKEN_VOTING_PLUGIN_ADDRESS: 0x1234567890123456789012345678901234567890
NEXT_PUBLIC_DELEGATION_CONTRACT_ADDRESS: 0x1234567890123456789012345678901234567890
NEXT_PUBLIC_DUAL_GOVERNANCE_PLUGIN_ADDRESS: 0x1234567890123456789012345678901234567890
NEXT_PUBLIC_TOKEN_VOTING_PLUGIN_ADDRESS: "0x1234567890123456789012345678901234567890"
NEXT_PUBLIC_DELEGATION_CONTRACT_ADDRESS: "0x1234567890123456789012345678901234567890"
NEXT_PUBLIC_DUAL_GOVERNANCE_PLUGIN_ADDRESS: "0x1234567890123456789012345678901234567890"
NEXT_PUBLIC_CHAIN_NAME: goerli
NEXT_PUBLIC_WEB3_URL_PREFIX: https://rpc/
NEXT_PUBLIC_ALCHEMY_API_KEY: x
Expand Down
34 changes: 15 additions & 19 deletions pages/plugins/[id].tsx
Original file line number Diff line number Diff line change
Expand Up @@ -6,42 +6,38 @@ import { NotFound } from "@/components/not-found";
import { plugins } from "@/plugins";

const PluginLoader: FC = () => {
const { query, push } = useRouter();
const { query } = useRouter();
const pluginId = resolveQueryParam(query.id);
const [PageComponent, setPageComponent] = useState<FC | null>(null);
const [showNotFoundError, setShowNotFoundError] = useState(false);
const [componentLoading, setComponentLoading] = useState(true);

useEffect(() => {
if (!pluginId || typeof pluginId !== "string") {
push("/");
return;
}
if (!pluginId) return;

const plugin = plugins.find((p) => p.id === pluginId);
if (!plugin) {
push("/");
return;
}
if (!plugin) return;

import(`@/plugins/${plugin.folderName}`)
.then((mod) => {
setShowNotFoundError(false);
setComponentLoading(true);
setPageComponent(() => mod.default);
})
.catch((err) => {
console.error("Failed to load the page component", err);

setShowNotFoundError(true);
setComponentLoading(false);
});
}, [pluginId]);

if (showNotFoundError) {
if (!PageComponent) {
if (componentLoading) {
return (
<div>
<PleaseWaitSpinner />
</div>
);
}
return <NotFound />;
} else if (!PageComponent) {
return (
<div>
<PleaseWaitSpinner />
</div>
);
}

return <PageComponent />;
Expand Down
Loading