diff --git a/web/src/api/buster_rest/users/queryRequests.ts b/web/src/api/buster_rest/users/queryRequests.ts index 97a21cd4a..067762d6b 100644 --- a/web/src/api/buster_rest/users/queryRequests.ts +++ b/web/src/api/buster_rest/users/queryRequests.ts @@ -3,10 +3,17 @@ import { useCreateReactMutation, useCreateReactQuery } from '@/api/createReactQuery'; -import { getUser, getUser_server, updateOrganizationUser, getMyUserInfo } from './requests'; +import { + getUser, + getUser_server, + updateOrganizationUser, + getMyUserInfo, + getMyUserInfo_server +} from './requests'; import { useMemoizedFn } from 'ahooks'; import { QueryClient, useQueryClient } from '@tanstack/react-query'; import { queryKeys } from '@/api/query_keys'; +import { BusterUserResponse } from '@/api/asset_interfaces'; export const useGetMyUserInfo = () => { const queryFn = useMemoizedFn(async () => getMyUserInfo()); @@ -18,12 +25,17 @@ export const useGetMyUserInfo = () => { }); }; -export const prefetchGetMyUserInfo = async (queryClientProp?: QueryClient) => { +export const prefetchGetMyUserInfo = async ( + params: Parameters[0], + queryClientProp?: QueryClient +) => { const queryClient = queryClientProp || new QueryClient(); + const initialData = await getMyUserInfo_server(params); await queryClient.prefetchQuery({ ...queryKeys['/users/response:getUserMyself'], - queryFn: () => getMyUserInfo() + initialData }); + return { queryClient, initialData }; }; export const useGetUser = (params: Parameters[0]) => { diff --git a/web/src/api/buster_rest/users/requests.ts b/web/src/api/buster_rest/users/requests.ts index 6b9b55539..11fa1ac94 100644 --- a/web/src/api/buster_rest/users/requests.ts +++ b/web/src/api/buster_rest/users/requests.ts @@ -28,6 +28,9 @@ export const getMyUserInfo_server = async ({ } }) .then((response) => { + if (!response.ok) { + return undefined; + } return response.json(); }) .catch((error) => { diff --git a/web/src/app/app/datasets/page.tsx b/web/src/app/app/datasets/page.tsx index b89edb149..81d6ab0f0 100644 --- a/web/src/app/app/datasets/page.tsx +++ b/web/src/app/app/datasets/page.tsx @@ -1,8 +1,13 @@ import { prefetchGetDatasets } from '@/api/buster_rest/datasets'; import { DatasetsPageContent } from './DatasetsPageContent'; +import { dehydrate, HydrationBoundary } from '@tanstack/react-query'; export default async function DashboardPage() { - await prefetchGetDatasets(); + const queryClient = await prefetchGetDatasets(); - return ; + return ( + + + + ); } diff --git a/web/src/app/app/layout.tsx b/web/src/app/app/layout.tsx index 1d7dab6b4..668d36b25 100644 --- a/web/src/app/app/layout.tsx +++ b/web/src/app/app/layout.tsx @@ -2,7 +2,6 @@ import { useSupabaseServerContext } from '@/context/Supabase/useSupabaseContext'; import React from 'react'; -import { getMyUserInfo_server } from '@/api/buster_rest/users/requests'; import { getAppSplitterLayout } from '@/components/layout/AppSplitter'; import { useBusterSupabaseAuthMethods } from '@/hooks/useBusterSupabaseAuthMethods'; import { createBusterRoute } from '@/routes'; @@ -10,6 +9,8 @@ import { BusterAppRoutes } from '@/routes/busterRoutes/busterAppRoutes'; import { headers, cookies } from 'next/headers'; import { ClientRedirect } from '../../components/layout/ClientRedirect'; import { AppLayoutClient } from './layoutClient'; +import { prefetchGetMyUserInfo } from '@/api/buster_rest'; +import { dehydrate, HydrationBoundary } from '@tanstack/react-query'; export default async function Layout({ children @@ -18,7 +19,10 @@ export default async function Layout({ }>) { const headersList = headers(); const supabaseContext = await useSupabaseServerContext(); - const userInfo = await getMyUserInfo_server({ jwtToken: supabaseContext.accessToken }); + const { initialData: userInfo, queryClient } = await prefetchGetMyUserInfo({ + jwtToken: supabaseContext.accessToken + }); + const defaultLayout = await getAppSplitterLayout('app-layout', ['230px', 'auto']); const { signOut } = useBusterSupabaseAuthMethods(); const pathname = headersList.get('x-next-pathname') as string; @@ -29,7 +33,7 @@ export default async function Layout({ (!userInfo?.organizations?.[0]?.id || !userInfo?.user?.name) && !cookiePathname?.includes(newUserRoute) && pathname !== newUserRoute && - supabaseContext.accessToken //added to avoid bug with anon user + !!supabaseContext.accessToken //added to avoid bug with anon user ) { return ; } @@ -40,7 +44,7 @@ export default async function Layout({ supabaseContext={supabaseContext} defaultLayout={defaultLayout} signOut={signOut}> - {children} + {children} ); } diff --git a/web/src/app/app/layoutClient.tsx b/web/src/app/app/layoutClient.tsx index 22aeaff08..54604cf10 100644 --- a/web/src/app/app/layoutClient.tsx +++ b/web/src/app/app/layoutClient.tsx @@ -6,26 +6,30 @@ import { AppLayout } from './_controllers/AppLayout'; import type { BusterUserResponse } from '@/api/asset_interfaces'; import { useSupabaseServerContext } from '@/context/Supabase/useSupabaseContext'; import { GlobalErrorComponent } from '../../components/error'; +import { dehydrate, HydrationBoundary, QueryClient } from '@tanstack/react-query'; export const AppLayoutClient = ({ children, userInfo, supabaseContext, defaultLayout, + signOut }: { children: React.ReactNode; userInfo: BusterUserResponse | undefined; supabaseContext: Awaited>; defaultLayout: [string, string]; - signOut: () => void; + signOut: () => void; //DO I really need this here? }) => { return ( + {/* */} {children} + {/* */} ); diff --git a/web/src/context/AppProviders.tsx b/web/src/context/AppProviders.tsx index 55f70a06f..d70410339 100644 --- a/web/src/context/AppProviders.tsx +++ b/web/src/context/AppProviders.tsx @@ -25,6 +25,7 @@ import { BusterChatProvider } from './Chats'; import { RoutePrefetcher } from './RoutePrefetcher'; import { BusterMetricsProvider } from './Metrics'; import type { BusterUserResponse } from '@/api/asset_interfaces'; +import { QueryClient } from '@tanstack/react-query'; // scan({ // enabled: true, diff --git a/web/src/context/Users/UserConfigProvider.tsx b/web/src/context/Users/UserConfigProvider.tsx index 09dd8d5fb..0241a16d9 100644 --- a/web/src/context/Users/UserConfigProvider.tsx +++ b/web/src/context/Users/UserConfigProvider.tsx @@ -1,9 +1,9 @@ 'use client'; import type { BusterUserResponse } from '@/api/asset_interfaces'; -import React, { PropsWithChildren, useState } from 'react'; +import React, { PropsWithChildren } from 'react'; import { useFavoriteProvider } from './useFavoriteProvider'; -import { getMyUserInfo_server, useGetMyUserInfo } from '@/api/buster_rest/users'; +import { useGetMyUserInfo } from '@/api/buster_rest/users'; import { useSupabaseContext } from '../Supabase'; import { ContextSelector, @@ -17,7 +17,7 @@ import { useInviteUser } from './useInviteUser'; export const useUserConfigProvider = ({ userInfo }: { userInfo: BusterUserResponse | null }) => { const isAnonymousUser = useSupabaseContext((state) => state.isAnonymousUser); - const { data: userResponse, refetch: refetchUserResponse } = useGetMyUserInfo(); + const { data: userResponse, refetch: refetchUserResponse, isFetched } = useGetMyUserInfo(); const favoriteConfig = useFavoriteProvider();