summaryrefslogtreecommitdiff
path: root/animism-align/frontend/app/views/align/components/sidebar/tableOfContents.component.js
blob: 34aedb5fc965303bf6aac5212e6e558ad771763c (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
import React, { Component } from 'react'
// import { Link } from 'react-router-dom'
import { bindActionCreators } from 'redux'
import { connect } from 'react-redux'

import { ROMAN_NUMERALS } from 'app/constants'
import actions from 'app/actions'

class TableOfContents extends Component {
  render() {
    const { loading, order, lookup } = this.props.annotation
    if (loading || !order) return null
    const sectionIds = order.filter(id => lookup[id].type === "section_heading")
    return (
      <div className="toc">
        {sectionIds.map((id, i) => (
          <div key={id} onClick={() => actions.align.setScrollPosition(lookup[id].start_ts)}>
            {ROMAN_NUMERALS[i]}{'. '}{lookup[id].text}
          </div>
        ))}
      </div>
    )
  }
}

const mapStateToProps = state => ({
  annotation: state.annotation.index,
})

export default connect(mapStateToProps)(TableOfContents)