Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
17 changes: 6 additions & 11 deletions components/dashboard/src/hooks/use-user-loader.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
* See License.AGPL.txt in the project root for license information.
*/

import { useContext, useEffect } from "react";
import { useContext } from "react";
import { UserContext } from "../user-context";
import { getGitpodService } from "../service/service";
import { trackLocation } from "../Analytics";
Expand All @@ -19,7 +19,7 @@ export const useUserLoader = () => {

// For now, we're using the user context to store the user, but letting react-query handle the loading
// In the future, we should remove the user context and use react-query to access the user
const userQuery = useQuery({
const { isLoading } = useQuery({
queryKey: noPersistence(["current-user"]),
queryFn: async () => {
const user = await getGitpodService().server.getLoggedInUser();
Expand All @@ -40,18 +40,13 @@ export const useUserLoader = () => {
retryDelay: (attemptIndex) => Math.min(1000 * 2 ** attemptIndex, 10000),
cacheTime: 1000 * 60 * 60 * 1, // 1 hour
staleTime: 1000 * 60 * 60 * 1, // 1 hour

onSuccess: (loadedUser) => {
setUser(loadedUser);
},
onSettled: (loadedUser) => {
trackLocation(!!loadedUser);
},
});

// onSuccess is deprecated: https://tkdodo.eu/blog/breaking-react-querys-api-on-purpose
useEffect(() => {
if (userQuery.data) {
setUser(userQuery.data);
}
}, [userQuery.data, setUser]);

return { user, loading: userQuery.isLoading };
return { user, loading: isLoading };
};