import React, { Component } from 'react' import { connect } from 'react-redux' import { toArray } from 'app/utils' import actions from 'app/actions' import { Arrow } from '../nav/viewer.icons' import { EfluxClose } from '../nav/eflux.icons' class ViewerSectionsFootnotes extends Component { state = { scrollPositions: [], } constructor(props) { super(props) this.scrollRef = React.createRef() } componentDidUpdate(prevProps) { if (this.props.footnoteList !== prevProps.footnoteList) { this.cacheScrollPositions() } if (this.props.currentFootnote !== prevProps.currentFootnote) { this.scrollToFootnote() } } cacheScrollPositions() { let scrollPositions = toArray(this.scrollRef.current.querySelectorAll('.note-element')).map(el => { return el.offsetTop }) this.setState({ scrollPositions }) } scrollToFootnote() { const { currentFootnote } = this.props const id = currentFootnote.footnote_id - 1 const pos = this.state.scrollPositions[id] this.scrollRef.current.scrollTo(0, pos - 5) } render() { const { footnoteList } = this.props return (
actions.viewer.hideNavComponent('footnotes')}> {EfluxClose}
{footnoteList.map(note => (
{note.footnote_id}
actions.viewer.seekToTimestamp(note.start_ts)}> {'Go to text'}
))}
) } } const FootnotesLink = ({ type }) => (
actions.viewer.hideNavComponent('footnotes')}> {'Notes'}
) const mapStateToProps = state => ({ footnoteList: state.viewer.footnoteList, currentFootnote: state.viewer.currentFootnote, }) export default connect(mapStateToProps)(ViewerSectionsFootnotes)