import React, { memo, useState, FC, useEffect, useMemo, useRef } from 'react' import { IssueFeedCell } from '../general/cells' import { issueExtractor } from '@app/utils' import { FeedHeading } from './heading' import type { FeedComponentProps } from './interface' import { FixedSizeList as List } from 'react-window' import { getListHeight } from './utils' import { FilterManager } from '@app/managers/filters' import { Feed } from 'a11ywatch-web-wasm' import { PageIssue } from '@app/types' interface RowProps { index: number style?: React.CSSProperties } // base feed props interface BaseFeed extends Omit { feed: Feed domain: string pageUrl: string } // List of issues rendered. const LiveFeedComponent: FC = ({ onScanEvent, isHidden, fullScreen, highlightErrors, feed, domain, pageUrl, }) => { const [sectionHidden, onToggleSection] = useState(!!isHidden) const [pageIssues, setPageIssues] = useState([]) const [pageMatchers, setPageMatchers] = useState>(new Set()) const currentIssueCount = useRef(0) // allow feed adjustment at render for manual triggering const issue = feed?.get_page(domain, pageUrl) const pIssues = issueExtractor(issue) // array of issues extract duplex types useEffect(() => { for (const item of pageIssues) { FilterManager.addFilter(item?.code) } }, [pageIssues]) useEffect(() => { const shouldUpdate = currentIssueCount.current !== pIssues.length if (shouldUpdate) { // run side effect once per issue transition if (pageIssues.length < pIssues.length) { setPageIssues(pIssues) } else if (pageIssues.length > pIssues.length) { const matches: Set = new Set() // determine already fixed for (const iss of pIssues) { matches.add(iss.code + iss.selector + iss.context) } setPageMatchers(matches) } currentIssueCount.current = pIssues.length } }, [pageIssues, pIssues, setPageIssues, currentIssueCount, setPageMatchers]) const Row = ({ index, style }: RowProps) => { const item = pageIssues[index] return ( ) } const issueCount = pageIssues.length const { size, height } = useMemo( () => getListHeight({ fullScreen, issueCount }), [fullScreen, issueCount] ) if (fullScreen) { return (
{Row}
) } const highLight = highlightErrors && issue?.issues?.length && issue.issues[0]?.type === 'error' return (
  • {sectionHidden ? null : (
      {Row}
    )}
  • ) } export const LiveFeedList = memo(LiveFeedComponent)