import * as React from "react"; declare const window: any; const { Layout, Input, Empty, PageHeader, Row, Col } = window.antd; const { Header, Content, Footer } = Layout; const { Search } = Input; import "./index.scss"; import { ComponentItem, IComponentItemProps } from "./component-item"; import { useState } from "react"; import lscWindowConfig from "../../utils/lscConfig"; import { NPM_HOST } from "../../constants"; const { LibraryName } = lscWindowConfig; const Components = window[LibraryName]; export default function PageList() { const [searchValue, setSearchValue] = useState(""); const componentInfo: IComponentItemProps[] = Object.entries(Components) .map(([, item]: any) => { const docgenInfo = item.__docgenInfo || {}; const docsPath = item.__docsPath; const previewPath = item.__previewPath; const href = docsPath && docsPath.replace(/js$/, "html"); return { component: item, docsPath, href, preview: previewPath, title: item.displayName, description: docgenInfo.description || "", author: docgenInfo.author, workNo: docgenInfo.workNo, category: docgenInfo.category, updateTime: docgenInfo.mtime }; }) .filter(({ title }) => !!title); const componentCount = componentInfo.length; const componentListData = componentInfo // search .filter(({ title = "" }) => title.toLowerCase().includes(searchValue.toLowerCase()) ) .sort((a, b) => { if (!b.updateTime) { return -999999999999; } return b.updateTime - a.updateTime; }) .sort((a, b) => { return +!!b.docsPath - +!!a.docsPath; }) // category .reduce( (previousValue, currentValue) => { const { category = "" } = currentValue; if (!previousValue[category]) { previousValue[category] = []; } previousValue[category].push(currentValue); return previousValue; }, { "": [] } as Record ); // put in the end const noneComponents = componentListData[""]; delete componentListData[""]; componentListData[""] = noneComponents; return (
{Object.keys(componentListData).length ? ( Object.entries(componentListData).map( ( [title, components]: [string, IComponentItemProps[]], categoryIndex ) => { return ( <> {title ? : null}
{components.map((data, index) => ( ))}
); } ) ) : ( )}
); }