|
@@ -1,5 +1,5 @@
|
|
|
"use client";
|
|
|
-import { cancelFavorite, Category, GameListRep, GameRequest, setFavorite } from "@/api/home";
|
|
|
+import { Category, GameListRep, GameRequest, toggleFavorite } from "@/api/home";
|
|
|
import { userInfoApi } from "@/api/login";
|
|
|
import Box from "@/components/Box";
|
|
|
import useGame from "@/hooks/useGame";
|
|
@@ -137,16 +137,15 @@ const Card: FC<PropsWithChildren<CardProps>> = (props) => {
|
|
|
|
|
|
const doFavorite = async (evt: React.MouseEvent) => {
|
|
|
evt.stopPropagation();
|
|
|
+ if (!getToken) {
|
|
|
+ router.push("/login");
|
|
|
+ }
|
|
|
if (!item?.id) return;
|
|
|
const params = {
|
|
|
game_id: item?.id,
|
|
|
};
|
|
|
let res = null;
|
|
|
- if (isFavorite) {
|
|
|
- res = await cancelFavorite(params);
|
|
|
- } else {
|
|
|
- res = await setFavorite(params);
|
|
|
- }
|
|
|
+ res = await toggleFavorite(params);
|
|
|
if (res.code === 200) {
|
|
|
setIsFavorite(!isFavorite);
|
|
|
Toast.show({
|
|
@@ -173,8 +172,14 @@ const Card: FC<PropsWithChildren<CardProps>> = (props) => {
|
|
|
/>
|
|
|
{props.isShowOnline && <div className={styles.cardOnline}>2323 On-Line</div>}
|
|
|
{props.isShowFavorite && (
|
|
|
- <div className={styles.favorite} onClick={doFavorite}>
|
|
|
- <i className="iconfont icon-ertong"></i>
|
|
|
+ <div
|
|
|
+ className={clsx(styles.favorite, { [styles.active]: isFavorite })}
|
|
|
+ onClick={doFavorite}
|
|
|
+ >
|
|
|
+ {isFavorite && (
|
|
|
+ <i className="iconfont icon-ertong21 text-[#f6cf1e]"></i>
|
|
|
+ )}
|
|
|
+ {!isFavorite && <i className="iconfont icon-ertong"></i>}
|
|
|
</div>
|
|
|
)}
|
|
|
</div>
|