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

Jason/enable interfaces #140

Merged
merged 6 commits into from
Jun 2, 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
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ import styled, { css } from 'styled-components'
import mq from '../../utils/media-query'
import { connect } from 'react-redux'
import { Waypoint } from 'react-waypoint'
import { offsetTop } from '../../constants/customized-props'

const _ = {
get,
Expand Down Expand Up @@ -80,9 +81,9 @@ const ItemViewport = styled.div`
} else if (props.sectionsPosition === Waypoint.above) {
return `position: absolute; bottom: 50vh;`
} else if (props.sectionsPosition === Waypoint.below) {
return `position: absolute; top:0px;`
return `position: absolute; top: 0px;`
}
return `position: fixed; top: 0px;`
return `position: fixed; top: ${offsetTop}px;`
}}
`}
${mq.desktopOnly`
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ import React from 'react'
import styled from 'styled-components'
import { Waypoint } from 'react-waypoint'
import { connect } from 'react-redux'
import { scrollableAncestor } from '../constants/customized-props'

const EntryPoint = styled.div`
width: 1px;
Expand Down Expand Up @@ -51,6 +52,7 @@ class _HeadEntryPoint extends React.PureComponent {
render() {
return (
<Waypoint
scrollableAncestor={scrollableAncestor}
topOffset={this.props.topOffset}
bottomOffset={this.props.bottomOffset}
onPositionChange={this._handlePositionChange}
Expand Down
8 changes: 5 additions & 3 deletions packages/dual-channel/src/app/components/text/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ import React from 'react'
import styled from 'styled-components'
import { Waypoint } from 'react-waypoint'
import { connect } from 'react-redux'
import { scrollableAncestor } from '../../constants/customized-props'

const _ = {
get,
Expand Down Expand Up @@ -67,7 +68,7 @@ class ArticleText extends React.Component {
chapters: PropTypes.arrayOf(predefinedPropTypes.chapter).isRequired,
// provided by redux
// currentAnchor: PropTypes.number.isRequired,
updatAnchorIndex: PropTypes.func.isRequired,
updateAnchorIndex: PropTypes.func.isRequired,
}

_handlePositionChange = (
Expand All @@ -87,7 +88,7 @@ class ArticleText extends React.Component {
positionState.previousSection = sectionIndex
}

this.props.updatAnchorIndex({
this.props.updateAnchorIndex({
...positionState,
})
}
Expand All @@ -110,6 +111,7 @@ class ArticleText extends React.Component {
const _renderSection = (section, sectionIndex) => {
const sectionJsx = (
<Waypoint
scrollableAncestor={scrollableAncestor}
key={section.id}
id={section.id}
topOffset="49%"
Expand Down Expand Up @@ -142,7 +144,7 @@ class ArticleText extends React.Component {
}

const mapDispatchToProps = dispatch => ({
updatAnchorIndex: dispatch.position.update,
updateAnchorIndex: dispatch.position.update,
})

export default connect(
Expand Down
16 changes: 16 additions & 0 deletions packages/dual-channel/src/app/constants/customized-props.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
const isClientSide =
typeof window !== 'undefined' && typeof window.document !== 'undefined'

const scrollableAncestorValue =
isClientSide &&
document.currentScript.getAttribute('data-scrollable-ancestor')
export const scrollableAncestor = scrollableAncestorValue || undefined

const offsetTopValue =
isClientSide && document.currentScript.getAttribute('data-offset-top')
export const offsetTop =
offsetTopValue &&
Number.isInteger(Number(offsetTopValue)) &&
Number(offsetTopValue) > 0
? offsetTopValue
: 0