|
@@ -1,20 +1,30 @@
|
|
"use client";
|
|
"use client";
|
|
-import { EntityGameListRep } from "@/api/home";
|
|
|
|
|
|
+import { GameListRep, getGameDetailApi } from "@/api/home";
|
|
import { Button, Modal, ModalBody, ModalContent, useDisclosure } from "@nextui-org/react";
|
|
import { Button, Modal, ModalBody, ModalContent, useDisclosure } from "@nextui-org/react";
|
|
import { useTranslations } from "next-intl";
|
|
import { useTranslations } from "next-intl";
|
|
-import { FC, PropsWithChildren, ReactNode } from "react";
|
|
|
|
|
|
+import { FC, PropsWithChildren, ReactNode, useRef } from "react";
|
|
import styles from "./style.module.scss";
|
|
import styles from "./style.module.scss";
|
|
export interface CardProps {
|
|
export interface CardProps {
|
|
- item?: EntityGameListRep;
|
|
|
|
- render?: (value: EntityGameListRep) => ReactNode;
|
|
|
|
|
|
+ item?: GameListRep;
|
|
|
|
+ render?: (value: GameListRep) => ReactNode;
|
|
}
|
|
}
|
|
const Card: FC<PropsWithChildren<CardProps>> = (props) => {
|
|
const Card: FC<PropsWithChildren<CardProps>> = (props) => {
|
|
const { render, item } = props;
|
|
const { render, item } = props;
|
|
const { isOpen, onOpen, onOpenChange } = useDisclosure();
|
|
const { isOpen, onOpen, onOpenChange } = useDisclosure();
|
|
const app: HTMLElement = document.querySelector("#app")!;
|
|
const app: HTMLElement = document.querySelector("#app")!;
|
|
const t = useTranslations("Game");
|
|
const t = useTranslations("Game");
|
|
- const handler = (game: EntityGameListRep) => {
|
|
|
|
|
|
+ const urlRef = useRef<string>("");
|
|
|
|
+ const handler = (game: GameListRep) => {
|
|
onOpen();
|
|
onOpen();
|
|
|
|
+ const params = {
|
|
|
|
+ id: game.id,
|
|
|
|
+ };
|
|
|
|
+ getGameDetailApi(params).then((res) => {
|
|
|
|
+ urlRef.current = res.data.game_url;
|
|
|
|
+ });
|
|
|
|
+ };
|
|
|
|
+ const playGameHandler = () => {
|
|
|
|
+ window.open(urlRef.current);
|
|
};
|
|
};
|
|
return (
|
|
return (
|
|
<>
|
|
<>
|
|
@@ -52,6 +62,7 @@ const Card: FC<PropsWithChildren<CardProps>> = (props) => {
|
|
|
|
|
|
<div className={"flex w-[2.2rem] justify-around"}>
|
|
<div className={"flex w-[2.2rem] justify-around"}>
|
|
<Button
|
|
<Button
|
|
|
|
+ onClick={playGameHandler}
|
|
className={
|
|
className={
|
|
"h-[0.39rem] w-[0.89rem] rounded-[0.05rem] text-[0.15rem]" +
|
|
"h-[0.39rem] w-[0.89rem] rounded-[0.05rem] text-[0.15rem]" +
|
|
" bg-[#3a3a3a]" +
|
|
" bg-[#3a3a3a]" +
|
|
@@ -61,12 +72,8 @@ const Card: FC<PropsWithChildren<CardProps>> = (props) => {
|
|
{t("demo")}
|
|
{t("demo")}
|
|
</Button>
|
|
</Button>
|
|
<Button
|
|
<Button
|
|
- className={
|
|
|
|
- "h-[0.39rem] w-[0.89rem] text-[0.15rem]" +
|
|
|
|
- " rounded-[0.05rem]" +
|
|
|
|
- " bg-[#009d80]" +
|
|
|
|
- " font-bold"
|
|
|
|
- }
|
|
|
|
|
|
+ onClick={playGameHandler}
|
|
|
|
+ className={`h-[0.39rem] w-[0.89rem] rounded-[0.05rem] bg-[#009d80] text-[0.15rem] font-bold`}
|
|
>
|
|
>
|
|
{t("join")}
|
|
{t("join")}
|
|
</Button>
|
|
</Button>
|