浏览代码

database selection should be persistent even after refreshing the page

Signed-off-by: ryjiang <jiangruiyi@gmail.com>
ryjiang 1 年之前
父节点
当前提交
858d0643f6
共有 1 个文件被更改,包括 7 次插入2 次删除
  1. 7 2
      client/src/context/Data.tsx

+ 7 - 2
client/src/context/Data.tsx

@@ -74,7 +74,8 @@ const { Provider } = dataContext;
 
 export const DataProvider = (props: { children: React.ReactNode }) => {
   // auth context
-  const { authReq, isAuth, clientId, logout } = useContext(authContext);
+  const { authReq, isAuth, clientId, logout, setAuthReq } =
+    useContext(authContext);
 
   // local data state
   const [collections, setCollections] = useState<CollectionObject[]>([]);
@@ -342,7 +343,7 @@ export const DataProvider = (props: { children: React.ReactNode }) => {
       // set connected to false
       setConnected(false);
     }
-  }, [isAuth, authReq]);
+  }, [isAuth]);
 
   useEffect(() => {
     if (connected) {
@@ -363,6 +364,10 @@ export const DataProvider = (props: { children: React.ReactNode }) => {
     };
   }, [updateCollections, connected]);
 
+  useEffect(() => {
+    setAuthReq({ ...authReq, database });
+  }, [database]);
+
   return (
     <Provider
       value={{