import React, { useContext, useCallback, useRef, useEffect } from 'react'
import Row from './Row'
import Range from './Range'
import { ConfigContext } from './Table'
import { TableDispatch, SELECTING, VSCROLL } from './actions'
import PropTypes from 'prop-types'
import { TableStateType, ColumnsType, Modes, RangeType } from './prop-types'
import { SCROLLABLE, FIXED, ScrollerDispatch } from './reducers/scrollerReducer'
import { LEVELS, log } from './utils'
import './Body.css'
const Body = props => {
log('Body', LEVELS.INFO, props)
const { rowIdAttr } = useContext(ConfigContext)
const scrollerDispatch = useContext(ScrollerDispatch)
const { state, columns, colOrder, mode, range } = props
const { data, selectedIds, scrollTop = 0 } = state
const dispatch = useContext(TableDispatch)
const handleCellCheckChange = useCallback(
event => {
const id = event.target.dataset.id
const newSelectedIds = new Set(selectedIds)
if (event.target.checked) {
newSelectedIds.add(id)
} else {
newSelectedIds.delete(id)
}
dispatch({
type: SELECTING,
selectedIds: newSelectedIds
})
},
[selectedIds, dispatch]
)
const handleScroll = useCallback(event => {
dispatch({ type: VSCROLL, scrollTop: event.target.scrollTop, isScrollEnd: false })
}, [])
const handleScrollEnd = useCallback(event => {
dispatch({ type: VSCROLL, scrollTop: event.target.scrollTop, isScrollEnd: true })
}, [])
const ref = useRef(null)
useEffect(() => {
const { current } = ref
if (current) {
Copyright 2020 Ulrich Gaal
Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. You may obtain a copy of the License at
Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License.