Skip to content

Commit

Permalink
optimise codes
Browse files Browse the repository at this point in the history
  • Loading branch information
LastStranger committed Feb 21, 2024
1 parent bc732ee commit 5b9353f
Show file tree
Hide file tree
Showing 7 changed files with 36 additions and 16 deletions.
3 changes: 3 additions & 0 deletions eas.json
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,9 @@
"distribution": "internal"
},
"preview": {
"android": {
"buildType": "apk"
},
"distribution": "internal"
},
"production": {}
Expand Down
1 change: 1 addition & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@
"react-native-safe-area-context": "4.6.3",
"react-native-screens": "~3.22.0",
"react-native-svg": "13.9.0",
"react-native-user-agent": "^2.3.1",
"react-native-vector-icons": "^10.0.3",
"typescript": "^5.1.3",
"zustand": "^4.4.1"
Expand Down
9 changes: 6 additions & 3 deletions src/navigation/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -15,17 +15,20 @@ const Stack = createNativeStackNavigator();

function AppNavigation() {
const [isSignIn, setIsSignIn] = useState(false);
const userStore = useUserStore();
const userInfo = useUserStore(state => state.userInfo);
const getUserInfo = useUserStore(state => state.getUserInfo);

console.warn("AppNavigation renderings");

useEffect(() => {
userStore.getUserInfo();
getUserInfo();
}, []);

return (
<NavigationContainer>
{/*<Stack.Navigator initialRouteName={Url.Login} screenOptions={{ headerShown: false }}>*/}
<Stack.Navigator screenOptions={{ headerShown: false }}>
{userStore.userInfo ? (
{userInfo ? (
<>
<Stack.Screen name="main" component={Main} />
<Stack.Screen name="profile" component={Profile} />
Expand Down
10 changes: 0 additions & 10 deletions src/pages/Login/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -101,10 +101,6 @@ const Index = () => {
navigation.navigate("home");
};

const handlePressTestBtn = () => {
zustandStorage.setItem("test", "a empty test");
};

// 登录loading 链接"https://assets.vrchat.com/www/images/loading.gif"

if (userStore.loading) {
Expand Down Expand Up @@ -163,12 +159,6 @@ const Index = () => {
>
<Text className="color-[#6ae3f9] text-2xl">Login</Text>
</TouchableOpacity>
<TouchableOpacity
className="full mt-2 items-center rounded bg-[#064b5c] p-2"
onPress={handlePressTestBtn}
>
<Text className="color-[#6ae3f9] text-2xl">tempBtn</Text>
</TouchableOpacity>
</Animated.View>
</View>
);
Expand Down
8 changes: 6 additions & 2 deletions src/pages/home/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -11,15 +11,19 @@ import { Image } from "expo-image";
// import {Ionicons} from "@expo/vector-icons";

const Index = () => {
const { userInfo, pressTest, clearUserInfo, logOut, getUserInfo } = useUserStore();
// const { userInfo, pressTest, clearUserInfo, logOut, getUserInfo } = useUserStore();

const userInfo = useUserStore(state => state.userInfo);
const clearUserInfo = useUserStore(state => state.clearUserInfo);
const logOut = useUserStore(state => state.logOut);
const getUserInfo = useUserStore(state => state.getUserInfo);
const navigation = useNavigation<any>();
// const navigation = useNavigation<NativeStackNavigationProp<ParamListBase, Url>>();

useFocusEffect(
React.useCallback(() => {
getUserInfo();
// const unsubscribe = API.subscribe(userId, user => setUser(user));

// return () => unsubscribe();
}, []),
);
Expand Down
16 changes: 15 additions & 1 deletion src/utils/request.ts
Original file line number Diff line number Diff line change
@@ -1,10 +1,17 @@
import axios from "axios";
import Toast from "react-native-root-toast";
import UserAgent from "react-native-user-agent";

// const ua = UserAgent?.applicationName + "dddddd";
const ua = UserAgent?.getUserAgent();

// 创建一个axios实例
const instance = axios.create({
baseURL: "https://api.vrchat.cloud/api/1", // 替换成你的API的URL
withCredentials: true, // 启用跨域请求时携带cookies
headers: {
"User-Agent": ua,
},
});

instance.interceptors.response.use(
Expand All @@ -22,8 +29,15 @@ instance.interceptors.response.use(
position: Toast.positions.CENTER,
});
break;
case 400:
Toast.show(error.response?.data?.error?.message ?? "身份验证失败", {
position: Toast.positions.CENTER,
});
break;
default:
Toast.show("default");
Toast.show("未知错误", {
position: Toast.positions.CENTER,
});
}
return Promise.reject(error.response);
}
Expand Down
5 changes: 5 additions & 0 deletions yarn.lock
Original file line number Diff line number Diff line change
Expand Up @@ -5949,6 +5949,11 @@ [email protected]:
css-select "^5.1.0"
css-tree "^1.1.3"

react-native-user-agent@^2.3.1:
version "2.3.1"
resolved "https://registry.yarnpkg.com/react-native-user-agent/-/react-native-user-agent-2.3.1.tgz#81308be0026d9d4e50cc8f1126068d58e6745868"
integrity sha512-AIFr1VgJHwgWmMwCOmIGxuBeAaADlouXKc10UyR4fzWneUbt5uIJIoRu2oExlfCtiT8IyCp106khDD5vx7RUjw==

react-native-vector-icons@^10.0.3:
version "10.0.3"
resolved "https://registry.yarnpkg.com/react-native-vector-icons/-/react-native-vector-icons-10.0.3.tgz#369824a3b17994b2cd65edbaa32dbf9540d49678"
Expand Down

0 comments on commit 5b9353f

Please sign in to comment.