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

Fix scrolling with drawer open #435

Merged
merged 3 commits into from
Sep 12, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
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
1 change: 1 addition & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -135,6 +135,7 @@
"react-qrcode-logo": "^2.9.0",
"react-query": "^3.39.3",
"react-redux": "8.0.5",
"react-remove-scroll": "^2.5.6",
"react-responsive-carousel": "^3.2.23",
"react-router-dom": "^6.15.0",
"react-scripts": "5.0.1",
Expand Down
4 changes: 3 additions & 1 deletion src/components/DynamicModal.tsx
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import { Modal, ModalOverlay, ModalProps, useDisclosure } from "@chakra-ui/react";
import { createContext, ReactElement, useState } from "react";
import { RemoveScroll } from "react-remove-scroll";

// this should be used in components as useContext(DynamicModalContext);
export const DynamicModalContext = createContext<{
Expand Down Expand Up @@ -41,12 +42,13 @@ export const useDynamicModal = () => {
isOpen={isOpen}
onClose={onClose}
closeOnOverlayClick={false}
blockScrollOnMount={false}
autoFocus={false}
size={size}
isCentered
>
<ModalOverlay />
{modalContent}
<RemoveScroll enabled={isOpen}>{modalContent}</RemoveScroll>
</Modal>
),
};
Expand Down
11 changes: 10 additions & 1 deletion src/views/home/AccountListWithDrawer.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -5,12 +5,14 @@ import AccountCard from "../../components/AccountDrawer";
import { useAllAccounts } from "../../utils/hooks/accountHooks";
import { AccountsList } from "./AccountsList";
import { DrawerTopButtons } from "./DrawerTopButtons";
import { useDynamicModal } from "../../components/DynamicModal";

const AccountListWithDrawer: React.FC = () => {
const [selected, setSelected] = useState<string | null>(null);
const allAccounts = useAllAccounts();

const { isOpen, onClose: closeDrawer, onOpen } = useDisclosure();
const { isOpen: isDynamicModalOpen } = useDynamicModal();

const handleClose = () => {
setSelected(null);
Expand All @@ -27,7 +29,14 @@ const AccountListWithDrawer: React.FC = () => {
setSelected(pkh);
}}
/>
<Drawer isOpen={isOpen} placement="right" onClose={handleClose} size="md" autoFocus={false}>
<Drawer
blockScrollOnMount={!isDynamicModalOpen}
isOpen={isOpen}
placement="right"
onClose={handleClose}
size="md"
autoFocus={false}
>
<DrawerOverlay />
<DrawerContent maxW="594px" bg="umami.gray.900">
<DrawerTopButtons onClose={handleClose} />
Expand Down
3 changes: 3 additions & 0 deletions src/views/nfts/NftsView.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -10,12 +10,14 @@ import { useAllNfts } from "../../utils/hooks/assetsHooks";
import { DrawerTopButtons } from "../home/DrawerTopButtons";
import NFTDrawerCard from "./NFTDrawerCard";
import NFTGallery from "./NFTGallery";
import { useDynamicModal } from "../../components/DynamicModal";

const NFTsViewBase = () => {
const nfts = useAllNfts();
const { accountsFilter, selectedAccounts } = useAccountsFilter();
const navigate = useNavigate();
const { ownerPkh, nftId } = useParams();
const { isOpen: isDynamicModalOpen } = useDynamicModal();

const openNFTsPage = useCallback(() => {
navigate(`/nfts`);
Expand Down Expand Up @@ -58,6 +60,7 @@ const NFTsViewBase = () => {
</Box>

<Drawer
blockScrollOnMount={!isDynamicModalOpen}
placement="right"
onClose={openNFTsPage}
size="md"
Expand Down
11 changes: 9 additions & 2 deletions src/views/settings/BeaconDrawerCard.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -14,14 +14,21 @@ import { SettingsCardWithDrawerIcon } from "../../components/ClickableCard";
import { useAddPeer } from "../../utils/beacon/beacon";
import BeaconPeers from "../../utils/beacon/BeaconPeers";
import { DrawerTopButtons } from "../home/DrawerTopButtons";
import { useDynamicModal } from "../../components/DynamicModal";

export const BeaconDrawerCard = () => {
const { isOpen, onClose: closeDrawer, onOpen } = useDisclosure();

const { isOpen: isDynamicModalOpen } = useDynamicModal();
return (
<>
<SettingsCardWithDrawerIcon left="dApps" onClick={onOpen} />
<Drawer isOpen={isOpen} placement="right" onClose={closeDrawer} size="md">
<Drawer
blockScrollOnMount={!isDynamicModalOpen}
isOpen={isOpen}
placement="right"
onClose={closeDrawer}
size="md"
>
<DrawerOverlay />
<DrawerContent maxW="594px" bg="umami.gray.900">
<DrawerTopButtons onClose={closeDrawer} />
Expand Down
15 changes: 12 additions & 3 deletions src/views/settings/ErrorLogsDrawerCard.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -17,9 +17,12 @@ import colors from "../../style/colors";
import { ErrorContext } from "../../utils/getErrorContext";
import { useAppSelector } from "../../utils/redux/hooks";
import { DrawerTopButtons } from "../home/DrawerTopButtons";
import { nanoid } from "@reduxjs/toolkit";
import { useDynamicModal } from "../../components/DynamicModal";

const ErrorLogsDrawerCard = () => {
const { isOpen, onClose: closeDrawer, onOpen } = useDisclosure();
const { isOpen: isDynamicModalOpen } = useDynamicModal();

const handleClose = () => {
closeDrawer();
Expand All @@ -28,7 +31,13 @@ const ErrorLogsDrawerCard = () => {
return (
<>
<SettingsCardWithDrawerIcon left="ErrorLogs" onClick={onOpen} />
<Drawer isOpen={isOpen} placement="right" onClose={handleClose} size="md">
<Drawer
blockScrollOnMount={!isDynamicModalOpen}
isOpen={isOpen}
placement="right"
onClose={handleClose}
size="md"
>
<DrawerOverlay />
<DrawerContent maxW="594px" bg="umami.gray.900">
<DrawerTopButtons onClose={handleClose} />
Expand Down Expand Up @@ -56,8 +65,8 @@ const ErrorLogsDrawerBody = () => {
{/* TODO:Implement delete */}
{/* <IconAndTextBtn label="Clear All" icon={Trash} textFirst onClick={() => {}} /> */}
</Flex>
{errors.map((error, i) => (
<ErrorLogRow errorLog={error} key={error.timestamp} />
{errors.map(error => (
<ErrorLogRow errorLog={error} key={nanoid()} />
))}
</Flex>
);
Expand Down
3 changes: 2 additions & 1 deletion yarn.lock
Original file line number Diff line number Diff line change
Expand Up @@ -20866,7 +20866,7 @@ __metadata:
languageName: node
linkType: hard

"react-remove-scroll@npm:^2.5.5":
"react-remove-scroll@npm:^2.5.5, react-remove-scroll@npm:^2.5.6":
version: 2.5.6
resolution: "react-remove-scroll@npm:2.5.6"
dependencies:
Expand Down Expand Up @@ -23798,6 +23798,7 @@ __metadata:
react-qrcode-logo: ^2.9.0
react-query: ^3.39.3
react-redux: 8.0.5
react-remove-scroll: ^2.5.6
react-responsive-carousel: ^3.2.23
react-router-dom: ^6.15.0
react-scripts: 5.0.1
Expand Down