mirror of
https://github.com/nix-community/noogle.git
synced 2024-12-22 16:31:31 +03:00
8679af38a2
* add: deeplinks * add: enhanced pagination for large datasets * add more meta tags * add data to initial state * remove preview page, instead link directly into the list
57 lines
1.5 KiB
TypeScript
57 lines
1.5 KiB
TypeScript
import { Box } from "@mui/system";
|
|
import { useMemo } from "react";
|
|
import { PageState } from "../../models/internals";
|
|
import { byQuery, byType, pipe } from "../../queries";
|
|
import { DocItem } from "../../models/nix";
|
|
import { BasicList, BasicListItem } from "../basicList";
|
|
import FunctionItem from "../functionItem/functionItem";
|
|
import { SetPageStateVariable } from "../pageContext";
|
|
|
|
interface FunctionsProps {
|
|
pageState: PageState;
|
|
setPageStateVariable: SetPageStateVariable;
|
|
}
|
|
|
|
export function NixFunctions(props: FunctionsProps) {
|
|
const { pageState, setPageStateVariable } = props;
|
|
const { data, selected, term, filter } = pageState;
|
|
|
|
const setSelected = setPageStateVariable<string | null>("selected");
|
|
|
|
const filteredData = useMemo(
|
|
() => pipe(byType(filter), byQuery(term))(data),
|
|
[filter, term, data]
|
|
);
|
|
|
|
const preRenderedItems: BasicListItem[] = filteredData.map(
|
|
(docItem: DocItem) => {
|
|
const key = docItem.id;
|
|
return {
|
|
item: (
|
|
<Box
|
|
sx={{
|
|
width: "100%",
|
|
height: "100%",
|
|
}}
|
|
onClick={!(selected === key) ? () => setSelected(key) : undefined}
|
|
>
|
|
<FunctionItem
|
|
name={docItem.name}
|
|
docItem={docItem}
|
|
selected={selected === key}
|
|
handleClose={() => setSelected(null)}
|
|
/>
|
|
</Box>
|
|
),
|
|
key,
|
|
};
|
|
}
|
|
);
|
|
|
|
return (
|
|
<Box sx={{ ml: { xs: 0, md: 2 } }}>
|
|
<BasicList items={preRenderedItems} />
|
|
</Box>
|
|
);
|
|
}
|