From ab09b967ac7d7ef114f0d06257dcb8853b653715 Mon Sep 17 00:00:00 2001 From: pablodanswer Date: Wed, 16 Oct 2024 12:08:15 -0700 Subject: [PATCH] ensure context passed properly --- web/src/app/assistants/SidebarWrapper.tsx | 14 ++------ .../assistants/gallery/AssistantsGallery.tsx | 4 ++- .../gallery/WrappedAssistantsGallery.tsx | 11 ++----- web/src/app/assistants/gallery/page.tsx | 1 - .../app/assistants/mine/AssistantsList.tsx | 13 +------- .../assistants/mine/WrappedAssistantsMine.tsx | 13 ++------ .../assistants/mine/WrappedInputPrompts.tsx | 33 ++++++++----------- web/src/app/assistants/mine/page.tsx | 1 - web/src/app/chat/ChatPage.tsx | 1 - web/src/app/chat/shared/[chatId]/page.tsx | 2 +- web/src/app/prompts/page.tsx | 3 +- web/src/components/chat_search/Header.tsx | 10 ++---- web/src/components/search/SearchSection.tsx | 1 - 13 files changed, 31 insertions(+), 76 deletions(-) diff --git a/web/src/app/assistants/SidebarWrapper.tsx b/web/src/app/assistants/SidebarWrapper.tsx index 9a1d320d7..58190228b 100644 --- a/web/src/app/assistants/SidebarWrapper.tsx +++ b/web/src/app/assistants/SidebarWrapper.tsx @@ -26,14 +26,9 @@ interface SidebarWrapperProps { folders?: Folder[]; initiallyToggled: boolean; openedFolders?: { [key: number]: boolean }; - content: (props: T) => ReactNode; - headerProps: { - page: pageType; - user: User | null; - }; - contentProps: T; page: pageType; size?: "sm" | "lg"; + children: ReactNode; } export default function SidebarWrapper({ @@ -42,10 +37,8 @@ export default function SidebarWrapper({ folders, openedFolders, page, - headerProps, - contentProps, - content, size = "sm", + children, }: SidebarWrapperProps) { const [toggledSidebar, setToggledSidebar] = useState(initiallyToggled); const [showDocSidebar, setShowDocSidebar] = useState(false); // State to track if sidebar is open @@ -144,7 +137,6 @@ export default function SidebarWrapper({ sidebarToggled={toggledSidebar} toggleSidebar={toggleSidebar} page="assistants" - user={headerProps.user} />
({
- {content(contentProps)} + {children}
diff --git a/web/src/app/assistants/gallery/AssistantsGallery.tsx b/web/src/app/assistants/gallery/AssistantsGallery.tsx index 856e778c6..c704b50c0 100644 --- a/web/src/app/assistants/gallery/AssistantsGallery.tsx +++ b/web/src/app/assistants/gallery/AssistantsGallery.tsx @@ -16,6 +16,7 @@ import { useRouter } from "next/navigation"; import { AssistantTools } from "../ToolsDisplay"; import { classifyAssistants } from "@/lib/assistants/utils"; import { useAssistants } from "@/components/context/AssisantsContext"; +import { useUser } from "@/components/user/UserProvider"; export function AssistantGalleryCard({ assistant, user, @@ -137,8 +138,9 @@ export function AssistantGalleryCard({ ); } -export function AssistantsGallery({ user }: { user: User | null }) { +export function AssistantsGallery() { const { assistants } = useAssistants(); + const { user } = useUser(); const router = useRouter(); diff --git a/web/src/app/assistants/gallery/WrappedAssistantsGallery.tsx b/web/src/app/assistants/gallery/WrappedAssistantsGallery.tsx index 6e6700a67..afb5f6a7a 100644 --- a/web/src/app/assistants/gallery/WrappedAssistantsGallery.tsx +++ b/web/src/app/assistants/gallery/WrappedAssistantsGallery.tsx @@ -12,13 +12,11 @@ export default function WrappedAssistantsGallery({ initiallyToggled, folders, openedFolders, - user, }: { chatSessions: ChatSession[]; folders: Folder[]; initiallyToggled: boolean; openedFolders?: { [key: number]: boolean }; - user: User | null; }) { return ( } - /> + > + + ); } diff --git a/web/src/app/assistants/gallery/page.tsx b/web/src/app/assistants/gallery/page.tsx index 208a2948d..a516ae34f 100644 --- a/web/src/app/assistants/gallery/page.tsx +++ b/web/src/app/assistants/gallery/page.tsx @@ -41,7 +41,6 @@ export default async function GalleryPage({ chatSessions={chatSessions} folders={folders} openedFolders={openedFolders} - user={user} /> diff --git a/web/src/app/assistants/mine/AssistantsList.tsx b/web/src/app/assistants/mine/AssistantsList.tsx index 4834079cf..eabed73c6 100644 --- a/web/src/app/assistants/mine/AssistantsList.tsx +++ b/web/src/app/assistants/mine/AssistantsList.tsx @@ -1,12 +1,6 @@ "use client"; -import React, { - Dispatch, - SetStateAction, - use, - useEffect, - useState, -} from "react"; +import React, { Dispatch, SetStateAction, useEffect, useState } from "react"; import { MinimalUserSnapshot, User } from "@/lib/types"; import { Persona } from "@/app/admin/assistants/interfaces"; import { Button, Divider } from "@tremor/react"; @@ -61,11 +55,6 @@ import { } from "@/app/admin/assistants/lib"; import { DeleteEntityModal } from "@/components/modals/DeleteEntityModal"; import { MakePublicAssistantModal } from "@/app/chat/modal/MakePublicAssistantModal"; -import { - classifyAssistants, - getUserCreatedAssistants, - orderAssistantsForUser, -} from "@/lib/assistants/utils"; import { CustomTooltip } from "@/components/tooltip/CustomTooltip"; import { useAssistants } from "@/components/context/AssisantsContext"; import { useUser } from "@/components/user/UserProvider"; diff --git a/web/src/app/assistants/mine/WrappedAssistantsMine.tsx b/web/src/app/assistants/mine/WrappedAssistantsMine.tsx index 81f52c14d..3e54662b8 100644 --- a/web/src/app/assistants/mine/WrappedAssistantsMine.tsx +++ b/web/src/app/assistants/mine/WrappedAssistantsMine.tsx @@ -3,21 +3,17 @@ import { AssistantsList } from "./AssistantsList"; import SidebarWrapper from "../SidebarWrapper"; import { ChatSession } from "@/app/chat/interfaces"; import { Folder } from "@/app/chat/folders/interfaces"; -import { Persona } from "@/app/admin/assistants/interfaces"; -import { User } from "@/lib/types"; export default function WrappedAssistantsMine({ chatSessions, initiallyToggled, folders, openedFolders, - user, }: { chatSessions: ChatSession[]; folders: Folder[]; initiallyToggled: boolean; openedFolders?: { [key: number]: boolean }; - user: User | null; }) { return ( } - /> + > + + ); } diff --git a/web/src/app/assistants/mine/WrappedInputPrompts.tsx b/web/src/app/assistants/mine/WrappedInputPrompts.tsx index 964e003a0..e39e69536 100644 --- a/web/src/app/assistants/mine/WrappedInputPrompts.tsx +++ b/web/src/app/assistants/mine/WrappedInputPrompts.tsx @@ -13,13 +13,11 @@ export default function WrappedPrompts({ initiallyToggled, folders, openedFolders, - user, }: { chatSessions: ChatSession[]; folders: Folder[]; initiallyToggled: boolean; openedFolders?: { [key: number]: boolean }; - user: User | null; }) { const { data: promptLibrary, @@ -36,23 +34,18 @@ export default function WrappedPrompts({ chatSessions={chatSessions} folders={folders} openedFolders={openedFolders} - headerProps={{ user, page: "chat" }} - contentProps={{ - user: user, - }} - content={(_) => ( -
- Prompt Gallery - -
- )} - /> + > +
+ Prompt Gallery + +
+ ); } diff --git a/web/src/app/assistants/mine/page.tsx b/web/src/app/assistants/mine/page.tsx index 757a1b901..0a27de835 100644 --- a/web/src/app/assistants/mine/page.tsx +++ b/web/src/app/assistants/mine/page.tsx @@ -39,7 +39,6 @@ export default async function GalleryPage({ chatSessions={chatSessions} folders={folders} openedFolders={openedFolders} - user={user} /> ); diff --git a/web/src/app/chat/ChatPage.tsx b/web/src/app/chat/ChatPage.tsx index 890062767..7e709e1cd 100644 --- a/web/src/app/chat/ChatPage.tsx +++ b/web/src/app/chat/ChatPage.tsx @@ -1938,7 +1938,6 @@ export function ChatPage({ : undefined } toggleSidebar={toggleSidebar} - user={user} currentChatSession={selectedChatSession} /> )} diff --git a/web/src/app/chat/shared/[chatId]/page.tsx b/web/src/app/chat/shared/[chatId]/page.tsx index e620e85cd..277281232 100644 --- a/web/src/app/chat/shared/[chatId]/page.tsx +++ b/web/src/app/chat/shared/[chatId]/page.tsx @@ -67,7 +67,7 @@ export default async function Page({ params }: { params: { chatId: string } }) { return (
- +
diff --git a/web/src/app/prompts/page.tsx b/web/src/app/prompts/page.tsx index 0da6b319c..20c9038ac 100644 --- a/web/src/app/prompts/page.tsx +++ b/web/src/app/prompts/page.tsx @@ -16,7 +16,7 @@ export default async function GalleryPage({ redirect(data.redirect); } - const { user, chatSessions, folders, openedFolders, toggleSidebar } = data; + const { chatSessions, folders, openedFolders, toggleSidebar } = data; return ( ); } diff --git a/web/src/components/chat_search/Header.tsx b/web/src/components/chat_search/Header.tsx index 7ad1b34a2..fc17b1d9d 100644 --- a/web/src/components/chat_search/Header.tsx +++ b/web/src/components/chat_search/Header.tsx @@ -2,23 +2,19 @@ import { User } from "@/lib/types"; import { UserDropdown } from "../UserDropdown"; import { FiShare2 } from "react-icons/fi"; -import { SetStateAction, useContext, useEffect, useState } from "react"; +import { SetStateAction, useEffect } from "react"; import { NewChatIcon } from "../icons/icons"; import { NEXT_PUBLIC_NEW_CHAT_DIRECTS_TO_SAME_PERSONA } from "@/lib/constants"; import { ChatSession } from "@/app/chat/interfaces"; -import { Notification } from "@/app/admin/settings/interfaces"; -import { Persona } from "@/app/admin/assistants/interfaces"; import Link from "next/link"; import { pageType } from "@/app/chat/sessionSidebar/types"; import { useRouter } from "next/navigation"; import { ChatBanner } from "@/app/chat/ChatBanner"; import LogoType from "../header/LogoType"; -import useSWR from "swr"; -import { errorHandlingFetcher } from "@/lib/fetcher"; import { NotificationCard } from "./Notification"; +import { useUser } from "../user/UserProvider"; export default function FunctionalHeader({ - user, page, currentChatSession, setSharingModalVisible, @@ -28,12 +24,12 @@ export default function FunctionalHeader({ }: { reset?: () => void; page: pageType; - user: User | null; sidebarToggled?: boolean; currentChatSession?: ChatSession | null | undefined; setSharingModalVisible?: (value: SetStateAction) => void; toggleSidebar?: () => void; }) { + const { user } = useUser(); useEffect(() => { const handleKeyDown = (event: KeyboardEvent) => { if (event.metaKey || event.ctrlKey) { diff --git a/web/src/components/search/SearchSection.tsx b/web/src/components/search/SearchSection.tsx index b1215a370..b8c13be91 100644 --- a/web/src/components/search/SearchSection.tsx +++ b/web/src/components/search/SearchSection.tsx @@ -709,7 +709,6 @@ export const SearchSection = ({ reset={() => setQuery("")} toggleSidebar={toggleSidebar} page="search" - user={user} />