diff --git a/packages/interface/src/components/ConnectButton.tsx b/packages/interface/src/components/ConnectButton.tsx index ae08d3f8..10e00a73 100644 --- a/packages/interface/src/components/ConnectButton.tsx +++ b/packages/interface/src/components/ConnectButton.tsx @@ -1,14 +1,14 @@ import { ConnectButton as RainbowConnectButton } from "@rainbow-me/rainbowkit"; +import dynamic from "next/dynamic"; 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,11 +31,16 @@ const ConnectedDetails = ({ openAccountModal, account, isMobile }: IConnectedDet ); }; -export const ConnectButton = (): JSX.Element => { - const breakpoint = useBreakpoint(); - const isMobile = breakpoint === "S"; +interface IConnectButtonProps { + showMobile: boolean; +} + +const ConnectButton = ({ showMobile }: IConnectButtonProps): JSX.Element | null => { + const isMobile = useIsMobile(); - return ( + const isShow = useMemo(() => showMobile === isMobile, [isMobile, showMobile]); + + return isShow ? ( {({ account, chain, openAccountModal, openChainModal, openConnectModal, mounted, authenticationStatus }) => { const ready = mounted && authenticationStatus !== "loading"; @@ -57,7 +62,7 @@ export const ConnectButton = (): JSX.Element => { if (!connected) { return ( ); } @@ -70,11 +75,13 @@ export const ConnectButton = (): JSX.Element => { ); } - return ; + return ; })()} ); }} - ); + ) : null; }; + +export default dynamic(async () => Promise.resolve(ConnectButton), { ssr: false }); diff --git a/packages/interface/src/components/Header.tsx b/packages/interface/src/components/Header.tsx index 0a75ac80..0e232954 100644 --- a/packages/interface/src/components/Header.tsx +++ b/packages/interface/src/components/Header.tsx @@ -10,7 +10,7 @@ import { useBallot } from "~/contexts/Ballot"; import { useRoundState } from "~/utils/state"; import { ERoundState } from "~/utils/types"; -import { ConnectButton } from "./ConnectButton"; +import ConnectButton from "./ConnectButton"; import { IconButton } from "./ui/Button"; import { Logo } from "./ui/Logo"; @@ -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..78ad4db8 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 xl:flex-row xl: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..f312d2cc --- /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 ISingleRoundHomeProps { + round: IRoundData; +} + +export const SingleRoundHome = ({ round }: ISingleRoundHomeProps): 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..5e102ac2 --- /dev/null +++ b/packages/interface/src/hooks/useIsMobile.ts @@ -0,0 +1,15 @@ +import { createBreakpoint } from "react-use"; + +import { EBreakpointSizes } from "~/utils/types"; + +export function useIsMobile(): boolean { + const useBreakpoint = createBreakpoint({ + XL: EBreakpointSizes.XL, + L: EBreakpointSizes.L, + M: EBreakpointSizes.M, + S: EBreakpointSizes.S, + }); + const breakpoint = useBreakpoint(); + + return breakpoint === "S"; +} diff --git a/packages/interface/src/pages/index.tsx b/packages/interface/src/pages/index.tsx index 29287af3..bf9a5dba 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,45 @@ const HomePage = (): JSX.Element => { const { isRegistered } = useMaci(); const isAdmin = useIsAdmin(); const { rounds } = useRound(); + const singleRound = useMemo(() => rounds?.[0], [rounds]); return ( - -
- - {config.eventName} - + + {singleRound && } - - {config.eventDescription} - + {!singleRound && ( +
+ + {config.eventName} + - {!isConnected &&

Connect your wallet to get started.

} + + {config.eventDescription} + - {isConnected && !isRegistered && } + {!isConnected &&

Connect your wallet to get started.

} - {isConnected && isAdmin && ( -
-

Configure and deploy your contracts to get started.

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

There are no rounds deployed.

- )} + {isConnected && isAdmin && ( +
+

Configure and deploy your contracts to get started.

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

There are no rounds deployed.

+ )} + + {rounds && rounds.length > 1 && } +
+ )}
diff --git a/packages/interface/src/utils/types.ts b/packages/interface/src/utils/types.ts index 801f0d91..ab9a9a36 100644 --- a/packages/interface/src/utils/types.ts +++ b/packages/interface/src/utils/types.ts @@ -16,6 +16,13 @@ export enum EInfoCardState { UPCOMING = "UPCOMING", } +export enum EBreakpointSizes { + S = 320, + M = 480, + L = 768, + XL = 1280, +} + export interface AttestationWithMetadata { id: string; refUID: string; diff --git a/packages/subgraph/package.json b/packages/subgraph/package.json index 22fce076..5a6d8a50 100644 --- a/packages/subgraph/package.json +++ b/packages/subgraph/package.json @@ -18,7 +18,7 @@ "generate:schema": "cp ./schemas/schema.${VERSION:-v1}.graphql schema.graphql", "prebuild": "pnpm codegen", "build": "graph build", - "deploy": "graph deploy --node https://api.studio.thegraph.com/deploy/ maci", + "deploy": "graph deploy --node https://api.studio.thegraph.com/deploy/ maci-subgraph", "create-local": "graph create --node http://localhost:8020/ maci-subgraph", "remove-local": "graph remove --node http://localhost:8020/ maci-subgraph", "deploy-local": "graph deploy --node http://localhost:8020/ --ipfs http://localhost:5001 maci-subgraph --network localhost",