diff --git a/app/(tabs)/index.tsx b/app/(tabs)/index.tsx index 1adcf62..a8f83c8 100644 --- a/app/(tabs)/index.tsx +++ b/app/(tabs)/index.tsx @@ -3,7 +3,7 @@ import { registerBackgroundUploadTask, triggerManualUpload } from '@/components/ import * as MediaLibrary from 'expo-media-library'; import { useRouter } from 'expo-router'; import * as SecureStore from 'expo-secure-store'; -import { useEffect, useState } from 'react'; +import { useEffect, useRef, useState } from 'react'; import { useTranslation } from 'react-i18next'; import { Platform, Text, TouchableOpacity, View } from 'react-native'; import { useSafeAreaInsets } from "react-native-safe-area-context"; @@ -15,20 +15,26 @@ export default function HomeScreen() { const insets = useSafeAreaInsets(); const [isLoading, setIsLoading] = useState(true); const [isLoggedIn, setIsLoggedIn] = useState(false); + const [token, setToken] = useState(''); + const tokenInterval = useRef(null); + const isMounted = useRef(true); + + const getAuthToken = async (): Promise => { + let tokenValue = ''; + if (Platform.OS === 'web') { + tokenValue = localStorage.getItem('token') || ''; + } else { + tokenValue = (await SecureStore.getItemAsync('token')) || ''; + } + setToken(tokenValue); // 只在获取到新token时更新状态 + return tokenValue; + }; useEffect(() => { const checkAuthStatus = async () => { try { - let token; - if (Platform.OS === 'web') { - token = localStorage.getItem('token') || ''; - } else { - token = await SecureStore.getItemAsync('token') || ''; - } - const loggedIn = !!token; setIsLoggedIn(loggedIn); - console.log(loggedIn); if (loggedIn) { // 已登录,请求必要的权限 @@ -49,10 +55,38 @@ export default function HomeScreen() { setIsLoading(false); } }; - checkAuthStatus(); }, []); + // 轮询获取token + useEffect(() => { + // 如果已经有token,直接返回 + if (token) { + if (tokenInterval.current) { + clearInterval(tokenInterval.current); + } + return; + } + if (!tokenInterval.current) return; + // 设置轮询 + tokenInterval.current = setInterval(async () => { + if (isMounted.current) { + const currentToken = await getAuthToken(); + // 如果获取到token,清除定时器 + if (currentToken && tokenInterval.current) { + clearInterval(tokenInterval.current); + } + } + }, 5000); + + // 返回清理函数 + return () => { + if (tokenInterval.current) { + clearInterval(tokenInterval.current); + } + }; + }, [token]); // 添加token作为依赖 + if (isLoading) { return ( @@ -91,7 +125,7 @@ export default function HomeScreen() { {"\n"} {t('auth.welcomeAwaken.back', { ns: 'login' })} - {/* */} + {/* 唤醒按钮 */} ("userName") const [username, setUsername] = useState('') const [avatar, setAvatar] = useState('') @@ -18,6 +19,10 @@ export default function UserMessage() { const [userInfo, setUserInfo] = useState(null); const statusBarHeight = StatusBar?.currentHeight ?? 0; + // 获取路由参数 + const params = useLocalSearchParams(); + const { username: usernameParam } = params; + // 获取用户信息 const getUserInfo = async () => { const res = await fetchApi("/iam/user-info"); @@ -44,7 +49,7 @@ export default function UserMessage() { useEffect(() => { getUserInfo(); setSteps("userName") - }, []); + }, [usernameParam]); return ( - - + + + diff --git a/assets/icons/svg/chatNotIn.svg b/assets/icons/svg/chatNotIn.svg new file mode 100644 index 0000000..9a1bd84 --- /dev/null +++ b/assets/icons/svg/chatNotIn.svg @@ -0,0 +1,3 @@ + + + diff --git a/assets/icons/svg/personIn.svg b/assets/icons/svg/personIn.svg index 5b0516a..c0cf339 100644 --- a/assets/icons/svg/personIn.svg +++ b/assets/icons/svg/personIn.svg @@ -1 +1,3 @@ - \ No newline at end of file + + + diff --git a/assets/icons/svg/personNotIn.svg b/assets/icons/svg/personNotIn.svg new file mode 100644 index 0000000..883c7f4 --- /dev/null +++ b/assets/icons/svg/personNotIn.svg @@ -0,0 +1,3 @@ + + + diff --git a/assets/images/png/owner/ask.png b/assets/images/png/owner/ask.png new file mode 100644 index 0000000..8c5f798 Binary files /dev/null and b/assets/images/png/owner/ask.png differ diff --git a/components/ask/aiChat.tsx b/components/ask/aiChat.tsx index 7080d00..8aeeee1 100644 --- a/components/ask/aiChat.tsx +++ b/components/ask/aiChat.tsx @@ -7,6 +7,7 @@ import { Message, Video } from "@/types/ask"; import { MaterialItem } from "@/types/personal-info"; import { useVideoPlayer, VideoView } from 'expo-video'; import React from 'react'; +import { useTranslation } from "react-i18next"; import { FlatList, Image, @@ -40,7 +41,7 @@ const renderMessage = ({ insets, item, sessionId, setModalVisible, modalVisible, const isVideo = (data: Video | MaterialItem): data is Video => { return 'video' in data; }; - + const { t } = useTranslation(); // 创建一个新的 VideoPlayer 组件 const VideoPlayer = ({ videoUrl, @@ -222,7 +223,7 @@ const renderMessage = ({ insets, item, sessionId, setModalVisible, modalVisible, setModalDetailsVisible(false)}> - Select Photo + {t('ask.selectPhoto', { ns: 'ask' })} @@ -292,7 +293,7 @@ const renderMessage = ({ insets, item, sessionId, setModalVisible, modalVisible, activeOpacity={0.8} > - Continue Asking + {t('ask.continueAsking', { ns: 'ask' })} diff --git a/components/layout/ask.tsx b/components/layout/ask.tsx index dcf964a..3a8445b 100644 --- a/components/layout/ask.tsx +++ b/components/layout/ask.tsx @@ -1,10 +1,10 @@ import ChatInSvg from "@/assets/icons/svg/chatIn.svg"; -import NavbarSvg from "@/assets/icons/svg/navbar.svg"; +import ChatNotInSvg from "@/assets/icons/svg/chatNotIn.svg"; import PersonInSvg from "@/assets/icons/svg/personIn.svg"; -import { Ionicons } from "@expo/vector-icons"; +import PersonNotInSvg from "@/assets/icons/svg/personNotIn.svg"; import { router, usePathname } from "expo-router"; import React from 'react'; -import { Dimensions, Platform, TouchableOpacity, View } from 'react-native'; +import { Dimensions, Image, Platform, TouchableOpacity, View } from 'react-native'; import { Circle, Ellipse, G, Mask, Path, Rect, Svg } from 'react-native-svg'; const AskNavbar = () => { @@ -21,10 +21,11 @@ const AskNavbar = () => { shadowRadius: 8, elevation: 10, // For Android }}> - + {/* */} + - router.push('/memo-list')} > - {pathname === "/memo-list" ? : } + router.push('/memo-list')} style={{ padding: 16 }}> + {pathname === "/memo-list" ? : } { params: { newSession: "true" } }); }} - className={`${Platform.OS === 'web' ? '-mt-[4rem]' : width <= 375 ? '-mt-[5rem] ml-[2rem]' : '-mt-[5rem] ml-[0.8rem]'}`} + className={`${Platform.OS === 'web' ? '-mt-[4rem]' : width <= 375 ? '-mt-[5rem]' : '-mt-[5rem]'}`} > { - router.push('/owner')}> + router.push('/owner')} style={{ padding: 16 }}> - {pathname === "/owner" ? : } + {pathname === "/owner" ? : } {/* */} diff --git a/components/login/login.tsx b/components/login/login.tsx index 0bb9162..0ea2f08 100644 --- a/components/login/login.tsx +++ b/components/login/login.tsx @@ -45,9 +45,13 @@ const Login = ({ updateUrlParam, setError, setShowPassword, showPassword }: Logi body: JSON.stringify(body), }); login({ ...res, email: res?.account }, res.access_token || ''); - router.replace('/user-message'); + const userInfo = await fetchApi("/iam/user-info"); + if (userInfo?.nickname) { + router.replace('/ask'); + } else { + router.replace('/user-message'); + } } catch (error) { - // console.error('Login failed', error); } finally { setIsLoading(false); } diff --git a/components/owner/userInfo.tsx b/components/owner/userInfo.tsx index 5e769a9..7356e9e 100644 --- a/components/owner/userInfo.tsx +++ b/components/owner/userInfo.tsx @@ -125,7 +125,13 @@ const UserInfo = (props: UserInfoProps) => { } { setModalVisible(false); - router.push('/user-message') + // 携带参数跳转 + router.push({ + pathname: '/user-message', + params: { + username: "true" + } + }); }}> diff --git a/i18n/locales/en/ask.json b/i18n/locales/en/ask.json index 94e5c93..3031390 100644 --- a/i18n/locales/en/ask.json +++ b/i18n/locales/en/ask.json @@ -3,6 +3,8 @@ "hi": "Hi,", "iAmMemo": "I'm Memo!", "ready": "Ready to wake up your memories?", - "justAsk": "Just ask MeMo, let me bring them back to life!" + "justAsk": "Just ask MeMo, let me bring them back to life!", + "selectPhoto": "Select Photo", + "continueAsking": "Continue Asking" } } \ No newline at end of file diff --git a/i18n/locales/zh/ask.json b/i18n/locales/zh/ask.json index 94e5c93..3031390 100644 --- a/i18n/locales/zh/ask.json +++ b/i18n/locales/zh/ask.json @@ -3,6 +3,8 @@ "hi": "Hi,", "iAmMemo": "I'm Memo!", "ready": "Ready to wake up your memories?", - "justAsk": "Just ask MeMo, let me bring them back to life!" + "justAsk": "Just ask MeMo, let me bring them back to life!", + "selectPhoto": "Select Photo", + "continueAsking": "Continue Asking" } } \ No newline at end of file