Browse Source

database selection should be persistent even after refreshing the page

Signed-off-by: ryjiang <jiangruiyi@gmail.com>
ryjiang 1 year ago
parent
commit
858d0643f6
1 changed files with 7 additions and 2 deletions
  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={{