From ff12773173131e51516857422736faa37037477a Mon Sep 17 00:00:00 2001 From: 0xExp-po Date: Sun, 1 Dec 2024 23:09:51 +0900 Subject: [PATCH] chore: add query params to proposal page --- .../page/governance/GovernancePageTitle.astro | 14 +++++++---- .../page/governance/ProposalCard.tsx | 12 +++++++--- .../page/governance/ProposalList.tsx | 23 ++++++++++++------- .../components/page/proposal/ProposalPage.tsx | 11 +++++++-- dapp/src/pages/governance/index.astro | 1 - dapp/src/pages/proposal/index.astro | 6 ++++- dapp/src/pages/proposal/new.astro | 12 +++++++++- 7 files changed, 59 insertions(+), 20 deletions(-) diff --git a/dapp/src/components/page/governance/GovernancePageTitle.astro b/dapp/src/components/page/governance/GovernancePageTitle.astro index cfda9728..a923cf60 100644 --- a/dapp/src/components/page/governance/GovernancePageTitle.astro +++ b/dapp/src/components/page/governance/GovernancePageTitle.astro @@ -23,14 +23,16 @@ import Topic from "../../utils/Topic.astro"; import { capitalizeFirstLetter } from "utils/utils"; document.addEventListener("astro:page-load", async () => { - projectNameForGovernance.subscribe((projectName) => { - if (projectName) { + let projectName = ""; + projectNameForGovernance.subscribe((_projectName) => { + if (_projectName) { const titleElement = document .getElementById("proposal-page-topic") ?.querySelector("span"); if (titleElement) { - titleElement.textContent = `${capitalizeFirstLetter(projectName)} Governance`; + titleElement.textContent = `${capitalizeFirstLetter(_projectName)} Governance`; } + projectName = _projectName; } }); @@ -40,7 +42,11 @@ import Topic from "../../utils/Topic.astro"; if (submitProposalButton) { submitProposalButton.addEventListener("click", () => { - navigate(`/proposal/new`); + if (projectName) { + navigate(`/proposal/new?name=${projectName}`); + } else { + alert("Project name is not provided"); + } }); } }); diff --git a/dapp/src/components/page/governance/ProposalCard.tsx b/dapp/src/components/page/governance/ProposalCard.tsx index f1c310d9..cd12d572 100644 --- a/dapp/src/components/page/governance/ProposalCard.tsx +++ b/dapp/src/components/page/governance/ProposalCard.tsx @@ -1,8 +1,10 @@ import React from "react"; import ProposalStatusShow from "./ProposalStatusShow"; -import type { ProposalCardView } from "types/proposal"; -import { calculateDateDifference } from "utils/formatTimeFunctions"; import { navigate } from "astro:transitions/client"; +import { useStore } from "@nanostores/react"; +import { calculateDateDifference } from "utils/formatTimeFunctions"; +import { projectNameForGovernance } from "utils/store"; +import type { ProposalCardView } from "types/proposal"; const ProposalCard: React.FC = ({ proposalNumber, @@ -10,10 +12,14 @@ const ProposalCard: React.FC = ({ proposalStatus, endDate, }) => { + const projectName = useStore(projectNameForGovernance); + return (
navigate(`/proposal?id=${proposalNumber}`)} + onClick={() => + navigate(`/proposal?id=${proposalNumber}&&name=${projectName}`) + } >
diff --git a/dapp/src/components/page/governance/ProposalList.tsx b/dapp/src/components/page/governance/ProposalList.tsx index 3a0087b6..1c2ad448 100644 --- a/dapp/src/components/page/governance/ProposalList.tsx +++ b/dapp/src/components/page/governance/ProposalList.tsx @@ -14,16 +14,23 @@ const ProposalList: React.FC = () => { const [proposalData, setProposalData] = useState([]); const fetchProposalData = async (_page: number) => { - const updatedProposalData = demoProposalData.map((proposal) => { - const proposalStatusView = modifyProposalStatusToView( - proposal.status, - proposal.endDate, - ); + if (projectName) { + const updatedProposalData = demoProposalData.map((proposal) => { + const proposalStatusView = modifyProposalStatusToView( + proposal.status, + proposal.endDate, + ); - return { ...proposal, status: proposalStatusView as ProposalViewStatus }; - }); + return { + ...proposal, + status: proposalStatusView as ProposalViewStatus, + }; + }); - setProposalData(updatedProposalData); + setProposalData(updatedProposalData); + } else { + alert("Project name is not provided"); + } }; useEffect(() => { diff --git a/dapp/src/components/page/proposal/ProposalPage.tsx b/dapp/src/components/page/proposal/ProposalPage.tsx index 71274d05..faa1c993 100644 --- a/dapp/src/components/page/proposal/ProposalPage.tsx +++ b/dapp/src/components/page/proposal/ProposalPage.tsx @@ -9,7 +9,11 @@ import VotersModal from "./VotersModal"; import VotingModal from "./VotingModal"; import ExecuteProposalModal from "./ExecuteProposalModal"; import { modifyProposalStatusToView } from "utils/utils"; -import { connectedPublicKey, proposalId } from "utils/store"; +import { + connectedPublicKey, + projectNameForGovernance, + proposalId, +} from "utils/store"; import { demoProposalData } from "constants/demoProposalData"; import { fetchOutcomeDataFromIPFS, @@ -24,6 +28,7 @@ import type { const ProposalPage: React.FC = () => { const id = useStore(proposalId); + const projectName = useStore(projectNameForGovernance); const connectedAddress = useStore(connectedPublicKey); const [isVotersModalOpen, setIsVotersModalOpen] = useState(false); const [isVotingModalOpen, setIsVotingModalOpen] = useState(false); @@ -61,7 +66,7 @@ const ProposalPage: React.FC = () => { } }; const getProposalDetails = async () => { - if (id) { + if (id && projectName) { const proposal = demoProposalData.find((p) => p.id === id); if (proposal) { const proposalStatusView = modifyProposalStatusToView( @@ -80,6 +85,8 @@ const ProposalPage: React.FC = () => { } else { alert("Proposal not found"); } + } else { + alert("Project name or proposal id is not provided"); } }; diff --git a/dapp/src/pages/governance/index.astro b/dapp/src/pages/governance/index.astro index 229fa38b..f5b6fd1c 100644 --- a/dapp/src/pages/governance/index.astro +++ b/dapp/src/pages/governance/index.astro @@ -24,7 +24,6 @@ import GovernancePage from "../../components/page/governance/GovernancePage.astr const projectName = urlParams.get("name") || ""; if (projectName) { projectNameForGovernance.set(projectName); - console.log("projectName:", projectName); } }); diff --git a/dapp/src/pages/proposal/index.astro b/dapp/src/pages/proposal/index.astro index d85ccb41..57befdbc 100644 --- a/dapp/src/pages/proposal/index.astro +++ b/dapp/src/pages/proposal/index.astro @@ -17,7 +17,7 @@ import ProposalPage from "../../components/page/proposal/ProposalPage.tsx"; diff --git a/dapp/src/pages/proposal/new.astro b/dapp/src/pages/proposal/new.astro index 354977db..0440787b 100644 --- a/dapp/src/pages/proposal/new.astro +++ b/dapp/src/pages/proposal/new.astro @@ -19,5 +19,15 @@ import NewProposalPage from "components/page/governance/NewProposalPage.astro";