feat: 事件中心h5去掉,通知弹窗

This commit is contained in:
zdl
2025-11-24 20:16:48 +08:00
parent ebbb9133d8
commit 6ff4f91a62
3 changed files with 22 additions and 8 deletions

View File

@@ -2,6 +2,8 @@
// 统一的认证表单组件
import React, { useState, useEffect, useRef } from "react";
import { useNavigate } from "react-router-dom";
import { useSelector } from "react-redux";
import { selectIsMobile } from "@/store/slices/deviceSlice";
import {
Box,
Button,
@@ -69,6 +71,7 @@ export default function AuthFormContent() {
const { checkSession } = useAuth();
const { handleLoginSuccess } = useAuthModal();
const { showWelcomeGuide } = useNotification();
const isMobile = useSelector(selectIsMobile);
// 使用统一配置
const config = AUTH_CONFIG;
@@ -380,9 +383,9 @@ export default function AuthFormContent() {
}, config.features.successDelay);
}
// ⚡ 延迟 10 秒显示权限引导(温和、非侵入)
// ⚡ 延迟 10 秒显示权限引导(温和、非侵入,移动端不显示
setTimeout(() => {
if (showWelcomeGuide) {
if (!isMobile && showWelcomeGuide) {
logger.info('AuthFormContent', '显示欢迎引导');
showWelcomeGuide();
}

View File

@@ -1,11 +1,13 @@
// src/contexts/AuthContext.js - Session版本
import React, { createContext, useContext, useState, useEffect } from 'react';
import { useSelector } from 'react-redux';
import { useNavigate } from 'react-router-dom';
import { useToast } from '@chakra-ui/react';
import { logger } from '../utils/logger';
import { useNotification } from '../contexts/NotificationContext';
import { identifyUser, resetUser, trackEvent } from '@lib/posthog';
import { SPECIAL_EVENTS } from '@lib/constants';
import { selectIsMobile } from '@/store/slices/deviceSlice';
// 创建认证上下文
const AuthContext = createContext();
@@ -27,6 +29,7 @@ export const AuthProvider = ({ children }) => {
const navigate = useNavigate();
const toast = useToast();
const { showWelcomeGuide } = useNotification();
const isMobile = useSelector(selectIsMobile);
// ⚡ 使用 ref 保存最新的 isAuthenticated 值,避免事件监听器重复注册
const isAuthenticatedRef = React.useRef(isAuthenticated);
@@ -235,9 +238,11 @@ export const AuthProvider = ({ children }) => {
// isClosable: true,
// });
// ⚡ 登录成功后显示欢迎引导延迟2秒避免与登录Toast冲突
// ⚡ 登录成功后显示欢迎引导延迟2秒避免与登录Toast冲突,移动端不显示
setTimeout(() => {
showWelcomeGuide();
if (!isMobile) {
showWelcomeGuide();
}
}, 2000);
return { success: true };
@@ -293,9 +298,11 @@ export const AuthProvider = ({ children }) => {
isClosable: true,
});
// ⚡ 注册成功后显示欢迎引导延迟2秒
// ⚡ 注册成功后显示欢迎引导延迟2秒,移动端不显示
setTimeout(() => {
showWelcomeGuide();
if (!isMobile) {
showWelcomeGuide();
}
}, 2000);
return { success: true };

View File

@@ -6,6 +6,7 @@ import {
fetchPopularKeywords,
fetchHotEvents
} from '@/store/slices/communityDataSlice';
import { selectIsMobile } from '@/store/slices/deviceSlice';
import {
Box,
Container,
@@ -75,6 +76,9 @@ const Community = () => {
// ⚡ 通知权限引导
const { browserPermission, requestBrowserPermission, registerEventUpdateCallback } = useNotification();
// ⚡ 设备检测
const isMobile = useSelector(selectIsMobile);
// ⚡ DynamicNewsCard 的 ref用于触发刷新
const dynamicNewsCardRef = useRef(null);
@@ -123,8 +127,8 @@ const Community = () => {
useEffect(() => {
// 延迟3秒显示让用户先浏览页面
const timer = setTimeout(() => {
// 如果未授权或未请求过权限,显示横幅
if (browserPermission !== 'granted') {
// 移动端不显示通知横幅
if (!isMobile && browserPermission !== 'granted') {
const hasClosedBanner = localStorage.getItem('notification_banner_closed');
if (!hasClosedBanner) {
setShowNotificationBanner(true);