Bläddra i källkod

1.音乐开关不控制背景音乐问题。
2.收藏游戏不跳转页面。
3.收藏游戏viewall按钮点击后循环刷新问题。

fattiger 2 veckor sedan
förälder
incheckning
9dc1e4542c

+ 3 - 2
src/components/GameItem/index.jsx

@@ -79,7 +79,8 @@ const GameItem=({data,handleRoom,whStyle,...props})=>{
         }
     }
     const handleLike=()=>{
-        let info={id:data.id,data:data,like:(1-like)}
+        const nextLike=1-like;
+        let info={id:data.id,data:data,like:nextLike}
         dispatch(updateGameLike(info));
         dispatch(updatePageGameLike(info));
         if(isLogin)dispatch(reqUpdateFavoInfo(info));
@@ -106,4 +107,4 @@ const GameItem=({data,handleRoom,whStyle,...props})=>{
         </StyledGridItem>
     )
 }
-export default GameItem;
+export default GameItem;

+ 8 - 2
src/components/GameTabs/index.jsx

@@ -1,5 +1,5 @@
 import styles from "@components/GameTabs/styles.module.scss";
-import React, { Fragment, Suspense, useEffect, useState } from "react";
+import React, { Fragment, Suspense, useEffect, useRef, useState } from "react";
 import AllWidgets from "@widgets/index";
 import SmallLoading from "@components/SmallLoading";
 import TabIcon from "@components/TabIcon";
@@ -8,6 +8,7 @@ import arrowAni from '@assets/home/jiantou.json';
 const i18n = global.i18n;
 const GameTabs = ({ data = {} }) => {
     const [tabIndex, setTabIndex] = useState(1);
+    const initialized = useRef(false);
     // data={
     //     tabs:[
     //         {type:0,title:'Lobby',icon:'icon_Lobby'},
@@ -33,7 +34,12 @@ const GameTabs = ({ data = {} }) => {
         const requestedTab = visibleTabs.find(tab => tab?.tabtype === requestedType);
         const nextTab = requestedTab?.tabtype ?? visibleTabs[0]?.tabtype ?? -1;
 
-        setTabIndex(current => current === nextTab ? current : nextTab);
+        setTabIndex(current => {
+            const currentTabIsVisible = visibleTabs.some(tab => tab?.tabtype === current);
+            if (initialized.current && currentTabIsVisible) return current;
+            return nextTab;
+        });
+        initialized.current = true;
     }, [data]);
     const changeTab = (tabIndex) => {
         setTabIndex(tabIndex);

+ 1 - 0
src/constants/routes.js

@@ -20,6 +20,7 @@ const ROUTE_PATH = {
     EDIT_PROFILE: "#/editprofile",
     EDIT_PWD: "#/editpwd",
     GAME: "/game",
+    FAVORITE: "/favorite",
     DEPOSIT_POP: "#/deposit",
     PAY: "#/pay",
     WITHDRAW_POP: "#/withdraw",

+ 8 - 4
src/contexts/themeContext.js

@@ -1,4 +1,4 @@
-import { createContext, useCallback, useContext, useEffect, useRef, useState } from 'react';
+import { createContext, useCallback, useContext, useEffect, useLayoutEffect, useRef, useState } from 'react';
 import { isRtlLang } from 'rtl-detect';
 import { useWindowSize } from "react-use";
 import { APP_THEME, ENABLE_SUPERBALL } from "@constants/app";
@@ -79,6 +79,11 @@ export const ThemeProvider = ({ children }) => {
 
     const [soundOpen, setSoundOpen] = useState(persisted && (persisted.soundOpen != null) ? persisted.soundOpen : true);
 
+    // 在子组件的播放 effect 执行前同步持久化设置,避免刷新后以默认开启状态播放 BGM。
+    useLayoutEffect(() => {
+        SoundHelp.setSoundOn(soundOpen);
+    }, [soundOpen]);
+
     const [headerHeight, setHeaderHeight] = useState('64px');
 
     //GameSearch
@@ -169,11 +174,10 @@ export const ThemeProvider = ({ children }) => {
         setInstallOpen(!installOpen);
     };
     const toggleSoundOpen = () => {
-        setSoundOpen(!soundOpen);
+        setSoundOpen(open => !open);
     };
     const updateSoundOpen = (open) => {
-        setSoundOpen(open);
-        SoundHelp.setSoundOn(open);
+        setSoundOpen(Boolean(open));
     }
 
     const openRecommandGamePopup = () => {

+ 1 - 9
src/db/payment.js

@@ -1,4 +1,3 @@
-import icon_cashapp from "@assets/pay/icon_cashapp.svg";
 import icon_card from "@assets/pay/icon_card.svg";
 import icon_applePay from "@assets/pay/icon_apple.svg";
 import icon_googlePay from "@assets/pay/icon_google.svg";
@@ -19,7 +18,6 @@ export const CryptoGroupId = 2;
 export const CryptoGroupName = "crypto";
 
 export const PayTypeMap = {
-    //"1": "cashapp",
     "1": "credit_card",
     "2": "paypal",
     "4": "applepay",
@@ -38,7 +36,6 @@ export const PayTypeMap = {
  * 支付渠道分组  group_id
  */
 export const PayTypeGroup = {
-    //1: "cashapp",
     1: "credit_card",
     2: "crypto"
 }
@@ -50,10 +47,6 @@ export const PayTypeGroup = {
  * icon: 图片
  */
 export const PaymentGears = {
-    // "cashapp": {
-    //     name: "Cash App",
-    //     icon: icon_cashapp
-    // },
     "credit_card": {
         name: "Card",
         icon: icon_card
@@ -103,7 +96,6 @@ export const RecommendGears = ["usdc", "credit_card"];
 
 
 export const WithdrawType = {
-    //CashApp: 1,
     Credit_card: 1,
     Paypal: 2,
-}
+}

+ 8 - 23
src/features/pageSlice.js

@@ -106,35 +106,19 @@ export const Page = createSlice({
         }),
         updatePageGameLike: ((state, action) => {
             let { data, like } = action.payload;
+            let favoriteData = Array.isArray(state.favoriteData) ? state.favoriteData : [];
+            const favoriteIndex = favoriteData.findIndex(item => item != null && item.id === data.id);
+            if (like === 1 && favoriteIndex === -1) favoriteData.unshift(data);
+            if (like !== 1 && favoriteIndex >= 0) favoriteData.splice(favoriteIndex, 1);
+            state.favoriteData = favoriteData;
+
             let favoriteKeys = state.favoriteKeys;
             if (favoriteKeys && favoriteKeys.length > 0) {
                 for (let i = 0; i < favoriteKeys.length; i++) {
                     let mkey = favoriteKeys[i];
                     let module = getModuleData(state.pageData, mkey);
                     if (module != null) {
-                        let oldData = module.data;
-                        if (oldData == null) oldData = [];
-                        if (oldData.length === 0) {
-                            if (like === 1) oldData.unshift(data);
-                        }
-                        else {
-                            let index = -1;
-                            for (let j = 0; j < oldData.length; j++) {
-                                let item = oldData[j];
-                                if (item != null && item.id === data.id) {
-                                    index = j;
-                                    break;
-                                }
-                            }
-                            if (like === 1) {
-                                if (index === -1) oldData.unshift(data);
-                            }
-                            else {
-                                if (index >= 0) oldData.splice(index, 1);
-                            }
-                        }
-                        module.data = oldData;
-                        state.favoriteData = oldData;
+                        module.data = favoriteData;
                     }
                 }
             }
@@ -170,6 +154,7 @@ export const getModules = (pageID) => (state) => {
     if (pageData == null) return [];
     return pageData[pageID];
 };
+export const getFavoriteData = (state) => state.page.favoriteData || [];
 const collectGameItems = (pageData) => {
     const list = [];
     const seen = new Set();

+ 6 - 0
src/utils/SoundManger.js

@@ -374,6 +374,12 @@ class SoundManger {
     }
 
     playBgm(name) {
+        if (!this.audioOn) {
+            this.isPlaying = false;
+            this.shouldResumeBgm = false;
+            return;
+        }
+
         if (!name) {
             if (bgmList.length === 0) {
                 this.isPlaying = false;

+ 24 - 7
src/widgets/ModuleGroup/index.jsx

@@ -1,5 +1,5 @@
 import { useDispatch, useSelector } from "react-redux";
-import { getFetchStatus, getModules } from "@features/pageSlice";
+import { getFavoriteData, getFetchStatus, getModules } from "@features/pageSlice";
 import { useThemeProvider } from "@contexts/themeContext";
 import { Fragment, Suspense, useEffect } from "react";
 import { reqPageModules } from "@features/api";
@@ -8,7 +8,7 @@ import AllWidgets from "@widgets/index";
 import styles from "./styles.module.scss";
 import LoadingIn from "@components/Loading/LoadingIn";
 import Logo from '@components/Logo';
-import { useNavigate } from "react-router-dom";
+import { useLocation, useNavigate } from "react-router-dom";
 import { ROUTE_PATH } from "@constants/routes";
 import Button from "@mui/material/Button";
 import Footer from "@layout/Footer";
@@ -414,10 +414,14 @@ const ModuleGroup = ({ pageID }) => {
     const dispatch = useDispatch();
     const status = useSelector(getFetchStatus);
     const modules = useSelector(getModules(pageID));
+    const favoriteData = useSelector(getFavoriteData);
     const { isMobile } = useThemeProvider();
+    const { pathname } = useLocation();
+    const requestedPageRef = useRef(null);
 
     useEffect(() => {
-        if (modules == null || modules.length === 0) {
+        if (modules == null && requestedPageRef.current !== pageID) {
+            requestedPageRef.current = pageID;
             dispatch(reqPageModules(pageID));
         }
     }, [dispatch, modules, pageID]);
@@ -431,9 +435,22 @@ const ModuleGroup = ({ pageID }) => {
 
     const renderModules = () => {
         if (status === REQ_STATUS.IDLE) {
-            if (modules == null) return (<></>);
-        const hasHomeWithdraw = modules.some((item) => item.type === "ModuleHomeWithdraw");
-        const hasSearch = modules.some((item) => item.type === "ModuleSearch");
+            let displayModules = modules;
+            if (pathname === ROUTE_PATH.FAVORITE && (!Array.isArray(displayModules) || displayModules.length === 0)) {
+                displayModules = [{
+                    _mkey: `${pageID}_favorite`,
+                    type: "ModuleGameList",
+                    data_key: "favorite",
+                    tabtype: 0,
+                    page: 1,
+                    totalPage: 1,
+                    total: favoriteData.length,
+                    data: favoriteData,
+                }];
+            }
+            if (!Array.isArray(displayModules)) return (<></>);
+            const hasHomeWithdraw = displayModules.some((item) => item.type === "ModuleHomeWithdraw");
+            const hasSearch = displayModules.some((item) => item.type === "ModuleSearch");
             const ModuleSidebar = AllWidgets["ModuleSidebar"];
             const ModuleSearch = AllWidgets["ModuleSearch"];
 
@@ -455,7 +472,7 @@ const ModuleGroup = ({ pageID }) => {
                             <Suspense fallback={<LoadingIn />}>
                                 <div className={`${styles.container} ${isMobile() ? '' : 'page-max-width-wrap'}`} >
                                     {
-                                        modules.map((item, index) => {
+                                        displayModules.map((item, index) => {
                                             let Comp = AllWidgets[item.type];
                                             if (Comp == null) {
                                                 console.warn(`Module type "${item.type}" not found in AllWidgets`);

+ 1 - 10
src/widgets/Userinfo/WBindInfo/index.jsx

@@ -14,7 +14,6 @@ import imgLock from '@assets/userinfo/img_lock.png';
 import { ReactComponent as MailIcon } from '@assets/userinfo/icon_mail.svg';
 import { ReactComponent as PhoneIcon } from '@assets/userinfo/icon_mobile.svg';
 import { ReactComponent as PaypalIcon } from '@assets/userinfo/icon_paypal.svg';
-import { ReactComponent as CashappIcon } from '@assets/userinfo/icon_cashapp.svg';
 import { ReactComponent as CodeIcon } from '@assets/userinfo/icon_redeem_code.svg';
 
 import styles from './styles.module.scss';
@@ -76,7 +75,7 @@ const WBindInfo = () => {
     const dispatch = useDispatch();
     const limitInfo = useSelector(getChangeLimitInfo);
     const phoneNum = useSelector(getBindPhone);
-    const { paypalEmail, cashAppTag, paypalEditCd, cashAppEditCd } = useWithdrawInfo();
+    const { paypalEmail, paypalEditCd } = useWithdrawInfo();
 
     const emailInfo = useSelector(selectEmailInfo);
 
@@ -164,14 +163,6 @@ const WBindInfo = () => {
                 onClick={global.showEditBindPaypal}
             />
 
-            {/* <ItemInfo
-                Icon={CashappIcon}
-                title="Cash App"
-                value={cashAppTag}
-                badge={i18n.t('settings.for_withdraw')}
-                cdTs={cashAppEditCd}
-                onClick={global.showEditBindCashapp}
-            /> */}
         </div>
     );
 };