Commit 30650297 authored by timel's avatar timel

feat: simple pagination

parent aa88001e
Pipeline #23040 passed with stages
in 14 minutes and 27 seconds
...@@ -10,12 +10,11 @@ import { ...@@ -10,12 +10,11 @@ import {
import { import {
App, App,
Button, Button,
ConfigProvider,
Dropdown, Dropdown,
Input, Input,
type MenuProps, type MenuProps,
Pagination,
Space, Space,
type ThemeConfig,
} from "antd"; } from "antd";
import classNames from "classnames"; import classNames from "classnames";
import { isEqual } from "lodash-es"; import { isEqual } from "lodash-es";
...@@ -45,14 +44,6 @@ import { Filter } from "./Filter"; ...@@ -45,14 +44,6 @@ import { Filter } from "./Filter";
import styles from "./index.module.scss"; import styles from "./index.module.scss";
import { editingDeckToIDeck, iDeckToEditingDeck, type Type } from "./utils"; import { editingDeckToIDeck, iDeckToEditingDeck, type Type } from "./utils";
const theme: ThemeConfig = {
components: {
Layout: {
colorBgBody: "transparent",
},
},
};
export const loader: LoaderFunction = async () => { export const loader: LoaderFunction = async () => {
// 必须先加载卡组,不然页面会崩溃 // 必须先加载卡组,不然页面会崩溃
if (!initStore.decks) { if (!initStore.decks) {
...@@ -94,7 +85,6 @@ export const Component: React.FC = () => { ...@@ -94,7 +85,6 @@ export const Component: React.FC = () => {
return ( return (
<DndProvider backend={HTML5Backend}> <DndProvider backend={HTML5Backend}>
<ConfigProvider theme={theme}>
<Background /> <Background />
<div className={styles.layout} style={{ width: "100%" }}> <div className={styles.layout} style={{ width: "100%" }}>
<div className={styles.sider}> <div className={styles.sider}>
...@@ -132,7 +122,6 @@ export const Component: React.FC = () => { ...@@ -132,7 +122,6 @@ export const Component: React.FC = () => {
</div> </div>
</div> </div>
</div> </div>
</ConfigProvider>
</DndProvider> </DndProvider>
); );
}; };
...@@ -257,6 +246,10 @@ const Search: React.FC = () => { ...@@ -257,6 +246,10 @@ const Search: React.FC = () => {
setSearchResult(() => result); setSearchResult(() => result);
}; };
useEffect(() => {
handleSearch();
}, []);
const [_, dropRef] = useDrop({ const [_, dropRef] = useDrop({
accept: ["Card"], // 指明该区域允许接收的拖放物。可以是单个,也可以是数组 accept: ["Card"], // 指明该区域允许接收的拖放物。可以是单个,也可以是数组
// 里面的值就是useDrag所定义的type // 里面的值就是useDrag所定义的type
...@@ -422,9 +415,22 @@ const SearchResults: React.FC<{ ...@@ -422,9 +415,22 @@ const SearchResults: React.FC<{
const type = isExtraDeckCard(card.data.type ?? 0) ? "extra" : "main"; const type = isExtraDeckCard(card.data.type ?? 0) ? "extra" : "main";
editDeckStore.canAdd(card, type).result && editDeckStore.add(type, card); editDeckStore.canAdd(card, type).result && editDeckStore.add(type, card);
}; };
const itemsPerPage = 200; // 每页显示的数据数量
const [currentPage, setCurrentPage] = useState(1);
useEffect(() => {
setCurrentPage(1);
}, [results]);
const startIndex = (currentPage - 1) * itemsPerPage;
const endIndex = startIndex + itemsPerPage;
const currentData = results.slice(startIndex, endIndex);
return ( return (
<>
<div className={styles["search-cards"]}> <div className={styles["search-cards"]}>
{results.map((card) => ( {currentData.map((card) => (
<Card <Card
value={card} value={card}
key={card.id} key={card.id}
...@@ -433,6 +439,17 @@ const SearchResults: React.FC<{ ...@@ -433,6 +439,17 @@ const SearchResults: React.FC<{
/> />
))} ))}
</div> </div>
<div style={{ textAlign: "center", padding: "10px 0 20px" }}>
<Pagination
current={currentPage}
onChange={(page) => setCurrentPage(page)}
total={results.length}
showSizeChanger={false}
showLessItems
hideOnSinglePage
/>
</div>
</>
); );
}); });
......
...@@ -34,5 +34,12 @@ export const theme: ThemeConfig = { ...@@ -34,5 +34,12 @@ export const theme: ThemeConfig = {
boxShadow: boxShadow:
"0 6px 16px 0 rgb(51 51 51 / 80%), 0 3px 6px -4px rgba(0, 0, 0, 0.12), 0 9px 28px 8px rgba(0, 0, 0, 0.05)", "0 6px 16px 0 rgb(51 51 51 / 80%), 0 3px 6px -4px rgba(0, 0, 0, 0.12), 0 9px 28px 8px rgba(0, 0, 0, 0.05)",
}, },
Pagination: {
lineWidth: 0,
colorBgContainer: "hsla(0, 0%, 100%, 0.05)",
},
Layout: {
colorBgBody: "transparent",
},
}, },
}; };
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment