Skip to content

Commit

Permalink
Fix opening points widget breaks layout
Browse files Browse the repository at this point in the history
  • Loading branch information
teodorus-nathaniel committed Jun 11, 2024
1 parent 490a243 commit 810fc20
Show file tree
Hide file tree
Showing 3 changed files with 17 additions and 6 deletions.
6 changes: 3 additions & 3 deletions src/hooks/useTgNoScroll.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,14 +5,14 @@ export default function useTgNoScroll() {
useEffect(() => {
const overflow = 500
document.body.style.overflowY = 'hidden'
document.body.style.marginTop = `${overflow}px`
document.body.style.height = window.innerHeight + overflow + 'px'
document.body.style.paddingTop = `${overflow}px`
document.body.style.height = window.innerHeight + overflow + 'px !important'
document.body.style.paddingBottom = `${overflow}px`
window.scrollTo(0, overflow)

return () => {
document.body.style.overflowY = 'initial'
document.body.style.marginTop = '0'
document.body.style.paddingTop = '0'
document.body.style.height = 'auto'
document.body.style.paddingBottom = '0'
}
Expand Down
5 changes: 4 additions & 1 deletion src/modules/chat/HomePage/ChatContent.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,10 @@ export default function ChatContent({ chatId, hubId, className }: Props) {
/>
<ChatRoom
topElement={
<PointsWidget className='absolute left-0 top-0 z-10 w-full' />
<PointsWidget
className='absolute left-0 top-0 z-10 w-full'
isNoTgScroll
/>
}
scrollableContainerClassName='pt-12'
asContainer
Expand Down
12 changes: 10 additions & 2 deletions src/modules/points/PointsWidget.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,9 @@ import { HiChevronRight, HiXMark } from 'react-icons/hi2'
import SlotCounter from 'react-slot-counter'
import { Drawer } from 'vaul'

export default function PointsWidget(props: ComponentProps<'div'>) {
export default function PointsWidget(
props: ComponentProps<'div'> & { isNoTgScroll?: boolean }
) {
const sendEvent = useSendEvent()

return (
Expand All @@ -30,7 +32,13 @@ export default function PointsWidget(props: ComponentProps<'div'>) {
direction='top'
onOpenChange={(open) => {
// To make bottom menu still clickable when this drawer is open
if (open) setTimeout(() => (document.body.style.pointerEvents = ''), 0)
setTimeout(() => {
if (open) {
document.body.style.pointerEvents = ''
} else if (props.isNoTgScroll) {
document.body.style.paddingTop = '500px'
}
}, 0)
}}
>
<Drawer.Trigger asChild>
Expand Down

0 comments on commit 810fc20

Please sign in to comment.