import PropTypes from 'prop-types'; import { find, findIndex, reduce } from 'ramda'; import React, { Component } from 'react'; import { Column, Table } from 'react-virtualized'; import { ContactItem } from '../ContactItem'; import i18n from './i18n'; import styles from './styles.scss'; const CAPTION_HEIGHT = 20; const ROW_HEIGHT = 50; // @ts-expect-error const Placeholder = ({ message }) => { return
{message}
; }; Placeholder.propTypes = { message: PropTypes.string.isRequired, }; class ContactList extends Component { // @ts-expect-error constructor(props) { super(props); this.state = ContactList.getDerivedStateFromProps(props); // @ts-expect-error this.list = React.createRef(); } static getDerivedStateFromProps( // @ts-expect-error props, state = { scrollTop: 0, currentCaption: '' }, ) { // @ts-expect-error if (props.contactGroups !== state.lastContactGroups) { return { ...reduce( (nextState, group) => { // @ts-expect-error nextState.captions.push(group.caption); // skip the caption row for the first group const rowOffset = nextState.groups.length !== 0 ? 1 : 0; if (rowOffset) { // @ts-expect-error nextState.captionRows[nextState.rowCount] = group.caption; } (nextState.groups as any).push({ // @ts-expect-error ...group, startIndex: nextState.rowCount + rowOffset, }); // @ts-expect-error nextState.rowCount += group.contacts.length + rowOffset; // with caption row // @ts-expect-error nextState.contactCount += group.contacts.length; return nextState; }, { ...state, groups: [], captions: [], captionRows: {}, rowCount: 0, contactCount: 0, }, props.contactGroups, ), lastContactGroups: props.contactGroups, }; } return state; } // @ts-expect-error componentDidUpdate(prevProps) { // @ts-expect-error if (this.state.lastContactGroups !== prevProps.contactGroups) { if ( // @ts-expect-error this.list && // @ts-expect-error this.list.current && // @ts-expect-error this.list.current.recomputeRowHeights ) { // @ts-expect-error this.list.current.recomputeRowHeights(0); } } } // @ts-expect-error isBottomNoticeRow(rowIndex) { // @ts-expect-error return this.props.bottomNotice && rowIndex === this.state.rowCount; } // @ts-expect-error calculateRowHeight = ({ index }) => { if (this.isBottomNoticeRow(index)) { // @ts-expect-error return this.props.bottomNoticeHeight; } // @ts-expect-error if (this.state.captionRows[index]) { return CAPTION_HEIGHT; } return ROW_HEIGHT; }; // @ts-expect-error findGroup = ({ index }) => find( (item) => // @ts-expect-error index >= item.startIndex && // @ts-expect-error index < item.startIndex + item.contacts.length, // @ts-expect-error this.state.groups, ); // @ts-expect-error rowGetter = ({ index }) => { if (this.isBottomNoticeRow(index)) { return { bottomNoticeRow: true, }; } // @ts-expect-error if (this.state.captionRows[index]) { return { // @ts-expect-error caption: this.state.captionRows[index], }; } const group = this.findGroup({ index }); // @ts-expect-error return group.contacts[index - group.startIndex]; }; // @ts-expect-error onScroll = ({ scrollTop }) => { // @ts-expect-error if (scrollTop !== this.state.scrollTop) { this.setState({ scrollTop, }); } }; resetScrollTop() { this.setState({ scrollTop: 0, }); } // @ts-expect-error cellRenderer = ({ rowData }) => { if (rowData.bottomNoticeRow) { // @ts-expect-error const { bottomNotice: BottomNotice } = this.props; return BottomNotice ?