Skip to content

Commit

Permalink
fix: always render floating bar
Browse files Browse the repository at this point in the history
  • Loading branch information
1emu committed Sep 20, 2023
1 parent 729750f commit 7b56ddd
Show file tree
Hide file tree
Showing 4 changed files with 38 additions and 33 deletions.
4 changes: 2 additions & 2 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

9 changes: 5 additions & 4 deletions src/components/FloatingBar/FloatingBar.css
Original file line number Diff line number Diff line change
Expand Up @@ -7,17 +7,18 @@
border: 1px solid var(--black-300);
background: var(--white-900);
box-shadow: 0 0 25px 0 var(--alpha-black-400);
z-index: 200;
padding: 12px 18px 12px 16px;
display: flex;
justify-content: space-between;
align-items: center;
opacity: 0;
transition: all 0.5s ease 0s;
opacity: 1;
z-index: 200;
}

.FloatingBar--visible {
opacity: 1;
.FloatingBar--hidden {
opacity: 0;
z-index: -1;
}

.FloatingBar__ProposalSectionActions {
Expand Down
15 changes: 10 additions & 5 deletions src/components/FloatingBar/FloatingBar.tsx
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import React from 'react'
import React, { useEffect, useState } from 'react'

import classNames from 'classnames'
import { Button } from 'decentraland-ui/dist/components/Button/Button'
Expand All @@ -20,9 +20,9 @@ interface FloatingBarProps {
showViewReactions: boolean
scrollToComments: () => void
scrollToReactions: () => void
proposalId: string
discourseTopicId: number
discourseTopicSlug: string
proposalId?: string
discourseTopicId?: number
discourseTopicSlug?: string
}

const FloatingBar: React.FC<FloatingBarProps> = ({
Expand All @@ -35,10 +35,15 @@ const FloatingBar: React.FC<FloatingBarProps> = ({
scrollToReactions,
}) => {
const t = useFormatMessage()
const [isLoaded, setIsLoaded] = useState<boolean>(false)
const { comments, isLoadingComments } = useProposalComments(proposalId)

useEffect(() => {
setIsLoaded(true)
}, [])

return (
<div className={classNames('FloatingBar', isVisible && 'FloatingBar--visible')}>
<div className={classNames('FloatingBar', !isVisible && isLoaded && 'FloatingBar--hidden')}>
<div className="FloatingBar__ProposalSectionActions">
{showViewReactions && (
<Link onClick={scrollToReactions} className={'FloatingBar__Action'}>
Expand Down
43 changes: 21 additions & 22 deletions src/pages/proposal.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -16,8 +16,8 @@ import { ErrorClient } from '../clients/ErrorClient'
import { Governance } from '../clients/Governance'
import { SnapshotApi } from '../clients/SnapshotApi'
import CategoryPill from '../components/Category/CategoryPill'
import FloatingBar from '../components/FloatingBar/FloatingBar'
import ProposalVPChart from '../components/Charts/ProposalVPChart'
import FloatingBar from '../components/FloatingBar/FloatingBar'
import ContentLayout, { ContentSection } from '../components/Layout/ContentLayout'
import MaintenanceLayout from '../components/Layout/MaintenanceLayout'
import BidSubmittedModal from '../components/Modal/BidSubmittedModal'
Expand Down Expand Up @@ -208,11 +208,16 @@ export default function ProposalPage() {
commentsSectionRef.current.scrollIntoView({ behavior: 'smooth' })
}
}

useEffect(() => {
setIsBarVisible(true)

const handleScroll = () => {
const hideBarSectionRef = reactionsSectionRef.current || commentsSectionRef.current
if (hideBarSectionRef) {
if (!!hideBarSectionRef && !!window) {
const hideBarSectionTop = hideBarSectionRef.getBoundingClientRect().top
console.log('hideBarSectionTop', hideBarSectionTop)
console.log('windowInnerHeight', window.innerHeight)
setIsBarVisible(hideBarSectionTop > window.innerHeight)
}
}
Expand Down Expand Up @@ -297,15 +302,11 @@ export default function ProposalPage() {
}, [proposal, account, isDAOCommittee])

useEffect(() => {
updatePageStateRef.current({ showProposalSuccessModal: params.get('new') === 'true' })
}, [params])

useEffect(() => {
updatePageStateRef.current({ showTenderPublishedModal: params.get('pending') === 'true' })
}, [params])

useEffect(() => {
updatePageStateRef.current({ showBidSubmittedModal: params.get('bid') === 'true' })
updatePageStateRef.current({
showProposalSuccessModal: params.get('new') === 'true',
showTenderPublishedModal: params.get('pending') === 'true',
showBidSubmittedModal: params.get('bid') === 'true',
})
}, [params])

useEffect(() => {
Expand Down Expand Up @@ -425,17 +426,15 @@ export default function ProposalPage() {
/>
)}
<ProposalComments proposal={proposal} ref={commentsSectionRef} />
{proposal && !isLoadingSurveyTopics && (
<FloatingBar
isVisible={isBarVisible}
showViewReactions={!!showSurveyResults}
scrollToReactions={scrollToReactions}
scrollToComments={scrollToComments}
proposalId={proposal?.id}
discourseTopicId={proposal?.discourse_topic_id}
discourseTopicSlug={proposal?.discourse_topic_slug}
/>
)}
<FloatingBar
isVisible={isBarVisible}
showViewReactions={!!showSurveyResults}
scrollToReactions={scrollToReactions}
scrollToComments={scrollToComments}
proposalId={proposal?.id}
discourseTopicId={proposal?.discourse_topic_id}
discourseTopicSlug={proposal?.discourse_topic_slug}
/>
</Grid.Column>

<Grid.Column tablet="4" className="ProposalDetailActions">
Expand Down

0 comments on commit 7b56ddd

Please sign in to comment.