fix(client): remove auto scroll on superBlock page (#40828)

This commit is contained in:
Tom
2021-01-29 07:21:52 -06:00
committed by Mrugesh Mohapatra
parent df014a4715
commit 1875984423

View File

@ -69,31 +69,11 @@ const mapDispatchToProps = dispatch =>
); );
export class SuperBlockIntroductionPage extends Component { export class SuperBlockIntroductionPage extends Component {
constructor(props) {
super(props);
this.elementRef = React.createRef();
}
componentDidMount() { componentDidMount() {
this.initializeExpandedState(); this.initializeExpandedState();
this.scrollToBlock();
} }
componentDidUpdate() { getChosenBlock() {
this.scrollToBlock();
}
scrollToBlock() {
if (this.elementRef.current) {
setTimeout(() => {
const scrollTo = this.elementRef.current.offsetTop;
window.scrollTo({ top: scrollTo, left: 0, behavior: 'smooth' });
}, 300);
}
}
getChosenBlock(forScrolling) {
const { const {
data: { data: {
allChallengeNode: { edges } allChallengeNode: { edges }
@ -120,7 +100,7 @@ export class SuperBlockIntroductionPage extends Component {
: edge.node.block; : edge.node.block;
} }
return forScrolling ? 'top' : edge.node.block; return edge.node.block;
} }
initializeExpandedState() { initializeExpandedState() {
@ -138,7 +118,6 @@ export class SuperBlockIntroductionPage extends Component {
}, },
allChallengeNode: { edges } allChallengeNode: { edges }
}, },
fetchState: { pending, complete },
isSignedIn, isSignedIn,
t t
} = this.props; } = this.props;
@ -150,21 +129,13 @@ export class SuperBlockIntroductionPage extends Component {
const i18nSuperBlock = t(`intro:${superBlockDashedName}.title`); const i18nSuperBlock = t(`intro:${superBlockDashedName}.title`);
let blockToScrollTo;
if (!pending && complete) {
blockToScrollTo = this.getChosenBlock(true);
}
return ( return (
<> <>
<Helmet> <Helmet>
<title>{i18nSuperBlock} | freeCodeCamp.org</title> <title>{i18nSuperBlock} | freeCodeCamp.org</title>
</Helmet> </Helmet>
<Grid> <Grid>
<Row <Row className='super-block-intro-page'>
className='super-block-intro-page'
ref={blockToScrollTo === 'top' ? this.elementRef : null}
>
<Col md={8} mdOffset={2} sm={10} smOffset={1} xs={12}> <Col md={8} mdOffset={2} sm={10} smOffset={1} xs={12}>
<Spacer size={2} /> <Spacer size={2} />
<SuperBlockIntro superBlock={superBlock} /> <SuperBlockIntro superBlock={superBlock} />
@ -175,14 +146,7 @@ export class SuperBlockIntroductionPage extends Component {
<Spacer /> <Spacer />
<div className='block-ui'> <div className='block-ui'>
{blockDashedNames.map(blockDashedName => ( {blockDashedNames.map(blockDashedName => (
<div <div key={blockDashedName}>
key={blockDashedName}
ref={
blockDashedName === blockToScrollTo
? this.elementRef
: null
}
>
<Block <Block
blockDashedName={blockDashedName} blockDashedName={blockDashedName}
challenges={nodesForSuperBlock.filter( challenges={nodesForSuperBlock.filter(