From c4d9e3aeed5b39a07e555c415ca22addc52cffd4 Mon Sep 17 00:00:00 2001 From: n4ze3m Date: Sat, 16 Nov 2024 15:50:11 +0530 Subject: [PATCH] feat: Add page assist select component to header This commit introduces a new `PageAssistSelect` component to the header, which replaces the previous `Select` component for selecting the active chat model. The new component provides improved functionality, including: - Ability to display provider icons alongside the model name - Truncation of long model names to ensure they fit within the available space - Improved loading state handling - Ability to refresh the model list on demand These changes enhance the user experience and make it easier for users to quickly select the desired chat model. --- src/components/Layouts/Header.tsx | 45 ++- src/components/Select/LoadingIndicator.tsx | 27 ++ src/components/Select/index.tsx | 303 +++++++++++++++++++++ 3 files changed, 350 insertions(+), 25 deletions(-) create mode 100644 src/components/Select/LoadingIndicator.tsx create mode 100644 src/components/Select/index.tsx diff --git a/src/components/Layouts/Header.tsx b/src/components/Layouts/Header.tsx index 7f3e153..3e4a1f6 100644 --- a/src/components/Layouts/Header.tsx +++ b/src/components/Layouts/Header.tsx @@ -22,6 +22,7 @@ import { getAllPrompts } from "@/db" import { ShareBtn } from "~/components/Common/ShareBtn" import { ProviderIcons } from "../Common/ProviderIcon" import { NewChat } from "./NewChat" +import { PageAssistSelect } from "../Select" type Props = { setSidebarOpen: (open: boolean) => void setOpenModelSettings: (open: boolean) => void @@ -49,14 +50,10 @@ export const Header: React.FC = ({ historyId, temporaryChat } = useMessageOption() - const { - data: models, - isLoading: isModelsLoading, - } = useQuery({ + const { data: models, isLoading: isModelsLoading, refetch } = useQuery({ queryKey: ["fetchModel"], queryFn: () => fetchChatModels({ returnEmpty: true }), - refetchInterval: 15_000, - refetchIntervalInBackground: true, + refetchIntervalInBackground: false, placeholderData: (prev) => prev }) @@ -87,9 +84,10 @@ export const Header: React.FC = ({ } return ( -
+
{pathname !== "/" && (
@@ -107,41 +105,38 @@ export const Header: React.FC = ({
- + {"/"}
- setSearchTerm(e.target.value)} + placeholder="Search..." + className={`${defaultSearchClass} ${searchClassName}`} + disabled={isLoading} + aria-label="Search options" + /> +
+
+ +
+ {isLoading ? ( +
+ + {loadingText} +
+ ) : filteredOptions.length === 0 ? ( +
+ +
+ ) : ( + filteredOptions.map((option, index) => ( +
{ + onChange(option) + setIsOpen(false) + setSearchTerm("") + }} + className={` + ${defaultOptionClass} + ${value === option.value ? "bg-blue-50 dark:bg-[#262627]" : "hover:bg-gray-100 dark:hover:bg-[#272728]"} + ${activeIndex === index ? "bg-gray-100 dark:bg-[#272728]" : ""} + ${optionClassName}`}> + {option.label} +
+ )) + )} +
+
+ )} +
+ ) +} \ No newline at end of file