2020-07-16 06:09:01 -04:00
|
|
|
import React, { useState, useEffect } from 'react'
|
2020-06-29 09:05:08 -04:00
|
|
|
import PropTypes from 'prop-types'
|
|
|
|
import { OverlayTrigger, Tooltip } from 'react-bootstrap'
|
|
|
|
import classNames from 'classnames'
|
|
|
|
import OutlineRoot from './OutlineRoot'
|
2020-07-16 06:09:01 -04:00
|
|
|
import localStorage from '../../../modules/localStorage'
|
2020-06-29 09:05:08 -04:00
|
|
|
|
2020-07-16 10:04:04 -04:00
|
|
|
function OutlinePane({
|
|
|
|
isTexFile,
|
|
|
|
outline,
|
|
|
|
projectId,
|
|
|
|
jumpToLine,
|
|
|
|
onToggle,
|
2020-07-28 05:37:46 -04:00
|
|
|
eventTracking,
|
|
|
|
highlightedLine
|
2020-07-16 10:04:04 -04:00
|
|
|
}) {
|
2020-07-16 06:09:01 -04:00
|
|
|
const storageKey = `file_outline.expanded.${projectId}`
|
|
|
|
const [expanded, setExpanded] = useState(() => {
|
|
|
|
const storedExpandedState = localStorage(storageKey) !== false
|
|
|
|
return storedExpandedState
|
|
|
|
})
|
|
|
|
const isOpen = isTexFile && expanded
|
|
|
|
|
|
|
|
useEffect(
|
|
|
|
() => {
|
|
|
|
onToggle(isOpen)
|
|
|
|
},
|
|
|
|
[isOpen]
|
|
|
|
)
|
2020-06-29 09:05:08 -04:00
|
|
|
|
|
|
|
const expandCollapseIconClasses = classNames('fa', 'outline-caret-icon', {
|
2020-07-16 06:09:01 -04:00
|
|
|
'fa-angle-down': isOpen,
|
|
|
|
'fa-angle-right': !isOpen
|
2020-06-29 09:05:08 -04:00
|
|
|
})
|
|
|
|
|
|
|
|
const headerClasses = classNames('outline-pane', {
|
|
|
|
'outline-pane-disabled': !isTexFile
|
|
|
|
})
|
|
|
|
|
|
|
|
function handleExpandCollapseClick() {
|
|
|
|
if (isTexFile) {
|
2020-07-16 06:09:01 -04:00
|
|
|
localStorage(storageKey, !expanded)
|
2020-07-16 10:04:04 -04:00
|
|
|
eventTracking.sendMB(expanded ? 'outline-collapse' : 'outline-expand')
|
2020-06-29 09:05:08 -04:00
|
|
|
setExpanded(!expanded)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return (
|
|
|
|
<div className={headerClasses}>
|
|
|
|
<header className="outline-header">
|
|
|
|
<button
|
|
|
|
className="outline-header-expand-collapse-btn"
|
|
|
|
disabled={!isTexFile}
|
|
|
|
onClick={handleExpandCollapseClick}
|
|
|
|
>
|
|
|
|
<i className={expandCollapseIconClasses} />
|
|
|
|
<h4 className="outline-header-name">File outline</h4>
|
2020-07-16 06:09:01 -04:00
|
|
|
<OverlayTrigger placement="top" overlay={tooltip} delayHide={100}>
|
|
|
|
<a
|
|
|
|
href="/beta/participate"
|
|
|
|
target="_blank"
|
|
|
|
rel="noopener noreferrer"
|
|
|
|
className="outline-header-beta-badge"
|
|
|
|
>
|
|
|
|
<span className="sr-only">
|
|
|
|
The File outline is a beta feature. Click here to manage your
|
|
|
|
beta program membership.
|
|
|
|
</span>
|
|
|
|
</a>
|
|
|
|
</OverlayTrigger>
|
2020-06-29 09:05:08 -04:00
|
|
|
</button>
|
|
|
|
</header>
|
|
|
|
{expanded && isTexFile ? (
|
|
|
|
<div className="outline-body">
|
2020-07-28 05:37:46 -04:00
|
|
|
<OutlineRoot
|
|
|
|
outline={outline}
|
|
|
|
jumpToLine={jumpToLine}
|
|
|
|
highlightedLine={highlightedLine}
|
|
|
|
/>
|
2020-06-29 09:05:08 -04:00
|
|
|
</div>
|
|
|
|
) : null}
|
|
|
|
</div>
|
|
|
|
)
|
|
|
|
}
|
|
|
|
|
|
|
|
const tooltip = (
|
|
|
|
<Tooltip id="outline-beta-badge-tooltip">
|
|
|
|
The <strong>File outline</strong> is a beta feature.
|
|
|
|
</Tooltip>
|
|
|
|
)
|
|
|
|
|
|
|
|
OutlinePane.propTypes = {
|
|
|
|
isTexFile: PropTypes.bool.isRequired,
|
|
|
|
outline: PropTypes.array.isRequired,
|
2020-07-16 06:09:01 -04:00
|
|
|
projectId: PropTypes.string.isRequired,
|
|
|
|
jumpToLine: PropTypes.func.isRequired,
|
2020-07-16 10:04:04 -04:00
|
|
|
onToggle: PropTypes.func,
|
2020-07-28 05:37:46 -04:00
|
|
|
eventTracking: PropTypes.object.isRequired,
|
|
|
|
highlightedLine: PropTypes.number
|
2020-06-29 09:05:08 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
export default OutlinePane
|