Commit e4e6b9f5 authored by timel's avatar timel

feat: search card

parent 479b78a7
Pipeline #22977 failed with stages
in 15 minutes and 25 seconds
...@@ -62,7 +62,7 @@ export async function fetchCard(id: number): Promise<CardMeta> { ...@@ -62,7 +62,7 @@ export async function fetchCard(id: number): Promise<CardMeta> {
* @returns 卡片数据 * @returns 卡片数据
* *
* */ * */
export async function searchCard( export async function searchCards(
query: string, query: string,
type?: number type?: number
): Promise<CardMeta[]> { ): Promise<CardMeta[]> {
...@@ -77,7 +77,7 @@ export async function searchCard( ...@@ -77,7 +77,7 @@ export async function searchCard(
// @ts-ignore // @ts-ignore
window.fetchCard = fetchCard; window.fetchCard = fetchCard;
// @ts-ignore // @ts-ignore
window.searchCard = searchCard; window.searchCard = searchCards;
export function getCardStr(meta: CardMeta, idx: number): string | undefined { export function getCardStr(meta: CardMeta, idx: number): string | undefined {
switch (idx) { switch (idx) {
......
...@@ -102,3 +102,7 @@ ...@@ -102,3 +102,7 @@
gap: 10px; gap: 10px;
} }
} }
.search-count {
font-size: 11px;
}
...@@ -26,6 +26,7 @@ import { CardDetail } from "./CardDetail"; ...@@ -26,6 +26,7 @@ import { CardDetail } from "./CardDetail";
import { DeckSelect } from "./DeckSelect"; import { DeckSelect } from "./DeckSelect";
import styles from "./index.module.scss"; import styles from "./index.module.scss";
import { LoaderFunction } from "react-router-dom"; import { LoaderFunction } from "react-router-dom";
import { searchCards, type CardMeta } from "@/api";
const theme: ThemeConfig = { const theme: ThemeConfig = {
components: { components: {
...@@ -147,14 +148,28 @@ const DeckEditor: React.FC<{ ...@@ -147,14 +148,28 @@ const DeckEditor: React.FC<{
/** 卡片库,选择卡片加入正在编辑的卡组 */ /** 卡片库,选择卡片加入正在编辑的卡组 */
const CardSelect: React.FC = () => { const CardSelect: React.FC = () => {
const [searchResult, setSearchResult] = useState<number[]>([]); const [searchWord, setSearchWord] = useState("");
const [searchResult, setSearchResult] = useState<CardMeta[]>([]);
const handleSearch = async () => {
const result = await searchCards(searchWord);
setSearchResult(result);
};
return ( return (
<div className={styles.container}> <div className={styles.container}>
<div className={styles.title}> <div className={styles.title}>
<Input <Input
placeholder="搜索卡片" placeholder="搜索卡片"
bordered={false} bordered={false}
suffix={<Button type="text" icon={<SearchOutlined />} />} suffix={
<Button
type="text"
icon={<SearchOutlined />}
onClick={handleSearch}
/>
}
value={searchWord}
onChange={(e) => setSearchWord(e.target.value)}
onKeyUp={(e) => e.key === "Enter" && handleSearch()}
/> />
</div> </div>
<div className={styles["select-btns"]}> <div className={styles["select-btns"]}>
...@@ -164,7 +179,12 @@ const CardSelect: React.FC = () => { ...@@ -164,7 +179,12 @@ const CardSelect: React.FC = () => {
{false && <Badge dot offset={[5, -5]} />} {false && <Badge dot offset={[5, -5]} />}
</Button> </Button>
<Button block type="text" icon={<SortAscendingOutlined />}> <Button block type="text" icon={<SortAscendingOutlined />}>
<span>
排列 排列
<span className={styles["search-count"]}>
({searchResult.length})
</span>
</span>
{false && <Badge dot offset={[5, -5]} />} {false && <Badge dot offset={[5, -5]} />}
</Button> </Button>
<Button block type="text" icon={<DeleteOutlined />}> <Button block type="text" icon={<DeleteOutlined />}>
...@@ -173,8 +193,10 @@ const CardSelect: React.FC = () => { ...@@ -173,8 +193,10 @@ const CardSelect: React.FC = () => {
</div> </div>
<ScrollableArea className={styles["search-cards-container"]}> <ScrollableArea className={styles["search-cards-container"]}>
<div className={styles["search-cards"]}> <div className={styles["search-cards"]}>
{Array.from({ length: 60 }).map((_, i) => ( {searchResult.map(({ id }, i) => (
<div className={styles.card} key={i} /> <div className={styles.card} key={i}>
<YgoCard code={id} />
</div>
))} ))}
</div> </div>
</ScrollableArea> </ScrollableArea>
......
...@@ -20,11 +20,13 @@ export const loader: LoaderFunction = async () => { ...@@ -20,11 +20,13 @@ export const loader: LoaderFunction = async () => {
const user = getCookie<User>(CookieKeys.USER); const user = getCookie<User>(CookieKeys.USER);
if (user) accountStore.login(user); if (user) accountStore.login(user);
// 加载卡组 // 加载卡组
if (!initStore.decks)
deckStore.initialize().then(() => (initStore.decks = true)); deckStore.initialize().then(() => (initStore.decks = true));
// 加载ygodb // 加载ygodb
if (!initStore.sqlite.progress) {
initSqlite().then(() => (initStore.sqlite.progress = 1)); initSqlite().then(() => (initStore.sqlite.progress = 1));
initStore.sqlite.progress = 0.01; initStore.sqlite.progress = 0.01;
}
return null; return null;
}; };
......
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