|
@@ -1,5 +1,6 @@
|
|
|
"use client";
|
|
|
import { GameListRep, GroupType } from "@/api/home";
|
|
|
+import { GameListTypeEnum } from "@/enums";
|
|
|
import { useRouter } from "@/i18n/routing";
|
|
|
import { useProviderStore } from "@/stores/useProvider";
|
|
|
import { server } from "@/utils/client";
|
|
@@ -8,8 +9,8 @@ import React from "react";
|
|
|
import styles from "./page.module.scss";
|
|
|
|
|
|
interface Props {
|
|
|
- actId: number;
|
|
|
- onChage?: (id: number) => void;
|
|
|
+ actInfo: { type: string; id: number };
|
|
|
+ onChage?: (p: { type: GameListTypeEnum; id: number }) => void;
|
|
|
onInit?: () => void;
|
|
|
}
|
|
|
|
|
@@ -25,7 +26,10 @@ const getGames = async () => {
|
|
|
});
|
|
|
};
|
|
|
|
|
|
-const Left: React.FC<Props> = ({ actId, onChage, onInit }) => {
|
|
|
+const Left: React.FC<Props> = ({ actInfo, onChage, onInit }) => {
|
|
|
+ const [tags, setTags] = React.useState([
|
|
|
+ { id: 1, text: "Popular", img: "https://bcwin.s3.sa-east-1.amazonaws.com/quente.png" },
|
|
|
+ ]);
|
|
|
const { providers, setProviders } = useProviderStore();
|
|
|
const router = useRouter();
|
|
|
|
|
@@ -40,42 +44,79 @@ const Left: React.FC<Props> = ({ actId, onChage, onInit }) => {
|
|
|
}, [providers, setProviders]);
|
|
|
|
|
|
React.useEffect(() => {
|
|
|
- if (actId) {
|
|
|
- const res = providers.find((item) => item.id === actId);
|
|
|
+ if (actInfo?.id) {
|
|
|
+ let res;
|
|
|
+ if (actInfo.type === GameListTypeEnum.TAG) {
|
|
|
+ res = tags.find((item) => item.id === actInfo.id);
|
|
|
+ }
|
|
|
+ if (actInfo.type === GameListTypeEnum.PROVIDER) {
|
|
|
+ res = providers.find((item) => item.id === actInfo.id);
|
|
|
+ }
|
|
|
+
|
|
|
if (res) {
|
|
|
if (typeof onInit === "function") onInit();
|
|
|
return;
|
|
|
}
|
|
|
}
|
|
|
- if (providers?.length && typeof onChage === "function") {
|
|
|
- onChage(providers[0].id);
|
|
|
+ if ((providers?.length || tags?.length) && typeof onChage === "function") {
|
|
|
+ onChage({ type: GameListTypeEnum.TAG, id: tags[0].id });
|
|
|
router.replace({
|
|
|
pathname: "/gameList2",
|
|
|
- query: { provider_id: providers[0].id },
|
|
|
+ query: { tag_id: tags[0].id },
|
|
|
});
|
|
|
if (typeof onInit === "function") onInit();
|
|
|
}
|
|
|
// eslint-disable-next-line react-hooks/exhaustive-deps
|
|
|
- }, [providers, onChage, actId, onInit]);
|
|
|
+ }, [providers, onChage, actInfo, onInit, tags]);
|
|
|
|
|
|
const changeProvider = (item: GameListRep) => {
|
|
|
+ if (item.id === actInfo.id && actInfo.type === GameListTypeEnum.PROVIDER) return;
|
|
|
if (providers?.length && typeof onChage === "function") {
|
|
|
router.replace({
|
|
|
pathname: "/gameList2",
|
|
|
query: { provider_id: item.id },
|
|
|
});
|
|
|
- onChage(item.id);
|
|
|
+ onChage({ type: GameListTypeEnum.PROVIDER, id: item.id });
|
|
|
+ }
|
|
|
+ };
|
|
|
+
|
|
|
+ const changeTag = (item: any) => {
|
|
|
+ if (item.id === actInfo.id && actInfo.type === GameListTypeEnum.TAG) return;
|
|
|
+ if (tags?.length && typeof onChage === "function") {
|
|
|
+ router.replace({
|
|
|
+ pathname: "/gameList2",
|
|
|
+ query: { tag_id: item.id },
|
|
|
+ });
|
|
|
+ onChage({ type: GameListTypeEnum.TAG, id: item.id });
|
|
|
}
|
|
|
};
|
|
|
- if (!providers?.length) return null;
|
|
|
+
|
|
|
+ // if (!providers?.length) return null;
|
|
|
return (
|
|
|
<div className={styles.left}>
|
|
|
+ {tags.map((item) => {
|
|
|
+ return (
|
|
|
+ <div
|
|
|
+ key={item.id}
|
|
|
+ className={clsx(styles.providerItem, {
|
|
|
+ [styles.active]:
|
|
|
+ actInfo.id === item.id && actInfo.type === GameListTypeEnum.TAG,
|
|
|
+ })}
|
|
|
+ onClick={() => changeTag(item)}
|
|
|
+ >
|
|
|
+ <img src={item.img} alt="" />
|
|
|
+ <div className="text-[.12rem] text-[#fff]">{item.text}</div>
|
|
|
+ </div>
|
|
|
+ );
|
|
|
+ })}
|
|
|
{providers.map((item) => {
|
|
|
return (
|
|
|
<div
|
|
|
key={item.id}
|
|
|
className={clsx(styles.providerItem, {
|
|
|
- [styles.active]: actId === item.id,
|
|
|
+ [styles.active]:
|
|
|
+ actInfo.id === item.id &&
|
|
|
+ actInfo.type === GameListTypeEnum.PROVIDER,
|
|
|
})}
|
|
|
onClick={() => changeProvider(item)}
|
|
|
>
|