import Skeleton from 'react-loading-skeleton'
import "./contents.css"
const Contents = ({data, readerRef, readerHeight, currentPage, setCurrentPage}) => {
const Chapter = ({title, id, subId}) => {
if (!readerRef.current) return
let totalSections = readerRef.current.getElementsByTagName("section")
if (totalSections[id] === undefined) return
let anchorOffset = totalSections[id].offsetTop
let nextAnchorOffset
if (totalSections[id+1] != undefined) {
nextAnchorOffset = totalSections[id+1].offsetTop
}
let anchorPage = Math.ceil(anchorOffset / readerHeight)
let nextAnchorPage
if (nextAnchorOffset) {
nextAnchorPage = Math.ceil(nextAnchorOffset / readerHeight)
}
return
{
setCurrentPage(anchorPage)
}}
style={{
backgroundColor: currentPage >= anchorPage && currentPage < nextAnchorPage || currentPage == anchorPage ? "var(--md-sys-color-primary-container)" : ""
}}
>
{title}
}
if (!readerRef.current || readerRef.current.getElementsByTagName("section").length === 0) {
return
}
let anchors = data.map(chapter => {
let chapters = []
if (chapter.title === "") return false
chapters.push()
if (chapter.subChapters) {
chapter.subChapters.map(subchapter => {
if (subchapter.title === "") return false
chapters.push()
})
}
return chapters
}).filter(val => val !== false)
if (anchors.length === 0) {
return <>>
}
return
{
anchors
}
}
export default Contents