import { ElementRef, FC, useMemo, useRef } from 'react' import { GroupBox } from './GroupBox/GroupBox' import styles from './Home.module.css' import { EnrichedEntity } from '../../src/types' import { EntitySpan } from './EntitySpan/EntitySpan' import { useGroups } from '../contexts/GroupProvider' import { Preferences } from './Preferences/Preferences' import { download, streamToArrayBuffer } from '../../src/download' import Link from 'next/link' import { useRouter } from 'next/router' import { i18n, I18n } from '../shared/I18n/I18n' import { useFactories } from '../contexts/FactoryProvider' import { GraphIcon } from '../icons/GraphIcon' import { useIntl } from 'react-intl' export const Home: FC = () => { const intl = useIntl() const { query } = useRouter() const { factories } = useFactories() const preferencesRef = useRef>(null) const { groups, doNotSuggest, ignoredFactories, setIgnoredFactories, store, load } = useGroups() const inputRef = useRef(null) const [missingExport, missingMall] = useMemo<[EnrichedEntity[], EnrichedEntity[]]>(() => { return factories .filter(factory => !doNotSuggest.has(factory.href) && factory.recipe) .reduce( (acc, factory) => (factory.usedBy?.length ?? 0) >= 3 ? [[...acc[0], factory], acc[1]] : [acc[0], [...acc[1], factory]], [[], []] as [EnrichedEntity[], EnrichedEntity[]] ) }, [factories, doNotSuggest]) return (

{ const stream = evt.currentTarget.files?.[0].stream() as | globalThis.ReadableStream | undefined if (stream) { const array = await streamToArrayBuffer(stream) load(array) if (inputRef.current) inputRef.current.value = null as unknown as string } }} />
{missingExport.map(missing => ( { preferencesRef.current?.addGroup(missing.name, [missing.href]) }} onContextMenu={event => { event.preventDefault() setIgnoredFactories([...ignoredFactories, missing.href]) }} leftClickText={i18n(intl, 'page.home.tooltip.action.add_to_new_export')} rightClickText={i18n(intl, 'page.home.tooltip.action.exclude_suggestion')} /> ))}
{missingMall.map(missing => ( { preferencesRef.current?.addGroup(missing.name, undefined, [missing.href]) }} onContextMenu={event => { event.preventDefault() setIgnoredFactories([...ignoredFactories, missing.href]) }} leftClickText={i18n(intl, 'page.home.tooltip.action.add_to_new_mall')} rightClickText={i18n(intl, 'page.home.tooltip.action.exclude_suggestion')} /> ))}
{Object.values(groups) .sort((a, b) => a.name.localeCompare(b.name)) .map(group => ( ))}
) }