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'
|
2020-09-01 04:09:04 -04:00
|
|
|
import OutlineRoot from './outline-root'
|
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-08-18 09:08:49 -04:00
|
|
|
{expanded ? (
|
|
|
|
<OverlayTrigger placement="top" overlay={tooltip} delayHide={100}>
|
|
|
|
<a
|
2020-09-01 08:36:55 -04:00
|
|
|
href="/learn/how-to/Using_the_File_Outline_in_Overleaf"
|
2020-08-18 09:08:49 -04:00
|
|
|
target="_blank"
|
|
|
|
rel="noopener noreferrer"
|
|
|
|
className="outline-header-info-badge"
|
|
|
|
onClick={ev => ev.stopPropagation()}
|
|
|
|
>
|
|
|
|
<span className="sr-only">{infoContent}</span>
|
|
|
|
</a>
|
|
|
|
</OverlayTrigger>
|
|
|
|
) : null}
|
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>
|
|
|
|
)
|
|
|
|
}
|
|
|
|
|
2020-08-18 09:08:49 -04:00
|
|
|
const infoContent = (
|
|
|
|
<>
|
2020-09-01 08:36:55 -04:00
|
|
|
The <strong>File outline</strong> is a new feature. Click the icon to learn
|
|
|
|
more.
|
2020-08-18 09:08:49 -04:00
|
|
|
</>
|
2020-06-29 09:05:08 -04:00
|
|
|
)
|
2020-08-18 09:08:49 -04:00
|
|
|
const tooltip = <Tooltip id="outline-info-tooltip">{infoContent}</Tooltip>
|
2020-06-29 09:05:08 -04:00
|
|
|
|
|
|
|
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
|