Commit 33c09911 authored by Charles Bachmeier's avatar Charles Bachmeier Committed by GitHub

chore: refactor Bag to use scroll hook (#6483)

* chore: refactor Bag to use scroll hook

* remove outdated comment

---------
Co-authored-by: default avatarCharles Bachmeier <charlie@genie.xyz>
parent 40247ff7
...@@ -7,7 +7,7 @@ import { Box } from 'nft/components/Box' ...@@ -7,7 +7,7 @@ import { Box } from 'nft/components/Box'
import { Portal } from 'nft/components/common/Portal' import { Portal } from 'nft/components/common/Portal'
import { Column } from 'nft/components/Flex' import { Column } from 'nft/components/Flex'
import { Overlay } from 'nft/components/modals/Overlay' import { Overlay } from 'nft/components/modals/Overlay'
import { useBag, useIsMobile, useProfilePageState, useSellAsset } from 'nft/hooks' import { useBag, useIsMobile, useProfilePageState, useSellAsset, useSubscribeScrollState } from 'nft/hooks'
import { BagStatus, ProfilePageStateType } from 'nft/types' import { BagStatus, ProfilePageStateType } from 'nft/types'
import { formatAssetEventProperties, recalculateBagUsingPooledAssets } from 'nft/utils' import { formatAssetEventProperties, recalculateBagUsingPooledAssets } from 'nft/utils'
import { useCallback, useEffect, useMemo, useState } from 'react' import { useCallback, useEffect, useMemo, useState } from 'react'
...@@ -122,14 +122,7 @@ const Bag = () => { ...@@ -122,14 +122,7 @@ const Bag = () => {
const itemsInBag = useMemo(() => recalculateBagUsingPooledAssets(uncheckedItemsInBag), [uncheckedItemsInBag]) const itemsInBag = useMemo(() => recalculateBagUsingPooledAssets(uncheckedItemsInBag), [uncheckedItemsInBag])
const [isModalOpen, setModalIsOpen] = useState(false) const [isModalOpen, setModalIsOpen] = useState(false)
const [userCanScroll, setUserCanScroll] = useState(false) const { userCanScroll, scrollRef, scrollProgress, scrollHandler } = useSubscribeScrollState()
const [scrollProgress, setScrollProgress] = useState(0)
const scrollRef = (node: HTMLDivElement) => {
if (node !== null) {
const canScroll = node.scrollHeight > node.clientHeight
canScroll !== userCanScroll && setUserCanScroll(canScroll)
}
}
const handleCloseBag = useCallback(() => { const handleCloseBag = useCallback(() => {
setBagExpanded({ bagExpanded: false, manualClose: true }) setBagExpanded({ bagExpanded: false, manualClose: true })
...@@ -140,15 +133,6 @@ const Bag = () => { ...@@ -140,15 +133,6 @@ const Bag = () => {
}, [bagIsLocked, isModalOpen]) }, [bagIsLocked, isModalOpen])
const hasAssetsToShow = itemsInBag.length > 0 const hasAssetsToShow = itemsInBag.length > 0
const scrollHandler = (event: React.UIEvent<HTMLDivElement>) => {
const scrollTop = event.currentTarget.scrollTop
const containerHeight = event.currentTarget.clientHeight
const scrollHeight = event.currentTarget.scrollHeight
setScrollProgress(scrollTop ? ((scrollTop + containerHeight) / scrollHeight) * 100 : 0)
}
const isBuyingAssets = itemsInBag.length > 0 const isBuyingAssets = itemsInBag.length > 0
const isSellingAssets = sellAssets.length > 0 const isSellingAssets = sellAssets.length > 0
......
import { useState } from 'react' import { useState } from 'react'
// TODO(NFT-1190): update Bag component to use this hook
export function useSubscribeScrollState() { export function useSubscribeScrollState() {
const [userCanScroll, setUserCanScroll] = useState(false) const [userCanScroll, setUserCanScroll] = useState(false)
const [scrollProgress, setScrollProgress] = useState(0) const [scrollProgress, setScrollProgress] = useState(0)
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment