|
@@ -2,8 +2,8 @@ import { GameListRep, searchGameListApi } from "@/api/home";
|
|
|
import Card from "@/components/Card/Card";
|
|
|
import Empty from "@/components/Empty";
|
|
|
import { GameListTypeEnum } from "@/enums";
|
|
|
-import { debounce } from "@/utils/methods";
|
|
|
-import { InfiniteScroll } from "antd-mobile";
|
|
|
+import { useDebounceEffect } from "ahooks";
|
|
|
+import { InfiniteScroll, Loading } from "antd-mobile";
|
|
|
import React from "react";
|
|
|
import styles from "./page.module.scss";
|
|
|
|
|
@@ -13,7 +13,7 @@ interface Props {
|
|
|
|
|
|
const Left: React.FC<Props> = ({ actInfo }) => {
|
|
|
const [data, setData] = React.useState<GameListRep[]>([]);
|
|
|
- const [loading, setLoading] = React.useState<boolean>(false);
|
|
|
+ const [loading, setLoading] = React.useState<boolean>(true);
|
|
|
const [hasMore, setHasMore] = React.useState(true);
|
|
|
const [isInit, setIsInit] = React.useState(true);
|
|
|
const PageRef = React.useRef({
|
|
@@ -21,14 +21,21 @@ const Left: React.FC<Props> = ({ actInfo }) => {
|
|
|
page_size: 15,
|
|
|
});
|
|
|
|
|
|
+ useDebounceEffect(() => {
|
|
|
+ toInitFn();
|
|
|
+ }, [actInfo]);
|
|
|
+
|
|
|
React.useEffect(() => {
|
|
|
setData([]);
|
|
|
- setHasMore(true);
|
|
|
- setLoading(false);
|
|
|
setIsInit(true);
|
|
|
- PageRef.current.current_page = 0;
|
|
|
+ setLoading(true);
|
|
|
}, [actInfo]);
|
|
|
|
|
|
+ const toInitFn = () => {
|
|
|
+ PageRef.current.current_page = 0;
|
|
|
+ setHasMore(true);
|
|
|
+ };
|
|
|
+
|
|
|
const getData = async () => {
|
|
|
if (!actInfo?.id) return;
|
|
|
try {
|
|
@@ -55,29 +62,36 @@ const Left: React.FC<Props> = ({ actInfo }) => {
|
|
|
setLoading(false);
|
|
|
}
|
|
|
};
|
|
|
- const loadMore = debounce(async () => {
|
|
|
- if (!hasMore || loading || !actInfo?.id) return;
|
|
|
+ const loadMore = async () => {
|
|
|
+ if (!hasMore || (loading && !isInit) || !actInfo?.id) return;
|
|
|
PageRef.current.current_page += 1;
|
|
|
getData();
|
|
|
- }, 500) as () => Promise<void>;
|
|
|
+ };
|
|
|
|
|
|
return (
|
|
|
<div className={styles.right}>
|
|
|
- <div className={styles.rightBox}>
|
|
|
- {data.map((item) => {
|
|
|
- return (
|
|
|
- <Card
|
|
|
- key={`${actInfo?.type}_${actInfo?.id}_${item.id}`}
|
|
|
- item={item}
|
|
|
- className={styles.gameCard}
|
|
|
- isShowFavorite={true}
|
|
|
- isShowOnline={true}
|
|
|
- ></Card>
|
|
|
- );
|
|
|
- })}
|
|
|
- </div>
|
|
|
+ {loading && isInit && (
|
|
|
+ <div className="flex h-[100%] items-center justify-center">
|
|
|
+ <Loading></Loading>
|
|
|
+ </div>
|
|
|
+ )}
|
|
|
{(isInit || data.length > 0) && (
|
|
|
- <InfiniteScroll loadMore={loadMore} hasMore={hasMore}></InfiniteScroll>
|
|
|
+ <>
|
|
|
+ <div className={styles.rightBox}>
|
|
|
+ {data.map((item) => {
|
|
|
+ return (
|
|
|
+ <Card
|
|
|
+ key={`${actInfo?.type}_${actInfo?.id}_${item.id}`}
|
|
|
+ item={item}
|
|
|
+ className={styles.gameCard}
|
|
|
+ isShowFavorite={true}
|
|
|
+ isShowOnline={true}
|
|
|
+ ></Card>
|
|
|
+ );
|
|
|
+ })}
|
|
|
+ </div>
|
|
|
+ <InfiniteScroll loadMore={loadMore} hasMore={hasMore}></InfiniteScroll>
|
|
|
+ </>
|
|
|
)}
|
|
|
|
|
|
{!isInit && !loading && data.length <= 0 && <Empty></Empty>}
|