diff --git a/packages/interface/src/components/ConnectButton.tsx b/packages/interface/src/components/ConnectButton.tsx index ae08d3f8..7c4fc5cf 100644 --- a/packages/interface/src/components/ConnectButton.tsx +++ b/packages/interface/src/components/ConnectButton.tsx @@ -1,14 +1,13 @@ import { ConnectButton as RainbowConnectButton } from "@rainbow-me/rainbowkit"; import Image from "next/image"; -import { createBreakpoint } from "react-use"; +import { useMemo } from "react"; import { config } from "~/config"; +import { useIsMobile } from "~/hooks/useIsMobile"; import { Button } from "./ui/Button"; import { Chip } from "./ui/Chip"; -const useBreakpoint = createBreakpoint({ XL: 1280, L: 768, S: 350 }); - interface IConnectedDetailsProps { account: { address: string; displayName: string; ensName?: string }; openAccountModal: () => void; @@ -31,9 +30,14 @@ const ConnectedDetails = ({ openAccountModal, account, isMobile }: IConnectedDet ); }; -export const ConnectButton = (): JSX.Element => { - const breakpoint = useBreakpoint(); - const isMobile = breakpoint === "S"; +interface IConnectButtonProps { + showMobile: boolean; +} + +export const ConnectButton = ({ showMobile }: IConnectButtonProps): JSX.Element => { + const isMobile = useIsMobile(); + + const show = useMemo(() => (showMobile && isMobile) || (!showMobile && !isMobile), [isMobile, showMobile]); return ( @@ -44,6 +48,7 @@ export const ConnectButton = (): JSX.Element => { return (
{ if (!connected) { return ( ); } @@ -70,7 +75,7 @@ export const ConnectButton = (): JSX.Element => { ); } - return ; + return ; })()}
); diff --git a/packages/interface/src/components/Header.tsx b/packages/interface/src/components/Header.tsx index 0a75ac80..67e96653 100644 --- a/packages/interface/src/components/Header.tsx +++ b/packages/interface/src/components/Header.tsx @@ -122,7 +122,7 @@ const Header = ({ navLinks, pollId = "" }: IHeaderProps) => { onClick={handleChangeTheme} /> - + diff --git a/packages/interface/src/components/Info.tsx b/packages/interface/src/components/Info.tsx index 5bb7f622..c852585a 100644 --- a/packages/interface/src/components/Info.tsx +++ b/packages/interface/src/components/Info.tsx @@ -18,7 +18,7 @@ const InfoContainer = createComponent( variants: { size: { sm: "flex-col", - default: "flex-col max-lg:w-full lg:flex-row", + default: "flex-col max-lg:w-full lg:flex-row lg:w-fit", }, }, }), @@ -73,7 +73,7 @@ export const Info = ({ ]; return ( -
+
{showRoundInfo && } diff --git a/packages/interface/src/components/SingleRoundHome.tsx b/packages/interface/src/components/SingleRoundHome.tsx new file mode 100644 index 00000000..9a758b90 --- /dev/null +++ b/packages/interface/src/components/SingleRoundHome.tsx @@ -0,0 +1,50 @@ +import { useAccount } from "wagmi"; + +import { ConnectButton } from "~/components/ConnectButton"; +import { Info } from "~/components/Info"; +import { JoinButton } from "~/components/JoinButton"; +import { Button } from "~/components/ui/Button"; +import { Heading } from "~/components/ui/Heading"; +import { useMaci } from "~/contexts/Maci"; +import { useIsMobile } from "~/hooks/useIsMobile"; +import { useRoundState } from "~/utils/state"; +import { ERoundState, type IRoundData } from "~/utils/types"; + +interface ISingleRoundHome { + round: IRoundData; +} + +export const SingleRoundHome = ({ round }: ISingleRoundHome): JSX.Element => { + const { isConnected } = useAccount(); + const { isRegistered } = useMaci(); + const isMobile = useIsMobile(); + const roundState = useRoundState({ pollId: round.pollId }); + + return ( +
+ + {round.roundId} + + +

{round.description}

+ + + + {roundState === ERoundState.RESULTS && ( + + )} + + {!isConnected && !isMobile &&

Connect your wallet to get started.

} + + {(roundState === ERoundState.APPLICATION || roundState === ERoundState.VOTING) && } + + {isConnected && !isRegistered && } + + +
+ ); +}; diff --git a/packages/interface/src/hooks/useIsMobile.ts b/packages/interface/src/hooks/useIsMobile.ts new file mode 100644 index 00000000..c017eadd --- /dev/null +++ b/packages/interface/src/hooks/useIsMobile.ts @@ -0,0 +1,8 @@ +import { createBreakpoint } from "react-use"; + +export function useIsMobile(): boolean { + const useBreakpoint = createBreakpoint({ XL: 1280, L: 768, S: 350 }); + const breakpoint = useBreakpoint(); + + return breakpoint === "S"; +} diff --git a/packages/interface/src/pages/index.tsx b/packages/interface/src/pages/index.tsx index 29287af3..82bfa681 100644 --- a/packages/interface/src/pages/index.tsx +++ b/packages/interface/src/pages/index.tsx @@ -1,6 +1,9 @@ +import { useMemo } from "react"; import { useAccount } from "wagmi"; +import { ConnectButton } from "~/components/ConnectButton"; import { JoinButton } from "~/components/JoinButton"; +import { SingleRoundHome } from "~/components/SingleRoundHome"; import { Button } from "~/components/ui/Button"; import { Heading } from "~/components/ui/Heading"; import { config } from "~/config"; @@ -16,38 +19,51 @@ const HomePage = (): JSX.Element => { const { isRegistered } = useMaci(); const isAdmin = useIsAdmin(); const { rounds } = useRound(); + const singleRound = useMemo(() => { + if (rounds && rounds.length === 1) { + return rounds[0]; + } + + return undefined; + }, [rounds]); return ( -
- - {config.eventName} - + {singleRound && } + + {!singleRound && ( +
+ + {config.eventName} + + + + {config.eventDescription} + - - {config.eventDescription} - + {!isConnected &&

Connect your wallet to get started.

} - {!isConnected &&

Connect your wallet to get started.

} + - {isConnected && !isRegistered && } + {isConnected && !isRegistered && } - {isConnected && isAdmin && ( -
-

Configure and deploy your contracts to get started.

+ {isConnected && isAdmin && ( +
+

Configure and deploy your contracts to get started.

- -
- )} + +
+ )} - {isConnected && !isAdmin && rounds && rounds.length === 0 && ( -

There are no rounds deployed.

- )} + {isConnected && !isAdmin && rounds && rounds.length === 0 && ( +

There are no rounds deployed.

+ )} - {rounds && rounds.length > 0 && } -
+ {rounds && rounds.length > 1 && } +
+ )}