From 0d5737c6f91bc4511c783191b692c5c8718a13a6 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Bart=C5=82omiej=20Sworze=C5=84?= Date: Mon, 4 Mar 2024 09:50:14 +0100 Subject: [PATCH 001/109] [#351] dashboard refactor --- govtool/frontend/index.html | 1 + .../molecules/CenteredBoxPageWrapper.tsx | 20 -- .../molecules/DashboardActionCard.tsx | 29 +-- .../components/molecules/WalletInfoCard.tsx | 85 +++---- .../src/components/organisms/BgCard.tsx | 41 +-- .../components/organisms/DashboardCards.tsx | 33 ++- .../organisms/DashboardDrawerMobile.tsx | 92 +++++++ .../components/organisms/DashboardTopNav.tsx | 238 ++++++------------ .../src/components/organisms/Drawer.tsx | 123 +++++---- .../src/components/organisms/DrawerMobile.tsx | 7 +- .../organisms/GovernanceActionsToVote.tsx | 1 - .../src/components/organisms/index.ts | 1 + .../src/components/organisms/types.ts | 12 +- govtool/frontend/src/i18n/locales/en.ts | 5 +- govtool/frontend/src/pages/Dashboard.tsx | 67 ++--- govtool/frontend/src/pages/DelegateTodRep.tsx | 25 +- govtool/frontend/src/pages/RegisterAsdRep.tsx | 29 +-- .../frontend/src/pages/UpdatedRepMetadata.tsx | 14 +- 18 files changed, 380 insertions(+), 443 deletions(-) create mode 100644 govtool/frontend/src/components/organisms/DashboardDrawerMobile.tsx diff --git a/govtool/frontend/index.html b/govtool/frontend/index.html index cdf8d5d79..ac87ebc7a 100644 --- a/govtool/frontend/index.html +++ b/govtool/frontend/index.html @@ -15,6 +15,7 @@ html, body { margin: 0; + overscroll-behavior-y: none; padding: 0; } diff --git a/govtool/frontend/src/components/molecules/CenteredBoxPageWrapper.tsx b/govtool/frontend/src/components/molecules/CenteredBoxPageWrapper.tsx index dc9cbe0da..96af6c42f 100644 --- a/govtool/frontend/src/components/molecules/CenteredBoxPageWrapper.tsx +++ b/govtool/frontend/src/components/molecules/CenteredBoxPageWrapper.tsx @@ -31,9 +31,6 @@ export const CenteredBoxPageWrapper: FC> = ({ @@ -41,25 +38,8 @@ export const CenteredBoxPageWrapper: FC> = ({ display={"flex"} justifyContent={"center"} flexDirection={"column"} - mt={isMobile ? 0 : 7} height={isMobile ? "100%" : "auto"} - sx={{ marginTop: "97px" }} > - {isMobile && ( - - - {pageTitle} - - - )} = ({ flex={1} flexDirection="column" p={3} + maxWidth={524} position="relative" sx={{ boxShadow: `5px 5px 15px 5px ${boxShadow2}` }} > @@ -192,15 +193,7 @@ export const DashboardActionCard: FC = ({ ) : ( {firstButtonLabel ? ( = ({ size="large" variant={firstButtonVariant} sx={{ - mr: - screenWidth < 768 - ? 0 - : screenWidth < 1024 && secondButtonLabel - ? 2 - : screenWidth >= 1440 && secondButtonLabel - ? 2 - : 0, + mr: screenWidth < 640 ? 0 : 2, width: isMobile ? "100%" : "auto", }} > @@ -234,14 +220,7 @@ export const DashboardActionCard: FC = ({ variant={secondButtonVariant} sx={{ width: isMobile ? "100%" : "auto", - marginTop: - screenWidth < 768 - ? 1 - : screenWidth < 1024 - ? 0 - : screenWidth < 1440 - ? 1 - : 0, + marginTop: screenWidth < 640 ? 1 : 0, }} > {secondButtonLabel} diff --git a/govtool/frontend/src/components/molecules/WalletInfoCard.tsx b/govtool/frontend/src/components/molecules/WalletInfoCard.tsx index 528dc4b3b..d1ab3ef11 100644 --- a/govtool/frontend/src/components/molecules/WalletInfoCard.tsx +++ b/govtool/frontend/src/components/molecules/WalletInfoCard.tsx @@ -3,75 +3,54 @@ import { Box, Button, Typography } from "@mui/material"; import { PATHS } from "@consts"; import { useCardano } from "@context"; -import { theme } from "@/theme"; import { useTranslation } from "@hooks"; export const WalletInfoCard = () => { - const { address, disconnectWallet, isMainnet } = useCardano(); + const { address, disconnectWallet } = useCardano(); const navigate = useNavigate(); const { t } = useTranslation(); - const { - palette: { lightBlue }, - } = theme; + + const onClickDisconnect = async () => { + await disconnectWallet(); + navigate(PATHS.home); + window.location.reload(); + }; return ( address && ( - - - {isMainnet ? "mainnet" : "testnet"} - - - + {t("wallet.connectedWallet")} - + {address} - - - + ) diff --git a/govtool/frontend/src/components/organisms/BgCard.tsx b/govtool/frontend/src/components/organisms/BgCard.tsx index 638acd9cb..b430eb205 100644 --- a/govtool/frontend/src/components/organisms/BgCard.tsx +++ b/govtool/frontend/src/components/organisms/BgCard.tsx @@ -72,37 +72,40 @@ export const BgCard = ({ return ( = 768 ? "center" : "inherit", display: "flex", flex: 1, flexDirection: "column", - marginTop: isMobile ? "97px" : "137px", + height: isMobile ? "100%" : "auto", }} > 768 ? 600 : undefined} - mb={isMobile ? undefined : 3} - pb={isMobile ? undefined : 10} - pt={isMobile ? 6 : 10} - px={isMobile ? 2 : 18.75} - sx={sx} + sx={{ + borderRadius: "20px", + boxShadow: isMobile ? "" : `2px 2px 20px 0px ${boxShadow2}`, + display: "flex", + flex: isMobile ? 1 : undefined, + flexDirection: "column", + height: "auto", + maxWidth: screenWidth > 768 ? 600 : undefined, + my: isMobile ? undefined : 3, + pb: isMobile ? undefined : 10, + pt: isMobile ? 6 : 10, + px: isMobile ? 2 : 18.75, + ...sx, + }} > - + {children} {renderBackButton} {renderContinueButton} diff --git a/govtool/frontend/src/components/organisms/DashboardCards.tsx b/govtool/frontend/src/components/organisms/DashboardCards.tsx index 73208b3cb..64075b3a8 100644 --- a/govtool/frontend/src/components/organisms/DashboardCards.tsx +++ b/govtool/frontend/src/components/organisms/DashboardCards.tsx @@ -32,7 +32,7 @@ export const DashboardCards = () => { const navigate = useNavigate(); const { currentDelegation, isCurrentDelegationLoading } = useGetAdaHolderCurrentDelegationQuery(stakeKey); - const { screenWidth } = useScreenDimension(); + const { isMobile, screenWidth } = useScreenDimension(); const { openModal } = useModal(); const [isRetirementLoading, setIsRetirementLoading] = useState(false); @@ -306,22 +306,31 @@ export const DashboardCards = () => { return isDrepLoading ? ( ) : ( 1728 + ? "repeat(3, minmax(300px, 572px))" + : "repeat(2, minmax(300px, 572px))", + px: isMobile ? 2 : 5, + py: 3, + rowGap: 3, + }} > {/* DELEGATION CARD */} { + const { screenWidth } = useScreenDimension(); + const { voter } = useCardano(); + + const openDrawer = () => { + setIsDrawerOpen(true); + }; + + const closeDrawer = () => { + setIsDrawerOpen(false); + }; + + return ( + + + + + + + + + + + + {CONNECTED_NAV_ITEMS.map((navItem) => ( + + { + navItem.newTabLink && openInNewTab(navItem.newTabLink); + setIsDrawerOpen(false); + }} + isConnectWallet + /> + + ))} + + + {(voter?.isRegisteredAsDRep || voter?.isRegisteredAsSoleVoter) && ( + + )} + + + + + + ); +}; diff --git a/govtool/frontend/src/components/organisms/DashboardTopNav.tsx b/govtool/frontend/src/components/organisms/DashboardTopNav.tsx index 00f44fedd..bcfb5baaa 100644 --- a/govtool/frontend/src/components/organisms/DashboardTopNav.tsx +++ b/govtool/frontend/src/components/organisms/DashboardTopNav.tsx @@ -1,181 +1,97 @@ -import { useState } from "react"; -import { useNavigate } from "react-router-dom"; -import { Box, Grid, IconButton, SwipeableDrawer } from "@mui/material"; +import { useEffect, useState } from "react"; +import { Box, IconButton } from "@mui/material"; -import { Background, Link, VotingPowerChips, Typography } from "@atoms"; -import { useScreenDimension, useTranslation } from "@hooks"; -import { ICONS, PATHS } from "@consts"; -import { useCardano } from "@context"; -import { DRepInfoCard, WalletInfoCard } from "@molecules"; -import { openInNewTab } from "@utils"; +import { VotingPowerChips, Typography } from "@atoms"; +import { ICONS } from "@consts"; +import { useScreenDimension } from "@hooks"; +import { DashboardDrawerMobile } from "@organisms"; type DashboardTopNavProps = { - imageSRC?: string; - imageWidth?: number; - imageHeight?: number; title: string; - isDrawer?: boolean; isVotingPowerHidden?: boolean; }; -const DRAWER_PADDING = 2; -const CALCULATED_DRAWER_PADDING = DRAWER_PADDING * 8 * 2; +const POSITION_TO_BLUR = 50; export const DashboardTopNav = ({ title, - imageSRC, - imageWidth, - imageHeight, isVotingPowerHidden, }: DashboardTopNavProps) => { - const { isMobile, screenWidth } = useScreenDimension(); - const { voter } = useCardano(); - const navigate = useNavigate(); + const [windowScroll, setWindowScroll] = useState(0); + const { isMobile } = useScreenDimension(); const [isDrawerOpen, setIsDrawerOpen] = useState(false); - const { t } = useTranslation(); + + const openDrawer = () => { + setIsDrawerOpen(true); + }; + + useEffect(() => { + const onScroll = () => { + setWindowScroll(window.scrollY); + }; + + window.addEventListener("scroll", onScroll, { + passive: true, + }); + + return () => window.removeEventListener("scroll", onScroll); + }, []); return ( - - - {imageSRC ? ( - { - navigate(PATHS.dashboard); - }} - > - - - ) : null} - {!isMobile && title ? ( - {title} - ) : null} - - - {!isVotingPowerHidden && } + <> + POSITION_TO_BLUR + ? "rgba(256, 256, 256, 0.7)" + : isMobile + ? "#FBFBFF59" + : "transparent", + borderBottom: "1px solid #D6E2FF", + display: "flex", + justifyContent: "space-between", + position: "sticky", + px: isMobile ? 2 : 5, + py: 3, + top: 0, + width: "fill-available", + zIndex: 100, + }} + > + + {isMobile ? ( + + ) : null} + {!isMobile && title ? ( + {title} + ) : null} + + + {!isVotingPowerHidden && } + {isMobile && ( + + + + )} + {isMobile && ( - setIsDrawerOpen(true)} - > - - + )} - {isMobile && ( - setIsDrawerOpen(false)} - onOpen={() => setIsDrawerOpen(true)} - > - - - - - - setIsDrawerOpen(false)} - > - - - - - - { - setIsDrawerOpen(false); - }} - isConnectWallet - /> - - - { - setIsDrawerOpen(false); - }} - isConnectWallet - /> - - - { - openInNewTab( - "https://docs.sanchogov.tools/about/what-is-sanchonet-govtool" - ); - setIsDrawerOpen(false); - }} - isConnectWallet - /> - - - { - openInNewTab("https://docs.sanchogov.tools/faqs"); - setIsDrawerOpen(false); - }} - isConnectWallet - /> - - - - {(voter?.isRegisteredAsDRep || - voter?.isRegisteredAsSoleVoter) && } - - - - - - )} - + {isMobile && title ? ( + + {title} + + ) : null} + ); }; diff --git a/govtool/frontend/src/components/organisms/Drawer.tsx b/govtool/frontend/src/components/organisms/Drawer.tsx index 914674bda..4eb123f5e 100644 --- a/govtool/frontend/src/components/organisms/Drawer.tsx +++ b/govtool/frontend/src/components/organisms/Drawer.tsx @@ -4,84 +4,81 @@ import { NavLink } from "react-router-dom"; import { DrawerLink, Typography } from "@atoms"; import { CONNECTED_NAV_ITEMS, ICONS, IMAGES, PATHS } from "@consts"; import { useCardano } from "@context"; -import { WalletInfoCard, DRepInfoCard } from "@molecules"; -import { openInNewTab } from "@/utils"; import { useTranslation } from "@hooks"; +import { WalletInfoCard, DRepInfoCard } from "@molecules"; +import { openInNewTab } from "@utils"; export const Drawer = () => { const { voter } = useCardano(); const { t } = useTranslation(); return ( - - + + + + - - - - - {CONNECTED_NAV_ITEMS.map((navItem) => ( - - openInNewTab(navItem.newTabLink) - : undefined - } - /> - - ))} - - - {voter?.isRegisteredAsDRep && } - - - + {CONNECTED_NAV_ITEMS.map((navItem) => ( + - openInNewTab( - "https://docs.sanchogov.tools/support/get-help-in-discord" - ) + {...navItem} + onClick={ + navItem.newTabLink + ? () => openInNewTab(navItem.newTabLink) + : undefined } /> - - - {t("footer.copyright")} - + + ))} + + + {voter?.isRegisteredAsDRep && } + + + + + openInNewTab( + "https://docs.sanchogov.tools/support/get-help-in-discord" + ) + } + /> + + {t("footer.copyright")} + ); diff --git a/govtool/frontend/src/components/organisms/DrawerMobile.tsx b/govtool/frontend/src/components/organisms/DrawerMobile.tsx index 9357c396a..9dbd14c09 100644 --- a/govtool/frontend/src/components/organisms/DrawerMobile.tsx +++ b/govtool/frontend/src/components/organisms/DrawerMobile.tsx @@ -1,4 +1,3 @@ -import { Dispatch, SetStateAction } from "react"; import { Box, Grid, IconButton, SwipeableDrawer } from "@mui/material"; import { Background, Button, Link } from "../atoms"; @@ -7,11 +6,7 @@ import { useScreenDimension, useTranslation } from "@hooks"; import { useModal } from "@context"; import { openInNewTab } from "@utils"; -type DrawerMobileProps = { - isConnectButton: boolean; - isDrawerOpen: boolean; - setIsDrawerOpen: Dispatch>; -}; +import { DrawerMobileProps } from "./types"; const DRAWER_PADDING = 2; const CALCULATED_DRAWER_PADDING = DRAWER_PADDING * 8 * 2; diff --git a/govtool/frontend/src/components/organisms/GovernanceActionsToVote.tsx b/govtool/frontend/src/components/organisms/GovernanceActionsToVote.tsx index 914e09861..7058ce106 100644 --- a/govtool/frontend/src/components/organisms/GovernanceActionsToVote.tsx +++ b/govtool/frontend/src/components/organisms/GovernanceActionsToVote.tsx @@ -6,7 +6,6 @@ import { Slider } from "./Slider"; import { Typography } from "@atoms"; import { - useGetDRepVotesQuery, useGetProposalsQuery, useScreenDimension, useTranslation, diff --git a/govtool/frontend/src/components/organisms/index.ts b/govtool/frontend/src/components/organisms/index.ts index 5387a425c..9b7ee74ce 100644 --- a/govtool/frontend/src/components/organisms/index.ts +++ b/govtool/frontend/src/components/organisms/index.ts @@ -4,6 +4,7 @@ export * from "./ChooseWalletModal"; export * from "./ControlledField"; export * from "./DashboardCards"; export * from "./DashboardCards"; +export * from "./DashboardDrawerMobile"; export * from "./DashboardGovernanceActionDetails"; export * from "./DashboardGovernanceActions"; export * from "./DashboardGovernanceActionsVotedOn"; diff --git a/govtool/frontend/src/components/organisms/types.ts b/govtool/frontend/src/components/organisms/types.ts index 0eaad74af..4207dd2db 100644 --- a/govtool/frontend/src/components/organisms/types.ts +++ b/govtool/frontend/src/components/organisms/types.ts @@ -1,12 +1,22 @@ import { SxProps } from "@mui/material"; +import { Dispatch, SetStateAction } from "react"; export type BgCardProps = { actionButtonLabel: string; backButtonLabel?: string; children: React.ReactNode; isLoadingActionButton?: boolean; - isActionButtonDisabled?:boolean; + isActionButtonDisabled?: boolean; onClickBackButton?: () => void; onClickActionButton: () => void; sx?: SxProps; }; + +export type DashboardDrawerMobileProps = { + isDrawerOpen: boolean; + setIsDrawerOpen: Dispatch>; +}; + +export type DrawerMobileProps = DashboardDrawerMobileProps & { + isConnectButton: boolean; +}; diff --git a/govtool/frontend/src/i18n/locales/en.ts b/govtool/frontend/src/i18n/locales/en.ts index f205ffcca..8fdb3278f 100644 --- a/govtool/frontend/src/i18n/locales/en.ts +++ b/govtool/frontend/src/i18n/locales/en.ts @@ -45,6 +45,7 @@ export const en = { dashboard: { headingOne: "Your Participation", headingTwo: "See Active Governance Actions", + title: "Dashboard", delegation: { changeDelegation: "Change delegation", delegateOwnPower: @@ -265,7 +266,7 @@ export const en = { faqs: "FAQs", guides: "Guides", help: "Help", - myDashboard: "My Dashboard", + dashboard: "Dashboard", viewGovActions: "View Governance Actions", }, metadataUpdate: { @@ -433,7 +434,7 @@ export const en = { nextStep: "Next step", no: "No", ok: "Ok", - register:"Register", + register: "Register", seeTransaction: "See transaction", select: "Select", skip: "Skip", diff --git a/govtool/frontend/src/pages/Dashboard.tsx b/govtool/frontend/src/pages/Dashboard.tsx index 7899270cc..992897916 100644 --- a/govtool/frontend/src/pages/Dashboard.tsx +++ b/govtool/frontend/src/pages/Dashboard.tsx @@ -1,22 +1,13 @@ -import { Box } from "@mui/material"; import { useEffect, useRef } from "react"; import { useLocation, Outlet, useNavigate } from "react-router-dom"; +import { Box } from "@mui/material"; -import { ICONS, PATHS } from "@consts"; -import { useCardano } from "@context"; import { Background, ScrollToManage } from "@atoms"; -import { useScreenDimension } from "@hooks"; +import { PATHS } from "@consts"; +import { useCardano } from "@context"; +import { useScreenDimension, useTranslation } from "@hooks"; import { DashboardTopNav, Drawer, Footer } from "@organisms"; -import { checkIsWalletConnected } from "@/utils"; - -const getPageTitle = (pathname: string) => { - if (pathname === PATHS.dashboard) { - return "My Dashboard"; - } else if (pathname.includes(PATHS.dashboard_governance_actions)) { - return "Governance Actions"; - } - return ""; -}; +import { checkIsWalletConnected } from "@utils"; export const Dashboard = () => { const { isEnabled, stakeKey } = useCardano(); @@ -24,6 +15,16 @@ export const Dashboard = () => { const { pathname, hash } = useLocation(); const divRef = useRef(null); const navigate = useNavigate(); + const { t } = useTranslation(); + + const getPageTitle = (pathname: string) => { + if (pathname === PATHS.dashboard) { + return t("dashboard.title"); + } else if (pathname.includes(PATHS.dashboard_governance_actions)) { + return t("dashboard.govActions.title"); + } + return ""; + }; useEffect(() => { if (divRef.current) { @@ -46,35 +47,21 @@ export const Dashboard = () => { return ( - + {isMobile ? null : } - - - - - + + + {isMobile ?