|
@@ -1,5 +1,6 @@
|
|
|
"use client";
|
|
|
import { GameListRep, GroupType } from "@/api/home";
|
|
|
+import { useRouter } from "@/i18n/routing";
|
|
|
import { useProviderStore } from "@/stores/useProvider";
|
|
|
import { server } from "@/utils/client";
|
|
|
import clsx from "clsx";
|
|
@@ -9,6 +10,7 @@ import styles from "./page.module.scss";
|
|
|
interface Props {
|
|
|
actId: number;
|
|
|
onChage?: (id: number) => void;
|
|
|
+ onInit?: () => void;
|
|
|
}
|
|
|
|
|
|
const getGames = async () => {
|
|
@@ -23,8 +25,9 @@ const getGames = async () => {
|
|
|
});
|
|
|
};
|
|
|
|
|
|
-const Left: React.FC<Props> = ({ actId, onChage }) => {
|
|
|
+const Left: React.FC<Props> = ({ actId, onChage, onInit }) => {
|
|
|
const { providers, setProviders } = useProviderStore();
|
|
|
+ const router = useRouter();
|
|
|
|
|
|
React.useEffect(() => {
|
|
|
if (!providers || providers.length === 0) {
|
|
@@ -40,16 +43,27 @@ const Left: React.FC<Props> = ({ actId, onChage }) => {
|
|
|
if (actId) {
|
|
|
const res = providers.find((item) => item.id === actId);
|
|
|
if (res) {
|
|
|
+ if (typeof onInit === "function") onInit();
|
|
|
return;
|
|
|
}
|
|
|
}
|
|
|
if (providers?.length && typeof onChage === "function") {
|
|
|
onChage(providers[0].id);
|
|
|
+ router.replace({
|
|
|
+ pathname: "/gameList2",
|
|
|
+ query: { provider_id: providers[0].id },
|
|
|
+ });
|
|
|
+ if (typeof onInit === "function") onInit();
|
|
|
}
|
|
|
- }, [providers, onChage, actId]);
|
|
|
+ // eslint-disable-next-line react-hooks/exhaustive-deps
|
|
|
+ }, [providers, onChage, actId, onInit]);
|
|
|
|
|
|
const changeProvider = (item: GameListRep) => {
|
|
|
if (providers?.length && typeof onChage === "function") {
|
|
|
+ router.replace({
|
|
|
+ pathname: "/gameList2",
|
|
|
+ query: { provider_id: item.id },
|
|
|
+ });
|
|
|
onChage(item.id);
|
|
|
}
|
|
|
};
|