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,45 +85,43 @@ export const Component: React.FC = () => { ...@@ -94,45 +85,43 @@ 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}> <ScrollableArea className={styles["deck-select-container"]}>
<ScrollableArea className={styles["deck-select-container"]}> <DeckSelect
<DeckSelect decks={snapDecks.decks}
decks={snapDecks.decks} selected={selectedDeck.deckName}
selected={selectedDeck.deckName} onSelect={(name) =>
onSelect={(name) => setSelectedDeck(deckStore.get(name) ?? deckStore.decks[0])
setSelectedDeck(deckStore.get(name) ?? deckStore.decks[0]) }
} onDelete={(id) => console.log(id)}
onDelete={(id) => console.log(id)} onDownload={(id) => console.log(id)}
onDownload={(id) => console.log(id)} onAdd={() => console.log("add")}
onAdd={() => console.log("add")} />
/> </ScrollableArea>
</ScrollableArea> <CardDetail code={123} open={false} onClose={() => {}} />
<CardDetail code={123} open={false} onClose={() => {}} /> </div>
<div className={styles.content}>
<div className={styles.deck}>
<DeckEditor
deck={selectedDeck}
onClear={editDeckStore.clear}
onReset={handleDeckEditorReset}
onSave={handleDeckEditorSave}
/>
</div> </div>
<div className={styles.content}> <div className={styles.select}>
<div className={styles.deck}> {sqlite.progress === 1 ? (
<DeckEditor <Search />
deck={selectedDeck} ) : (
onClear={editDeckStore.clear} <div className={styles.container}>
onReset={handleDeckEditorReset} <Loading />
onSave={handleDeckEditorSave} </div>
/> )}
</div>
<div className={styles.select}>
{sqlite.progress === 1 ? (
<Search />
) : (
<div className={styles.container}>
<Loading />
</div>
)}
</div>
</div> </div>
</div> </div>
</ConfigProvider> </div>
</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,17 +415,41 @@ const SearchResults: React.FC<{ ...@@ -422,17 +415,41 @@ 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"]}> <>
{results.map((card) => ( <div className={styles["search-cards"]}>
<Card {currentData.map((card) => (
value={card} <Card
key={card.id} value={card}
source="search" key={card.id}
onClick={() => handleClick(card)} source="search"
onClick={() => handleClick(card)}
/>
))}
</div>
<div style={{ textAlign: "center", padding: "10px 0 20px" }}>
<Pagination
current={currentPage}
onChange={(page) => setCurrentPage(page)}
total={results.length}
showSizeChanger={false}
showLessItems
hideOnSinglePage
/> />
))} </div>
</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