diff --git a/app/navigation/types.ts b/app/navigation/types.ts index 4698a56..82baf5a 100644 --- a/app/navigation/types.ts +++ b/app/navigation/types.ts @@ -7,7 +7,7 @@ export type RootStackParamList = { EmailLogin: undefined; MainTabs: undefined; Search: undefined; - SearchResult: { keyword: string, formData?: FormData }; + SearchResult: { keyword?: string, category_id?: number, formData?: FormData }; ImageSearchResultScreen: { image?: string, type?: number }; ProductDetail: { productId: string; searchKeyword?: string }; Balance: undefined; diff --git a/app/screens/CategoryScreen.tsx b/app/screens/CategoryScreen.tsx index d9c61cb..449ab48 100644 --- a/app/screens/CategoryScreen.tsx +++ b/app/screens/CategoryScreen.tsx @@ -18,7 +18,7 @@ import widthUtils from '../utils/widthUtils'; import { categoriesApi, Category } from '../services/api/categories'; import { useNavigation } from '@react-navigation/native'; import { NativeStackNavigationProp } from "@react-navigation/native-stack"; -import { RootStackParamList } from '../types/navigation'; +import { RootStackParamList } from '../navigation/types'; const { width: SCREEN_WIDTH } = Dimensions.get('window'); const MENU_WIDTH = widthUtils(120, 120).width; @@ -99,11 +99,11 @@ export const CategoryScreen = () => { { - navigation.navigate('SearchResult', { keyword: item.name_en.trim() }); + navigation.navigate('SearchResult', { category_id: item.category_id }); }} > @@ -134,6 +134,9 @@ export const CategoryScreen = () => { item.category_id.toString()} @@ -147,6 +150,9 @@ export const CategoryScreen = () => { ) : ( item.category_id.toString()} numColumns={NUM_COLUMNS} diff --git a/app/screens/HomeScreen.tsx b/app/screens/HomeScreen.tsx index 667c293..599e330 100644 --- a/app/screens/HomeScreen.tsx +++ b/app/screens/HomeScreen.tsx @@ -41,6 +41,7 @@ import { getSubjectTransLanguage } from "../utils/languageUtils"; import useUserStore from "../store/user"; import * as ImagePicker from "expo-image-picker"; import * as FileSystem from "expo-file-system"; +import { useGlobalStore } from "../store/useGlobalStore"; // 为图标定义类型 type IconProps = { name: string; @@ -434,10 +435,11 @@ export const HomeScreen = () => { setRefreshing(false); } }, [searchParams]); + const { country, currency, language } = useGlobalStore(); useEffect(() => { console.log("userStore.user", userStore.user); getProductData(); - }, [userStore.user]); + }, [userStore.user, country, currency, language]); const categories = [ "Tous", "Bijoux", diff --git a/app/screens/SearchResultScreen.tsx b/app/screens/SearchResultScreen.tsx index fe3fe00..b69dafe 100644 --- a/app/screens/SearchResultScreen.tsx +++ b/app/screens/SearchResultScreen.tsx @@ -40,7 +40,8 @@ const IconComponent = React.memo( ); // 路由参数类型 type SearchResultRouteParams = { - keyword: string; + keyword?: string; + category_id?: number; }; // 组件Props类型 type SearchResultScreenProps = { @@ -148,7 +149,7 @@ const ProductItem = React.memo( {/* 产品分类 */} - {getSubjectTransLanguage(product)} + {getSubjectTransLanguage(product) || product.subject_trans} {/* 价格信息 */} @@ -218,7 +219,16 @@ export const SearchResultScreen = ({ route, navigation }: SearchResultScreenProp setSearchParams(newParams); searchProducts(newParams); } - }, [route.params?.keyword]); + if (route.params?.category_id) { + setShowSkeleton(true); + const newParams = { + ...searchParams, + category_id: route.params.category_id, + }; + setSearchParams(newParams); + searchProducts(newParams) + } + }, [route.params?.keyword,route.params?.category_id]); // 搜索产品的API调用 const searchProducts = useCallback( async (params: ProductParams, isLoadMore = false) => { diff --git a/app/screens/setting/CountrySetting.tsx b/app/screens/setting/CountrySetting.tsx index 781d5dc..4d99333 100644 --- a/app/screens/setting/CountrySetting.tsx +++ b/app/screens/setting/CountrySetting.tsx @@ -1,11 +1,11 @@ -import { View, Text, StyleSheet, TouchableOpacity, Image, SafeAreaView, StatusBar, Platform } from "react-native"; +import { View, Text, StyleSheet, TouchableOpacity, Image, SafeAreaView, StatusBar } from "react-native"; import BackIcon from "../../components/BackIcon"; import fontSize from "../../utils/fontsizeUtils"; import { useNavigation, useRoute, RouteProp } from "@react-navigation/native"; import { NativeStackNavigationProp } from "@react-navigation/native-stack"; import { RootStackParamList } from "../../navigation/types"; import { useState, useEffect } from "react"; -import { settingApi, Country } from "../../services/api/setting"; +import { settingApi } from "../../services/api/setting"; import { FlatList } from "react-native"; import flagMap from "../../utils/flagMap"; import CheckIcon from "../../components/CheckIcon"; @@ -13,7 +13,10 @@ import Toast from "react-native-toast-message"; import { eventBus } from "../../utils/eventBus"; import { changeLanguage } from "../../i18n"; import { useTranslation } from "react-i18next"; -import RNRestart from 'react-native-restart'; +import { useGlobalStore } from "../../store/useGlobalStore"; +import { userApi } from "../../services/api/userApi"; +import useUserStore from "../../store/user"; + // Define CountryList type to match API response @@ -30,6 +33,7 @@ type CountryList = { export const CountrySetting = () => { const { t } = useTranslation(); + const { setGlobalCountry, setGlobalCurrency, setGlobalLanguage } = useGlobalStore(); const navigation = useNavigation>(); const route = useRoute>(); @@ -40,6 +44,8 @@ export const CountrySetting = () => { const [country, setCountry] = useState(0); const [currency, setCurrency] = useState(""); const [language, setLanguage] = useState(""); + const { setUser } = useUserStore(); + const getCountry = async () => { const res = await settingApi.getCountryList(); setCountryList(res); @@ -67,15 +73,17 @@ export const CountrySetting = () => { const putSettinghandel = async () => { // Only include the property that corresponds to the active tab let data = {}; - - if (changeType === "country") { + if (changeType === "country") { data = { country: country }; + setGlobalCountry({ country: country.toString() }); } else if (changeType === "currency") { data = { currency: currency }; + setGlobalCurrency({ currency: currency }); } else if (changeType === "language") { data = { language: language }; + setGlobalLanguage({ language: language }); } - + Toast.show({ text1: t('setting.success'), type: "success", @@ -86,8 +94,8 @@ export const CountrySetting = () => { await changeLanguage(language); } eventBus.emit("refreshSetting"); - - RNRestart.Restart(); + const userData = await userApi.getProfile(); + setUser(userData); }; return ( diff --git a/app/services/api/categories.ts b/app/services/api/categories.ts index 4f0c161..9c6098c 100644 --- a/app/services/api/categories.ts +++ b/app/services/api/categories.ts @@ -5,6 +5,7 @@ export interface Category { name: string; name_cn: string; name_en: string; + image:string level: number; is_leaf: boolean; image_url?: string; diff --git a/package-lock.json b/package-lock.json index 89cd8f9..bdca93e 100644 --- a/package-lock.json +++ b/package-lock.json @@ -52,7 +52,6 @@ "react-native-reanimated-carousel": "^4.0.2", "react-native-render-html": "^6.3.4", "react-native-responsive-fontsize": "^0.5.1", - "react-native-restart": "^0.0.27", "react-native-safe-area-context": "4.12.0", "react-native-screens": "~4.4.0", "react-native-svg": "^15.11.2", @@ -19548,16 +19547,6 @@ "react-native": ">=0.42.0" } }, - "node_modules/react-native-restart": { - "version": "0.0.27", - "resolved": "https://registry.npmmirror.com/react-native-restart/-/react-native-restart-0.0.27.tgz", - "integrity": "sha512-8KScVICrXwcTSJ1rjWkqVTHyEKQIttm5AIMGSK1QG1+RS5owYlE4z/1DykOTdWfVl9l16FIk0w9Xzk9ZO6jxlA==", - "license": "MIT", - "peerDependencies": { - "react": "*", - "react-native": "*" - } - }, "node_modules/react-native-safe-area-context": { "version": "4.12.0", "resolved": "https://registry.npmmirror.com/react-native-safe-area-context/-/react-native-safe-area-context-4.12.0.tgz", diff --git a/package.json b/package.json index 8b0a8e1..7b04e12 100644 --- a/package.json +++ b/package.json @@ -54,7 +54,6 @@ "react-native-reanimated-carousel": "^4.0.2", "react-native-render-html": "^6.3.4", "react-native-responsive-fontsize": "^0.5.1", - "react-native-restart": "^0.0.27", "react-native-safe-area-context": "4.12.0", "react-native-screens": "~4.4.0", "react-native-svg": "^15.11.2", diff --git a/yarn.lock b/yarn.lock index 3195e7c..6c8135b 100644 --- a/yarn.lock +++ b/yarn.lock @@ -10083,11 +10083,6 @@ react-native-responsive-fontsize@^0.5.1: dependencies: react-native-iphone-x-helper "^1.3.1" -react-native-restart@^0.0.27: - version "0.0.27" - resolved "https://registry.npmmirror.com/react-native-restart/-/react-native-restart-0.0.27.tgz" - integrity sha512-8KScVICrXwcTSJ1rjWkqVTHyEKQIttm5AIMGSK1QG1+RS5owYlE4z/1DykOTdWfVl9l16FIk0w9Xzk9ZO6jxlA== - react-native-safe-area-context@4.12.0: version "4.12.0" resolved "https://registry.npmmirror.com/react-native-safe-area-context/-/react-native-safe-area-context-4.12.0.tgz"