2021-12-29 13:33:36 +08:00
|
|
|
import React from "react";
|
2021-12-30 12:50:30 +08:00
|
|
|
import { usePagination } from "react-use-pagination";
|
2021-12-29 13:33:36 +08:00
|
|
|
|
2021-12-29 21:09:31 +08:00
|
|
|
import drivers from "../../static/drivers.json";
|
|
|
|
import { useFilteredObjs } from "../libs/store";
|
2021-12-30 22:46:15 +08:00
|
|
|
import Card from "./Card";
|
2021-12-30 12:50:30 +08:00
|
|
|
import Paginate from "./Paginate";
|
2021-12-29 21:09:31 +08:00
|
|
|
|
2021-12-30 12:50:30 +08:00
|
|
|
export default function Driver(): JSX.Element {
|
2021-12-29 21:09:31 +08:00
|
|
|
const {
|
|
|
|
filter,
|
|
|
|
setFilter,
|
|
|
|
filteredObjs: filteredDrivers,
|
|
|
|
} = useFilteredObjs(drivers);
|
2021-12-30 12:50:30 +08:00
|
|
|
|
|
|
|
const props = usePagination({
|
|
|
|
totalItems: filteredDrivers.length,
|
|
|
|
initialPageSize: 10,
|
|
|
|
});
|
|
|
|
const { startIndex, endIndex } = props;
|
2021-12-30 16:05:05 +08:00
|
|
|
const currentDrivers = filteredDrivers.slice(startIndex, endIndex + 1);
|
2021-12-30 12:50:30 +08:00
|
|
|
|
2021-12-29 21:09:31 +08:00
|
|
|
return (
|
|
|
|
<>
|
2021-12-30 12:50:30 +08:00
|
|
|
<div className="grid grid-cols-1 sm:grid-cols-2 gap-4 mt-4 px-4">
|
2021-12-29 21:09:31 +08:00
|
|
|
<input
|
2021-12-30 12:50:30 +08:00
|
|
|
className="w-full px-4 py-2 border rounded-full bg-light-nonepress-100 dark:bg-dark-nonepress-100"
|
2021-12-29 21:09:31 +08:00
|
|
|
value={filter}
|
2021-12-30 12:50:30 +08:00
|
|
|
placeholder="搜索驱动器"
|
2021-12-29 21:09:31 +08:00
|
|
|
onChange={(event) => setFilter(event.target.value)}
|
|
|
|
/>
|
2021-12-30 16:05:05 +08:00
|
|
|
<button className="w-full rounded-lg bg-hero text-white opacity-60">
|
2021-12-30 12:50:30 +08:00
|
|
|
发布驱动器
|
|
|
|
</button>
|
|
|
|
</div>
|
|
|
|
<div className="grid grid-cols-1 p-4">
|
|
|
|
<Paginate {...props} />
|
|
|
|
</div>
|
2021-12-30 22:46:15 +08:00
|
|
|
<div className="grid grid-cols-1 sm:grid-cols-2 gap-4 px-4">
|
2021-12-30 12:50:30 +08:00
|
|
|
{currentDrivers.map((driver, index) => (
|
2022-01-02 20:21:08 +08:00
|
|
|
<Card
|
|
|
|
key={index}
|
|
|
|
{...driver}
|
|
|
|
action={`nb driver install ${driver.project_link}`}
|
|
|
|
actionDisabled={!driver.project_link}
|
|
|
|
/>
|
2021-12-30 12:50:30 +08:00
|
|
|
))}
|
|
|
|
</div>
|
|
|
|
<div className="grid grid-cols-1 p-4">
|
|
|
|
<Paginate {...props} />
|
2021-12-29 21:09:31 +08:00
|
|
|
</div>
|
|
|
|
</>
|
|
|
|
);
|
2021-12-29 13:33:36 +08:00
|
|
|
}
|