🚧 add store pagination

This commit is contained in:
yanyongyu
2021-12-30 12:50:30 +08:00
parent 23d0b2509e
commit d1706e438b
7 changed files with 75 additions and 18 deletions

45
website/src/libs/store.ts Normal file
View File

@ -0,0 +1,45 @@
import { useState } from "react";
type Tag = {
label: string;
color: string;
};
type Obj = {
module_name?: string;
project_link?: string;
name: string;
desc: string;
author: string;
homepage: string;
tags: Tag[];
is_official: boolean;
};
export function filterObjs(filter: string, objs: Obj[]): Obj[] {
return objs.filter((o) => {
return (
o.module_name?.indexOf(filter) != -1 ||
o.project_link?.indexOf(filter) != -1 ||
o.name.indexOf(filter) != -1 ||
o.desc.indexOf(filter) != -1 ||
o.author.indexOf(filter) != -1
);
});
}
type useFilteredObjsReturn = {
filter: string;
setFilter: (filter: string) => void;
filteredObjs: Obj[];
};
export function useFilteredObjs(objs: Obj[]): useFilteredObjsReturn {
const [filter, setFilter] = useState<string>("");
const filteredObjs = filterObjs(filter, objs);
return {
filter,
setFilter,
filteredObjs,
};
}