From ee5b02e24401ef653781a74b11b80823836efc58 Mon Sep 17 00:00:00 2001 From: laststranger Date: Thu, 22 Feb 2024 16:45:18 +0800 Subject: [PATCH] optimise codes --- package.json | 1 + src/navigation/index.tsx | 2 +- src/pages/Login/index.tsx | 4 ++-- src/pages/home/index.tsx | 3 ++- yarn.lock | 5 +++++ 5 files changed, 11 insertions(+), 4 deletions(-) diff --git a/package.json b/package.json index c11853a..7d11b83 100644 --- a/package.json +++ b/package.json @@ -22,6 +22,7 @@ "expo-splash-screen": "~0.20.5", "expo-status-bar": "~1.6.0", "expo-system-ui": "~2.4.0", + "immer": "^10.0.3", "nativewind": "^2.0.11", "react": "18.2.0", "react-native": "0.72.6", diff --git a/src/navigation/index.tsx b/src/navigation/index.tsx index f0e81bc..3572ecb 100644 --- a/src/navigation/index.tsx +++ b/src/navigation/index.tsx @@ -18,7 +18,7 @@ function AppNavigation() { const userInfo = useUserStore(state => state.userInfo); const getUserInfo = useUserStore(state => state.getUserInfo); - console.warn("AppNavigation renderings"); + // console.warn("AppNavigation renderings"); useEffect(() => { getUserInfo(); diff --git a/src/pages/Login/index.tsx b/src/pages/Login/index.tsx index fe5b6cc..71f7e80 100644 --- a/src/pages/Login/index.tsx +++ b/src/pages/Login/index.tsx @@ -62,10 +62,10 @@ const Index = () => { // return; const Buffer = require("buffer").Buffer; let encodedAuth = new Buffer(`${encodeURI(form?.username)}:${encodeURI(form?.password)}`).toString("base64"); - const userInfo = await request.get("/auth/user", { + const result = await request.get("/auth/user", { headers: { Authorization: `Basic ${encodedAuth}` }, }); - console.log(userInfo); + userStore.updateUserInfo(result.data); }; const handleLogin = async (ifNeedCookie: boolean = true) => { diff --git a/src/pages/home/index.tsx b/src/pages/home/index.tsx index edc0251..87c08bb 100644 --- a/src/pages/home/index.tsx +++ b/src/pages/home/index.tsx @@ -64,7 +64,7 @@ const Index = () => { logOut(); }; - console.warn("rendering home1"); + // console.warn("rendering home1"); return ( @@ -104,6 +104,7 @@ const Index = () => { {languageTags.map(each => ( diff --git a/yarn.lock b/yarn.lock index 3add51d..11177c4 100644 --- a/yarn.lock +++ b/yarn.lock @@ -4083,6 +4083,11 @@ image-size@^1.0.2: dependencies: queue "6.0.2" +immer@^10.0.3: + version "10.0.3" + resolved "https://registry.yarnpkg.com/immer/-/immer-10.0.3.tgz#a8de42065e964aa3edf6afc282dfc7f7f34ae3c9" + integrity sha512-pwupu3eWfouuaowscykeckFmVTpqbzW+rXFCX8rQLkZzM9ftBmU/++Ra+o+L27mz03zJTlyV4UUr+fdKNffo4A== + import-fresh@^2.0.0: version "2.0.0" resolved "https://registry.yarnpkg.com/import-fresh/-/import-fresh-2.0.0.tgz#d81355c15612d386c61f9ddd3922d4304822a546"