fix: 修复hooks报错
This commit is contained in:
@@ -49,39 +49,7 @@ export const NotificationProvider = ({ children }) => {
|
|||||||
// ⚡ 移动端检测(使用 Redux 状态)
|
// ⚡ 移动端检测(使用 Redux 状态)
|
||||||
const isMobile = useSelector(selectIsMobile);
|
const isMobile = useSelector(selectIsMobile);
|
||||||
|
|
||||||
// ⚡ 移动端禁用完整通知能力:返回空壳 Provider
|
// ========== 所有 Hooks 必须在条件判断之前调用(React 规则) ==========
|
||||||
// 移动端不支持桌面通知,且不需要 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 toast = useToast();
|
||||||
const [notifications, setNotifications] = useState([]);
|
const [notifications, setNotifications] = useState([]);
|
||||||
const [isConnected, setIsConnected] = useState(false);
|
const [isConnected, setIsConnected] = useState(false);
|
||||||
@@ -1047,6 +1015,39 @@ export const NotificationProvider = ({ children }) => {
|
|||||||
};
|
};
|
||||||
}, [browserPermission, toast]);
|
}, [browserPermission, toast]);
|
||||||
|
|
||||||
|
// ⚡ 移动端禁用完整通知能力:返回空壳 Provider
|
||||||
|
// 注意:此判断必须在所有 Hooks 之后(React 规则要求 Hooks 调用顺序一致)
|
||||||
|
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 value = {
|
const value = {
|
||||||
notifications,
|
notifications,
|
||||||
isConnected,
|
isConnected,
|
||||||
|
|||||||
Reference in New Issue
Block a user