Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Handling modal windows #70

Merged
merged 25 commits into from
Dec 20, 2023
Merged
Show file tree
Hide file tree
Changes from 7 commits
Commits
Show all changes
25 commits
Select commit Hold shift + click to select a range
bdd3623
Handle of modal window for stake/unstake actions
kkosiorowska Dec 8, 2023
7cd3446
Open the docs drawer by button
kkosiorowska Dec 8, 2023
e32f154
Add basic styles for the Modal, Drawer, Sidebar
kkosiorowska Dec 11, 2023
4be5fce
Merge branch 'main' of github.com:thesis/acre into handling-modal-window
kkosiorowska Dec 11, 2023
9f2e4c1
Merge branch 'main' of github.com:thesis/acre into handling-modal-window
kkosiorowska Dec 11, 2023
8cbb73b
Use variables for colors
kkosiorowska Dec 11, 2023
0892776
Fix a eslint issue
kkosiorowska Dec 11, 2023
1d4e834
Fix for incorrect colors
kkosiorowska Dec 12, 2023
dcac86c
Change the approach to opening modals
kkosiorowska Dec 14, 2023
567d04a
Merge branch 'main' of github.com:thesis/acre into handling-modal-window
kkosiorowska Dec 14, 2023
bb9bb62
Fix issues for eslint
kkosiorowska Dec 14, 2023
7ee5708
Define a new color
kkosiorowska Dec 14, 2023
4ebb61a
Create a multi-style config for Sidebar
kkosiorowska Dec 14, 2023
6b6b3ef
Add a missing comma
kkosiorowska Dec 14, 2023
5868aab
Return an activeStep as a number
kkosiorowska Dec 14, 2023
45bd3a7
Remove unnecessary overwriting for zIndices
kkosiorowska Dec 14, 2023
f74104e
Move a `ModalCloseButton` to `ModalBase`
kkosiorowska Dec 15, 2023
eebd8a6
Use a `useBoolean` to open the staking modal
kkosiorowska Dec 15, 2023
94c2e9c
Keep all staking-related modals in one dir
kkosiorowska Dec 15, 2023
ba3298b
Simplify style definitions
kkosiorowska Dec 15, 2023
0d3e971
Merge branch 'main' of github.com:thesis/acre into handling-modal-window
kkosiorowska Dec 15, 2023
e57f802
Rename from `Staking` to `StakingModal `
kkosiorowska Dec 19, 2023
81d7de5
Update the `Sidebar` component.
kkosiorowska Dec 19, 2023
8c5fd08
Use a `semanticTokens` to declare header height
kkosiorowska Dec 19, 2023
6f6be13
Merge branch 'main' into handling-modal-window
kkosiorowska Dec 20, 2023
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
28 changes: 24 additions & 4 deletions dapp/src/DApp.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,18 @@ import React from "react"
import { Box, ChakraProvider } from "@chakra-ui/react"
import { useDetectThemeMode } from "./hooks"
import theme from "./theme"
import { LedgerWalletAPIProvider, WalletContextProvider } from "./contexts"
import {
DocsDrawerContextProvider,
LedgerWalletAPIProvider,
ModalContextProvider,
SidebarContextProvider,
WalletContextProvider,
} from "./contexts"
import Header from "./components/Header"
import Overview from "./components/Overview"
import Sidebar from "./components/Sidebar"
import DocsDrawer from "./components/DocsDrawer"
import ModalOverlay from "./components/ModalOverlay"

function DApp() {
useDetectThemeMode()
Expand All @@ -15,6 +24,11 @@ function DApp() {
<Box as="main">
<Overview />
</Box>
<Sidebar />
<DocsDrawer />
{/* The user has several modals in a flow.
Let's use our own modal overlay to prevent the background flickering effect. */}
<ModalOverlay />
r-czajkowski marked this conversation as resolved.
Show resolved Hide resolved
</>
)
}
Expand All @@ -23,9 +37,15 @@ function DAppProviders() {
return (
<LedgerWalletAPIProvider>
<WalletContextProvider>
<ChakraProvider theme={theme}>
<DApp />
</ChakraProvider>
<DocsDrawerContextProvider>
<SidebarContextProvider>
<ModalContextProvider>
<ChakraProvider theme={theme}>
<DApp />
</ChakraProvider>
</ModalContextProvider>
</SidebarContextProvider>
</DocsDrawerContextProvider>
</WalletContextProvider>
</LedgerWalletAPIProvider>
)
Expand Down
26 changes: 26 additions & 0 deletions dapp/src/components/DocsDrawer/index.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
import React from "react"
import {
Drawer,
DrawerBody,
DrawerContent,
DrawerOverlay,
} from "@chakra-ui/react"
import { useDocsDrawer } from "../../hooks"
import { TextMd } from "../Typography"
import { HEADER_HEIGHT } from "../Header"

export default function DocsDrawer() {
const { isOpen, onClose } = useDocsDrawer()

return (
<Drawer size="xl" placement="right" isOpen={isOpen} onClose={onClose}>
<DrawerOverlay mt={HEADER_HEIGHT} />
<DrawerContent mt={HEADER_HEIGHT}>
r-czajkowski marked this conversation as resolved.
Show resolved Hide resolved
<DrawerBody>
{/* TODO: Add a documentation */}
<TextMd>Documentation</TextMd>
</DrawerBody>
</DrawerContent>
</Drawer>
)
}
4 changes: 3 additions & 1 deletion dapp/src/components/Header/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,11 @@ import { Flex, HStack, Icon } from "@chakra-ui/react"
import ConnectWallet from "./ConnectWallet"
import { AcreLogo } from "../../static/icons"

export const HEADER_HEIGHT = 24
r-czajkowski marked this conversation as resolved.
Show resolved Hide resolved

export default function Header() {
return (
<HStack as="header" p={6}>
<HStack as="header" p={6} height={HEADER_HEIGHT}>
<Icon as={AcreLogo} boxSize={20} />
<Flex ml="auto">
<ConnectWallet />
Expand Down
40 changes: 40 additions & 0 deletions dapp/src/components/ModalOverlay/index.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
import React, { useEffect, useState } from "react"
import { Box } from "@chakra-ui/react"
import { useModal } from "../../hooks"
import { HEADER_HEIGHT } from "../Header"

const DELAY = 300

export default function ModalOverlay() {
const { modalType } = useModal()
const [showOverlay, setShowOverlay] = useState(!modalType)

useEffect(() => {
const timeout = setTimeout(
() => {
setShowOverlay(!!modalType)
},
// When the modal opens, we should show the sidebar without delay.
// However, when the modal disappears, the overlay should disappear with some delay.
modalType ? 0 : DELAY,
)
return () => clearTimeout(timeout)
}, [modalType])

return (
<Box
top={0}
left={0}
w="100vw"
h="100vh"
position="fixed"
bg="gold.300"
opacity={modalType ? 1 : 0}
zIndex="overlay"
// Hide the element when it is no longer needed.
display={showOverlay ? "block" : "none"}
transition={`opacity ${DELAY}ms`}
mt={HEADER_HEIGHT}
/>
)
}
25 changes: 25 additions & 0 deletions dapp/src/components/Modals/BaseModal.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
import React from "react"
import { Modal, ModalCloseButton, ModalContent } from "@chakra-ui/react"
import { HEADER_HEIGHT } from "../Header"
import { useModal, useSidebar } from "../../hooks"

export default function BaseModal({ children }: { children: React.ReactNode }) {
const { closeModal } = useModal()
const { onClose: closeSidebar } = useSidebar()

return (
<Modal
isOpen
size="md"
onClose={() => {
closeSidebar()
closeModal()
}}
>
<ModalContent mt={2 * HEADER_HEIGHT}>
<ModalCloseButton />
{children}
</ModalContent>
</Modal>
)
}
11 changes: 11 additions & 0 deletions dapp/src/components/Modals/StakingOverviewModal.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
import React from "react"
import { ModalHeader } from "@chakra-ui/react"
import BaseModal from "./BaseModal"

export default function StakingOverviewModal() {
return (
<BaseModal>
<ModalHeader textAlign="center">Staking overview</ModalHeader>
</BaseModal>
)
}
15 changes: 14 additions & 1 deletion dapp/src/components/Overview/PositionDetails.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -12,8 +12,13 @@ import {
} from "@chakra-ui/react"
import { BITCOIN, USD } from "../../constants"
import { Info } from "../../static/icons"
import { useModal, useSidebar } from "../../hooks"
import Staking from "../Staking"

export default function PositionDetails(props: CardProps) {
const { openModal } = useModal()
const { onOpen: openSidebar } = useSidebar()

return (
<Card {...props}>
<CardBody>
Expand All @@ -33,9 +38,17 @@ export default function PositionDetails(props: CardProps) {
</CardBody>
<CardFooter flexDirection="column" gap={2}>
{/* TODO: Handle click actions */}
<Button>Stake</Button>
<Button
onClick={() => {
openSidebar()
openModal("overview")
}}
>
Stake
</Button>
<Button variant="outline">Withdraw</Button>
</CardFooter>
<Staking />
</Card>
)
}
10 changes: 9 additions & 1 deletion dapp/src/components/Overview/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -12,16 +12,24 @@ import Statistics from "./Statistics"
import TransactionHistory from "./TransactionHistory"
import { USD } from "../../constants"
import { ChevronRight } from "../../static/icons"
import { useDocsDrawer } from "../../hooks"

export default function Overview() {
const { onOpen } = useDocsDrawer()

// TODO: Create a custom theme for card component
const bg = useColorModeValue("gold.100", "gold.100")

return (
<Flex direction="column" gap={2} p={6}>
<Flex justifyContent="space-between">
{/* TODO: Handle click actions */}
<Switch size="sm">Show values in {USD.symbol}</Switch>
<Button variant="link" rightIcon={<Icon as={ChevronRight} />}>
<Button
variant="link"
rightIcon={<Icon as={ChevronRight} />}
onClick={onOpen}
>
Read documentation
</Button>
</Flex>
Expand Down
39 changes: 39 additions & 0 deletions dapp/src/components/Sidebar/index.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
import React from "react"
import { Box, Button } from "@chakra-ui/react"
import DocsDrawer from "../DocsDrawer"
import { useDocsDrawer, useSidebar } from "../../hooks"
import { HEADER_HEIGHT } from "../Header"

export default function Sidebar() {
const { isOpen } = useSidebar()
const { onOpen: openDocsDrawer } = useDocsDrawer()

return (
<>
<Box
r-czajkowski marked this conversation as resolved.
Show resolved Hide resolved
top={0}
right={0}
h="100vh"
w={isOpen ? 80 : 0}
position="fixed"
overflow="hidden"
transition="width 0.3s"
zIndex="sidebar"
mt={HEADER_HEIGHT}
r-czajkowski marked this conversation as resolved.
Show resolved Hide resolved
>
<Box
p={4}
h="100%"
borderTop="2px"
borderLeft="2px"
borderColor="white"
borderTopLeftRadius="xl"
>
{/* TODO: Add a correct content for the sidebar */}
<Button onClick={openDocsDrawer}>Open a documentation</Button>
</Box>
</Box>
<DocsDrawer />
r-czajkowski marked this conversation as resolved.
Show resolved Hide resolved
</>
)
}
11 changes: 11 additions & 0 deletions dapp/src/components/Staking/index.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
import React from "react"
import { useModal } from "../../hooks"
import StakingOverviewModal from "../Modals/StakingOverviewModal"

export default function Staking() {
const { modalType } = useModal()

if (!modalType) return null

if (modalType === "overview") return <StakingOverviewModal />
}
44 changes: 44 additions & 0 deletions dapp/src/contexts/DocsDrawerContext.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
import React, { createContext, useCallback, useMemo, useState } from "react"

type DocsDrawerContextValue = {
isOpen: boolean
onOpen: () => void
onClose: () => void
}

export const DocsDrawerContext = createContext<DocsDrawerContextValue>({
isOpen: false,
onOpen: () => {},
onClose: () => {},
})

export function DocsDrawerContextProvider({
children,
}: {
children: React.ReactNode
}): React.ReactElement {
const [isOpen, setIsOpen] = useState(false)

const onOpen = useCallback(() => {
setIsOpen(true)
}, [])

const onClose = useCallback(() => {
setIsOpen(false)
}, [])

const contextValue: DocsDrawerContextValue = useMemo<DocsDrawerContextValue>(
() => ({
isOpen,
onOpen,
onClose,
}),
[isOpen, onClose, onOpen],
)

return (
<DocsDrawerContext.Provider value={contextValue}>
{children}
</DocsDrawerContext.Provider>
)
}
45 changes: 45 additions & 0 deletions dapp/src/contexts/ModalContext.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
import React, { createContext, useCallback, useMemo, useState } from "react"

type ModalType = "overview"

type ModalContextValue = {
modalType?: ModalType
openModal: (modalType: ModalType) => void
closeModal: () => void
}

export const ModalContext = createContext<ModalContextValue>({
openModal: () => {},
closeModal: () => {},
})

export function ModalContextProvider({
children,
}: {
children: React.ReactNode
}): React.ReactElement {
const [modalType, setModalType] = useState<ModalType | undefined>(undefined)

const openModal = useCallback((type: ModalType) => {
setModalType(type)
}, [])

const closeModal = useCallback(() => {
setModalType(undefined)
}, [])

const contextValue: ModalContextValue = useMemo<ModalContextValue>(
() => ({
modalType,
openModal,
closeModal,
}),
[modalType, closeModal, openModal],
)

return (
<ModalContext.Provider value={contextValue}>
{children}
</ModalContext.Provider>
)
}
Loading