2023-07-07 13:56:08 +03:00
|
|
|
"use client";
|
|
|
|
|
2023-09-01 16:14:35 +03:00
|
|
|
import { QueryClient, QueryClientProvider } from "@tanstack/react-query";
|
2023-12-30 01:45:36 +03:00
|
|
|
import { posthog } from "posthog-js";
|
|
|
|
import { PostHogProvider } from "posthog-js/react";
|
2023-07-07 13:56:08 +03:00
|
|
|
import { PropsWithChildren, useEffect } from "react";
|
|
|
|
|
2024-02-15 03:37:33 +03:00
|
|
|
import { BrainCreationProvider } from "@/lib/components/AddBrainModal/brainCreation-provider";
|
2023-12-14 12:15:38 +03:00
|
|
|
import { Menu } from "@/lib/components/Menu/Menu";
|
2023-12-14 18:22:09 +03:00
|
|
|
import { useOutsideClickListener } from "@/lib/components/Menu/hooks/useOutsideClickListener";
|
2024-01-27 03:06:01 +03:00
|
|
|
import SearchModal from "@/lib/components/SearchModal/SearchModal";
|
2024-01-31 00:34:32 +03:00
|
|
|
import {
|
|
|
|
BrainProvider,
|
|
|
|
ChatProvider,
|
|
|
|
KnowledgeToFeedProvider,
|
|
|
|
} from "@/lib/context";
|
2023-07-07 13:56:08 +03:00
|
|
|
import { useBrainContext } from "@/lib/context/BrainProvider/hooks/useBrainContext";
|
2024-01-20 07:34:30 +03:00
|
|
|
import { ChatsProvider } from "@/lib/context/ChatsProvider";
|
|
|
|
import { MenuProvider } from "@/lib/context/MenuProvider/Menu-provider";
|
2024-07-22 17:41:30 +03:00
|
|
|
import { useMenuContext } from "@/lib/context/MenuProvider/hooks/useMenuContext";
|
2024-07-10 18:13:47 +03:00
|
|
|
import { NotificationsProvider } from "@/lib/context/NotificationsProvider/notifications-provider";
|
2024-03-21 22:10:54 +03:00
|
|
|
import { OnboardingProvider } from "@/lib/context/OnboardingProvider/Onboarding-provider";
|
2024-01-27 03:06:01 +03:00
|
|
|
import { SearchModalProvider } from "@/lib/context/SearchModalProvider/search-modal-provider";
|
2023-07-17 16:45:18 +03:00
|
|
|
import { useSupabase } from "@/lib/context/SupabaseProvider";
|
2024-03-21 10:01:21 +03:00
|
|
|
import { UserSettingsProvider } from "@/lib/context/UserSettingsProvider/User-settings.provider";
|
2024-02-05 09:06:24 +03:00
|
|
|
import { IntercomProvider } from "@/lib/helpers/intercom/IntercomProvider";
|
2023-08-07 15:13:41 +03:00
|
|
|
import { UpdateMetadata } from "@/lib/helpers/updateMetadata";
|
2023-09-18 16:12:50 +03:00
|
|
|
import { usePageTracking } from "@/services/analytics/june/usePageTracking";
|
2024-06-09 19:43:18 +03:00
|
|
|
|
2023-08-29 11:50:36 +03:00
|
|
|
import "../lib/config/LocaleConfig/i18n";
|
2024-07-22 17:41:30 +03:00
|
|
|
import styles from "./App.module.scss";
|
2024-06-09 19:43:18 +03:00
|
|
|
import { FromConnectionsProvider } from "./chat/[chatId]/components/ActionsBar/components/KnowledgeToFeed/components/FromConnections/FromConnectionsProvider/FromConnection-provider";
|
2023-07-07 13:56:08 +03:00
|
|
|
|
2023-12-30 01:45:36 +03:00
|
|
|
if (
|
|
|
|
process.env.NEXT_PUBLIC_POSTHOG_KEY != null &&
|
|
|
|
process.env.NEXT_PUBLIC_POSTHOG_HOST != null
|
|
|
|
) {
|
|
|
|
posthog.init(process.env.NEXT_PUBLIC_POSTHOG_KEY, {
|
2024-01-02 12:23:40 +03:00
|
|
|
api_host: process.env.NEXT_PUBLIC_POSTHOG_HOST,
|
2023-12-30 01:45:36 +03:00
|
|
|
opt_in_site_apps: true,
|
2023-12-30 02:53:47 +03:00
|
|
|
disable_session_recording: true,
|
2023-12-30 01:45:36 +03:00
|
|
|
});
|
2023-12-28 13:03:05 +03:00
|
|
|
}
|
|
|
|
|
2023-07-07 13:56:08 +03:00
|
|
|
// This wrapper is used to make effect calls at a high level in app rendering.
|
2023-11-20 20:04:26 +03:00
|
|
|
const App = ({ children }: PropsWithChildren): JSX.Element => {
|
2024-04-10 12:45:16 +03:00
|
|
|
const { fetchAllBrains } = useBrainContext();
|
2023-12-14 18:22:09 +03:00
|
|
|
const { onClickOutside } = useOutsideClickListener();
|
2023-07-17 16:45:18 +03:00
|
|
|
const { session } = useSupabase();
|
2024-07-22 17:41:30 +03:00
|
|
|
const { isOpened } = useMenuContext();
|
2023-07-07 13:56:08 +03:00
|
|
|
|
2023-09-01 16:14:35 +03:00
|
|
|
usePageTracking();
|
|
|
|
|
2023-07-07 13:56:08 +03:00
|
|
|
useEffect(() => {
|
2023-10-02 10:27:17 +03:00
|
|
|
if (session?.user) {
|
2024-01-27 03:06:01 +03:00
|
|
|
void fetchAllBrains();
|
2024-04-09 19:06:33 +03:00
|
|
|
|
2024-01-27 03:06:01 +03:00
|
|
|
posthog.identify(session.user.id, { email: session.user.email });
|
|
|
|
posthog.startSessionRecording();
|
2023-10-02 10:27:17 +03:00
|
|
|
}
|
|
|
|
}, [session]);
|
2023-07-07 13:56:08 +03:00
|
|
|
|
|
|
|
return (
|
2024-02-24 05:46:51 +03:00
|
|
|
<>
|
|
|
|
<PostHogProvider client={posthog}>
|
|
|
|
<IntercomProvider>
|
|
|
|
<div className="flex flex-1 flex-col overflow-auto">
|
|
|
|
<SearchModalProvider>
|
|
|
|
<SearchModal />
|
2024-07-22 17:41:30 +03:00
|
|
|
<div className={styles.app_container}>
|
|
|
|
<div className={styles.menu_container}>
|
|
|
|
<Menu />
|
|
|
|
</div>
|
2024-02-24 05:46:51 +03:00
|
|
|
<div
|
|
|
|
onClick={onClickOutside}
|
2024-07-22 17:41:30 +03:00
|
|
|
className={`${styles.content_container} ${
|
|
|
|
isOpened ? styles.blured : ""
|
|
|
|
}`}
|
2024-02-24 05:46:51 +03:00
|
|
|
>
|
|
|
|
{children}
|
|
|
|
</div>
|
|
|
|
<UpdateMetadata />
|
2024-02-05 09:06:24 +03:00
|
|
|
</div>
|
2024-02-24 05:46:51 +03:00
|
|
|
</SearchModalProvider>
|
|
|
|
</div>
|
|
|
|
</IntercomProvider>
|
|
|
|
</PostHogProvider>
|
|
|
|
</>
|
2023-11-20 20:04:26 +03:00
|
|
|
);
|
|
|
|
};
|
|
|
|
|
|
|
|
const queryClient = new QueryClient();
|
|
|
|
|
|
|
|
const AppWithQueryClient = ({ children }: PropsWithChildren): JSX.Element => {
|
|
|
|
return (
|
|
|
|
<QueryClientProvider client={queryClient}>
|
2024-03-21 10:01:21 +03:00
|
|
|
<UserSettingsProvider>
|
|
|
|
<BrainProvider>
|
|
|
|
<KnowledgeToFeedProvider>
|
|
|
|
<BrainCreationProvider>
|
2024-07-10 18:13:47 +03:00
|
|
|
<NotificationsProvider>
|
|
|
|
<MenuProvider>
|
|
|
|
<OnboardingProvider>
|
|
|
|
<FromConnectionsProvider>
|
|
|
|
<ChatsProvider>
|
|
|
|
<ChatProvider>
|
|
|
|
<App>{children}</App>
|
|
|
|
</ChatProvider>
|
|
|
|
</ChatsProvider>
|
|
|
|
</FromConnectionsProvider>
|
|
|
|
</OnboardingProvider>
|
|
|
|
</MenuProvider>
|
|
|
|
</NotificationsProvider>
|
2024-03-21 10:01:21 +03:00
|
|
|
</BrainCreationProvider>
|
|
|
|
</KnowledgeToFeedProvider>
|
|
|
|
</BrainProvider>
|
|
|
|
</UserSettingsProvider>
|
2023-09-01 16:14:35 +03:00
|
|
|
</QueryClientProvider>
|
2023-07-07 13:56:08 +03:00
|
|
|
);
|
|
|
|
};
|
2023-11-20 20:04:26 +03:00
|
|
|
|
|
|
|
export { AppWithQueryClient as App };
|