Skip to content

Commit

Permalink
Merge pull request #1444 from IntersectMBO/fix/1436-pdf-show-all-back…
Browse files Browse the repository at this point in the history
…-to-proposal-discussion-error-404-appears-when-loading-applogosvg

fix(#1436): fix 404 on navigating back on proposal discussion
  • Loading branch information
MSzalowski authored Jul 1, 2024
2 parents 54dfbc6 + cb6eeb9 commit 858f8c9
Show file tree
Hide file tree
Showing 12 changed files with 81 additions and 165 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -106,6 +106,7 @@ changes.
- Fix displaying the GA Markdowns [Issue 1244](https://github.com/IntersectMBO/govtool/issues/1244)
- Fix app crash on voting on the GA without the connected wallet before [Issue 1313](https://github.com/IntersectMBO/govtool/issues/1313)
- Fix the navigation to Home from Proposal pillar on disconnected wallet [Issue 1355](https://github.com/IntersectMBO/govtool/issues/1355)
- Fix navigation over Proposal discussion forum pillar [Issue 1436](https://github.com/IntersectMBO/govtool/issues/1436)

### Changed

Expand Down
21 changes: 2 additions & 19 deletions govtool/frontend/src/App.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -80,23 +80,6 @@ export default () => {
checkTheWalletIsActive();
}, [checkTheWalletIsActive]);

// Proposal Discussion Pillar doesn't export pages or react router routes
// so we need to handle the routing here
useEffect(() => {
if (!isProposalDiscussionForumEnabled) return;
if (
window.location.pathname.includes(PDF_PATHS.proposalDiscussion) &&
!window.location.pathname.includes(PATHS.proposalPillar.replace("/*", ""))
) {
navigate(
`${(isEnabled
? PATHS.connectedProposalPillar
: PATHS.proposalPillar
).replace("/*", "")}${window.location.pathname}`,
);
}
}, [window.location.pathname]);

return (
<>
<ScrollToTop />
Expand All @@ -113,15 +96,15 @@ export default () => {
/>
{isProposalDiscussionForumEnabled && !isEnabled && (
<Route
path={PATHS.proposalPillar}
path={`${PDF_PATHS.proposalDiscussion}/*`}
element={<ProposalDiscussionPillar />}
/>
)}
<Route element={<Dashboard />}>
<Route path={PATHS.dashboard} element={<DashboardCards />} />
{isProposalDiscussionForumEnabled && (
<Route
path={PATHS.connectedProposalPillar}
path={`${PDF_PATHS.proposalDiscussion}/*`}
element={<ProposalDiscussionPillar />}
/>
)}
Expand Down
87 changes: 34 additions & 53 deletions govtool/frontend/src/components/atoms/DrawerLink.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@ import { FC } from "react";
import { NavLink } from "react-router-dom";

import { theme } from "@/theme";
import { PATHS, PDF_PATHS } from "@/consts";

type LinkProps = {
label: string;
Expand All @@ -14,16 +13,6 @@ type LinkProps = {
onClick?: () => void;
};

const isRouteActive = (isActive: boolean, route: string) =>
isActive ||
(route ===
`${PATHS.proposalPillar.replace("/*", "")}${
PDF_PATHS.proposalDiscussion
}` &&
Object.values(PDF_PATHS).some((pdfPath) =>
window.location.pathname.includes(pdfPath),
));

export const DrawerLink: FC<LinkProps> = ({ ...props }) => {
const { dataTestId, label, navTo, icon, activeIcon, onClick } = props;
const {
Expand All @@ -37,49 +26,41 @@ export const DrawerLink: FC<LinkProps> = ({ ...props }) => {
onClick={() => {
if (onClick) onClick();
}}
style={({ isActive: routeIsActive }) => {
// Workaround for the PDF routes not being handled by react-router
const isActive = isRouteActive(routeIsActive, navTo);
return {
textDecoration: "none",
backgroundColor: isActive ? highlightBlue : "transparent",
padding: "8px 16px",
display: "block",
borderRadius: 100,
};
}}
style={({ isActive }) => ({
textDecoration: "none",
backgroundColor: isActive ? highlightBlue : "transparent",
padding: "8px 16px",
display: "block",
borderRadius: 100,
})}
>
{({ isActive: routeIsActive }) => {
// Workaround for the PDF routes not being handled by react-router
const isActive = isRouteActive(routeIsActive, navTo);
return (
<Box display="flex">
{activeIcon &&
icon &&
typeof icon === "string" &&
typeof activeIcon === "string" ? (
<img
alt="icon"
src={isActive ? activeIcon : icon}
style={{ marginRight: "12px" }}
/>
) : (
<Box marginRight="12px" height="20px" width="20px">
{isActive ? activeIcon : icon}
</Box>
)}
<Typography
fontSize={14}
lineHeight="20px"
sx={{
fontWeight: isActive ? 500 : 400,
}}
>
{label}
</Typography>
</Box>
);
}}
{({ isActive }) => (
<Box display="flex">
{activeIcon &&
icon &&
typeof icon === "string" &&
typeof activeIcon === "string" ? (
<img
alt="icon"
src={isActive ? activeIcon : icon}
style={{ marginRight: "12px" }}
/>
) : (
<Box marginRight="12px" height="20px" width="20px">
{isActive ? activeIcon : icon}
</Box>
)}
<Typography
fontSize={14}
lineHeight="20px"
sx={{
fontWeight: isActive ? 500 : 400,
}}
>
{label}
</Typography>
</Box>
)}
</NavLink>
);
};
17 changes: 12 additions & 5 deletions govtool/frontend/src/components/molecules/WalletInfoCard.tsx
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import { useLocation, useNavigate } from "react-router-dom";
import { Box, Button, Typography } from "@mui/material";

import { PATHS, gray } from "@consts";
import { PDF_PATHS, PATHS, gray } from "@consts";
import { useCardano } from "@context";
import { useTranslation } from "@hooks";
import { Card } from "./Card";
Expand All @@ -14,11 +14,18 @@ export const WalletInfoCard = () => {

const onClickDisconnect = async () => {
await disconnectWallet();
navigate(
pathname.includes("/connected")
? `${pathname.replace("/connected", "")}${hash ?? ""}`
: PATHS.home,
const isProposalDiscussionForum = window.location.pathname.includes(
PDF_PATHS.proposalDiscussion.replace("/", ""),
);

if (!isProposalDiscussionForum) {
navigate(
pathname.includes("/connected")
? `${pathname.replace("/connected", "")}${hash ?? ""}`
: PATHS.home,
);
}

window.location.reload();
};

Expand Down
8 changes: 7 additions & 1 deletion govtool/frontend/src/components/molecules/WalletOption.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ import { FC, useCallback } from "react";
import { To, useNavigate, useLocation } from "react-router-dom";
import { Box, CircularProgress, Typography } from "@mui/material";

import { PATHS } from "@consts";
import { PATHS, PDF_PATHS } from "@consts";
import { useCardano } from "@context";
import { theme } from "@/theme";

Expand Down Expand Up @@ -32,8 +32,14 @@ export const WalletOptionButton: FC<WalletOption> = ({

const enableByWalletName = useCallback(async () => {
if (isEnableLoading) return;
const isProposalDiscussionForum = window.location.pathname.includes(
PDF_PATHS.proposalDiscussion.replace("/", ""),
);

const result = await enable(name);

if (result?.stakeKey) {
if (isProposalDiscussionForum) return;
navigate(
// eslint-disable-next-line no-unneeded-ternary
pathToNavigate
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -37,9 +37,7 @@ export const ProposeGovActionDashboardCard = ({

navigate(
isProposalDiscussionForumEnabled
? `${PATHS.proposalPillar.replace("/*", "")}${
PDF_PATHS.proposalDiscussion
}`
? PDF_PATHS.proposalDiscussion
: PATHS.createGovernanceAction,
);
}, [deposit, votingPower, isProposalDiscussionForumEnabled]);
Expand Down
7 changes: 1 addition & 6 deletions govtool/frontend/src/components/organisms/HomeCards.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -50,12 +50,7 @@ export const HomeCards = () => {
);

const navigateToProposalDiscussionPillar = useCallback(
() =>
navigate(
`${PATHS.connectedProposalPillar.replace("/*", "")}${
PDF_PATHS.proposalDiscussion
}`,
),
() => navigate(PDF_PATHS.proposalDiscussion),
[navigate],
);

Expand Down
57 changes: 0 additions & 57 deletions govtool/frontend/src/components/organisms/PDFWrapper.tsx

This file was deleted.

20 changes: 10 additions & 10 deletions govtool/frontend/src/components/organisms/TopNav.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,14 @@ export const TopNav = ({ isConnectButton = true }) => {
setIsDrawerOpen(true);
};

const onClickConnectButton = () => {
if (isEnabled && stakeKey) {
navigate(PATHS.dashboard);
} else {
openModal({ type: "chooseWallet" });
}
};

return (
<Box position="relative" py={isMobile ? 5 : 6}>
<AppBar
Expand Down Expand Up @@ -125,13 +133,7 @@ export const TopNav = ({ isConnectButton = true }) => {
<Grid item>
<Button
data-testid="connect-wallet-button"
onClick={() => {
if (isEnabled && stakeKey) {
navigate(PATHS.dashboard);
} else {
openModal({ type: "chooseWallet" });
}
}}
onClick={onClickConnectButton}
size="extraLarge"
variant="contained"
>
Expand All @@ -147,9 +149,7 @@ export const TopNav = ({ isConnectButton = true }) => {
{isConnectButton ? (
<Button
data-testid="connect-wallet-button"
onClick={() => {
openModal({ type: "chooseWallet" });
}}
onClick={onClickConnectButton}
size="small"
sx={{
marginRight: screenWidth >= 768 ? 3 : 1,
Expand Down
7 changes: 2 additions & 5 deletions govtool/frontend/src/consts/navItems.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -25,8 +25,7 @@ export const NAV_ITEMS = [
},
{
dataTestId: "proposed-governance-actions-link",
navTo:
PATHS.proposalPillar.replace("/*", "") + PDF_PATHS.proposalDiscussion,
navTo: PDF_PATHS.proposalDiscussion,
label: i18n.t("proposalDiscussion.title"),
newTabLink: null,
},
Expand Down Expand Up @@ -71,9 +70,7 @@ export const CONNECTED_NAV_ITEMS = [
{
dataTestId: "proposal-discussion-link",
label: i18n.t("proposalDiscussion.title"),
navTo: `${PATHS.connectedProposalPillar.replace("/*", "")}${
PDF_PATHS.proposalDiscussion
}`,
navTo: PDF_PATHS.proposalDiscussion,
activeIcon: (
<IconAcademicCap
width="20"
Expand Down
2 changes: 0 additions & 2 deletions govtool/frontend/src/consts/paths.ts
Original file line number Diff line number Diff line change
Expand Up @@ -24,8 +24,6 @@ export const PATHS = {
retireAsDrep: "/retire_drep",
retireAsDirectVoter: "/retire_direct_voter",
stakeKeys: "/stake_keys",
proposalPillar: "/proposal_pillar/*",
connectedProposalPillar: "/connected/proposal_pillar/*",
};

export const PDF_PATHS = {
Expand Down
Loading

0 comments on commit 858f8c9

Please sign in to comment.