src/contexts/NotificationContext.js
- 添加 selectIsMobile 导入 在 NotificationProvider 组件开头添加移动端检测 移动端返回空壳 Provider - 桌面端保持原有完整功能 移除 ConnectionStatusBar 组件和 ConnectionStatusBarWrapper(所有端) - 移除了不再使用的 useNotification、useLocation、logger 导入 - 添加了 Redux selectIsMobile 检测 - 移动端不渲染 NotificationContainer
This commit is contained in:
@@ -9,6 +9,8 @@
|
||||
import React, { createContext, useContext, useState, useEffect, useCallback, useRef } from 'react';
|
||||
import { useToast, Box, HStack, Text, Button, CloseButton, VStack, Icon } from '@chakra-ui/react';
|
||||
import { BellIcon } from '@chakra-ui/icons';
|
||||
import { useSelector } from 'react-redux';
|
||||
import { selectIsMobile } from '@/store/slices/deviceSlice';
|
||||
import { logger } from '../utils/logger';
|
||||
import socket from '../services/socket';
|
||||
import notificationSound from '../assets/sounds/notification.wav';
|
||||
@@ -44,6 +46,42 @@ export const useNotification = () => {
|
||||
|
||||
// 通知提供者组件
|
||||
export const NotificationProvider = ({ children }) => {
|
||||
// ⚡ 移动端检测(使用 Redux 状态)
|
||||
const isMobile = useSelector(selectIsMobile);
|
||||
|
||||
// ⚡ 移动端禁用完整通知能力:返回空壳 Provider
|
||||
// 移动端不支持桌面通知,且不需要 Socket 实时推送
|
||||
if (isMobile) {
|
||||
const emptyValue = {
|
||||
notifications: [],
|
||||
isConnected: false,
|
||||
soundEnabled: false,
|
||||
browserPermission: 'default',
|
||||
connectionStatus: CONNECTION_STATUS.DISCONNECTED,
|
||||
reconnectAttempt: 0,
|
||||
maxReconnectAttempts: 0,
|
||||
addNotification: () => null,
|
||||
removeNotification: () => {},
|
||||
clearAllNotifications: () => {},
|
||||
toggleSound: () => {},
|
||||
requestBrowserPermission: () => Promise.resolve('default'),
|
||||
trackNotificationClick: () => {},
|
||||
retryConnection: () => {},
|
||||
showWelcomeGuide: () => {},
|
||||
showCommunityGuide: () => {},
|
||||
showFirstFollowGuide: () => {},
|
||||
registerEventUpdateCallback: () => () => {},
|
||||
unregisterEventUpdateCallback: () => {},
|
||||
};
|
||||
|
||||
return (
|
||||
<NotificationContext.Provider value={emptyValue}>
|
||||
{children}
|
||||
</NotificationContext.Provider>
|
||||
);
|
||||
}
|
||||
|
||||
// ========== 桌面端:完整通知功能 ==========
|
||||
const toast = useToast();
|
||||
const [notifications, setNotifications] = useState([]);
|
||||
const [isConnected, setIsConnected] = useState(false);
|
||||
|
||||
Reference in New Issue
Block a user