|
@@ -1,32 +1,82 @@
|
|
|
"use client";
|
|
|
+import { GameListRep, searchGameListApi, SearchProps } from "@/api/home";
|
|
|
import Box from "@/components/Box";
|
|
|
-import { Mask, SearchBar } from "antd-mobile";
|
|
|
+import { useSearchStore } from "@/stores/useSearchStore";
|
|
|
+import { debounce } from "@/utils/methods";
|
|
|
+import { Button, createErrorBlock, Mask, SearchBar } from "antd-mobile";
|
|
|
import { useTranslations } from "next-intl";
|
|
|
-import { FC, PropsWithChildren, useState } from "react";
|
|
|
+import { FC, PropsWithChildren, useRef, useState } from "react";
|
|
|
+import GroupCard from "../../../../components/Card/GroupCard";
|
|
|
interface Props {}
|
|
|
|
|
|
interface ContentProps {
|
|
|
closeHandler: () => void;
|
|
|
}
|
|
|
+
|
|
|
+const ErrorBlock = createErrorBlock({
|
|
|
+ empty: <div className={"iconfont icon-meiyoushuju text-[0.5556rem] text-[#666]"}></div>,
|
|
|
+ default: <div></div>,
|
|
|
+});
|
|
|
const Content: FC<ContentProps> = (props) => {
|
|
|
const t = useTranslations("HomePage");
|
|
|
const { closeHandler } = props;
|
|
|
- const changeHandler = (value: string) => {};
|
|
|
+ const [games, setGames] = useState<GameListRep[]>([]);
|
|
|
+ const searchStore = useSearchStore();
|
|
|
+ const [visible, setVisible] = useState(false);
|
|
|
+ const params = useRef<SearchProps>({
|
|
|
+ current_page: 1,
|
|
|
+ page_size: 12,
|
|
|
+ use_page: true,
|
|
|
+ search_game_name: "",
|
|
|
+ });
|
|
|
+
|
|
|
+ const getGames = async (): Promise<GameListRep[] | undefined> => {
|
|
|
+ return searchGameListApi(params.current).then((res) => {
|
|
|
+ setVisible(!res.page.is_end);
|
|
|
+ if (res.data) {
|
|
|
+ return res.data;
|
|
|
+ }
|
|
|
+ });
|
|
|
+ };
|
|
|
+ const isPending = () =>
|
|
|
+ games.length === 0 &&
|
|
|
+ params.current.search_game_name === "" &&
|
|
|
+ params.current.current_page === 1;
|
|
|
+ const setSearchValueInit = (value: string) => {
|
|
|
+ params.current.search_game_name = value;
|
|
|
+ getGames().then((data) => data && setGames(data));
|
|
|
+ };
|
|
|
+ const func = debounce(setSearchValueInit, 500);
|
|
|
+ const changeHandler = (value: string) => {
|
|
|
+ if (value) func(value);
|
|
|
+ };
|
|
|
+ const onCancel = () => {
|
|
|
+ closeHandler();
|
|
|
+ params.current.current_page = 1;
|
|
|
+ params.current.search_game_name = "";
|
|
|
+ setGames([]);
|
|
|
+ setVisible(false);
|
|
|
+ };
|
|
|
+
|
|
|
+ const nextHandler = async () => {
|
|
|
+ params.current.current_page++;
|
|
|
+ return getGames().then((data) => data && setGames((games) => games.concat(data)));
|
|
|
+ };
|
|
|
|
|
|
- // @ts-ignore
|
|
|
return (
|
|
|
- <Box>
|
|
|
- <section className={"home-search"}>
|
|
|
+ <Box className={"flex h-[100dvh] flex-col"}>
|
|
|
+ <div className={"home-search flex-shrink-0"}>
|
|
|
<SearchBar
|
|
|
className={"rounded-[0.05rem] bg-[#191919]"}
|
|
|
style={{
|
|
|
"--background": "transparent",
|
|
|
"--height": "0.3rem",
|
|
|
}}
|
|
|
+ aria-hidden="true"
|
|
|
placeholder={t("search")}
|
|
|
showCancelButton={() => true}
|
|
|
onChange={changeHandler}
|
|
|
- onCancel={closeHandler}
|
|
|
+ onCancel={onCancel}
|
|
|
/>
|
|
|
<div
|
|
|
className={
|
|
@@ -35,15 +85,63 @@ const Content: FC<ContentProps> = (props) => {
|
|
|
>
|
|
|
{t("searchTips")}
|
|
|
</div>
|
|
|
- </section>
|
|
|
+
|
|
|
+ {/*<div className={"flex items-center justify-between"}>*/}
|
|
|
+ {/* <header> Histórico de busca </header>*/}
|
|
|
+ {/* <i className="iconfont icon-guanbi cursor-pointer text-[0.08rem]"></i>*/}
|
|
|
+ {/*</div>*/}
|
|
|
+ {/*<div className={"mt-[0.05rem] flex"}>*/}
|
|
|
+ {/* {searchStore.history.map((item, index) => {*/}
|
|
|
+ {/* return (*/}
|
|
|
+ {/* <div*/}
|
|
|
+ {/* className={*/}
|
|
|
+ {/* "flex items-center bg-[#1a1a1a]" +*/}
|
|
|
+ {/* " text-[#b3b3b3]" +*/}
|
|
|
+ {/* " rounded-[0.04rem] px-[0.05rem] py-[0.03rem]"*/}
|
|
|
+ {/* }*/}
|
|
|
+ {/* key={index}*/}
|
|
|
+ {/* >*/}
|
|
|
+ {/* <span className={"mr-[0.2rem]"}>{item}</span>*/}
|
|
|
+ {/* <i className="iconfont icon-guanbi cursor-pointer text-[0.08rem]"></i>*/}
|
|
|
+ {/* </div>*/}
|
|
|
+ {/* );*/}
|
|
|
+ {/* })}*/}
|
|
|
+ {/*</div>*/}
|
|
|
+ </div>
|
|
|
+ <div className={"mt-[0.13rem] flex-1 overflow-y-scroll"}>
|
|
|
+ {games.length ? (
|
|
|
+ <GroupCard data={games} row={1} />
|
|
|
+ ) : (
|
|
|
+ <ErrorBlock
|
|
|
+ status={isPending() ? "default" : "empty"}
|
|
|
+ description={""}
|
|
|
+ title={isPending() ? "" : "no data"}
|
|
|
+ />
|
|
|
+ )}
|
|
|
+ <div className={"mt-[0.1rem]"}>
|
|
|
+ {visible && (
|
|
|
+ <Button
|
|
|
+ fill={"none"}
|
|
|
+ color={"default"}
|
|
|
+ loading="auto"
|
|
|
+ onClick={async () => {
|
|
|
+ await nextHandler();
|
|
|
+ }}
|
|
|
+ block={true}
|
|
|
+ style={{ "--background-color": "#1a1a1a", "--text-color": "#c4c4c4" }}
|
|
|
+ >
|
|
|
+ {t("searchButton")}
|
|
|
+ </Button>
|
|
|
+ )}
|
|
|
+ </div>
|
|
|
+ </div>
|
|
|
</Box>
|
|
|
);
|
|
|
};
|
|
|
const HomeSearch: FC<PropsWithChildren<Props>> = (props) => {
|
|
|
const t = useTranslations("HomePage");
|
|
|
- const [visible, setVisible] = useState(true);
|
|
|
+ const [visible, setVisible] = useState(false);
|
|
|
const handler = () => {
|
|
|
- console.log(`🎯🎯🎯🎯🎯-> in HomeSearch.tsx on 9`, "");
|
|
|
setVisible(true);
|
|
|
};
|
|
|
return (
|
|
@@ -58,7 +156,7 @@ const HomeSearch: FC<PropsWithChildren<Props>> = (props) => {
|
|
|
<i className={"iconfont icon-sousuo1 mr-[0.0833rem] text-[0.16rem]"}></i>
|
|
|
<span className={"text-[0.12rem]"}>{t("search")}</span>
|
|
|
</div>
|
|
|
- <Mask visible={visible} opacity={0.9}>
|
|
|
+ <Mask visible={visible} opacity={0.9} getContainer={null}>
|
|
|
<Content closeHandler={() => setVisible(false)} />
|
|
|
</Mask>
|
|
|
</>
|