Skip to content
This repository has been archived by the owner on Sep 9, 2024. It is now read-only.

Variable cleanup #82

Merged
merged 4 commits into from
May 13, 2024
Merged
Show file tree
Hide file tree
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
4 changes: 2 additions & 2 deletions packages/ocular-ui/components/chat-layout.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

import React, { ReactNode } from 'react';

import { ChatbotUIContext } from "@/context/context"
import { ApplicationContext } from "@/context/context"
import { ChatSideBar } from "@/components/chat/chat-sidebar/chat-sidebar"
import { GlobalState } from "@/lib/global-state"
import { useTheme } from "next-themes"
Expand All @@ -29,7 +29,7 @@ export default function ChatLayout({ children }: ChatLayoutProps) {
const pathname = usePathname()
const router = useRouter()
const [chatsLoaded, setChatsLoaded] = useState(false)
const { chatMessages, setChats } = useContext(ChatbotUIContext)
const { chatMessages, setChats } = useContext(ApplicationContext)
const searchParams = useSearchParams()
const tabValue = searchParams.get("tab") || "chats"

Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { ChatbotUIContext } from "@/context/context"
import { ApplicationContext } from "@/context/context"
import { buildFinalMessages } from "@/lib/build-prompt"
import { useRouter } from "next/navigation"
import { useContext, useEffect, useRef } from "react"
Expand All @@ -25,7 +25,7 @@ export const useChatHandler = () => {
chatMessages,
setIsPromptPickerOpen,
isPromptPickerOpen,
} = useContext(ChatbotUIContext)
} = useContext(ApplicationContext)

const chatInputRef = useRef<HTMLTextAreaElement>(null)
useEffect(() => {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { ChatbotUIContext } from "@/context/context"
import { ApplicationContext } from "@/context/context"
import { useContext, useEffect, useState } from "react"

/**
Expand All @@ -11,7 +11,7 @@ import { useContext, useEffect, useState } from "react"
*/
export const useChatHistoryHandler = () => {
const { setUserInput, chatMessages, isGenerating } =
useContext(ChatbotUIContext)
useContext(ApplicationContext)
const userRoleString = "user"

const [messageHistoryIndex, setMessageHistoryIndex] = useState<number>(
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { ChatbotUIContext } from "@/context/context"
import { ApplicationContext } from "@/context/context"
// import { getAssistantCollectionsByAssistantId } from "@/db/assistant-collections"
// import { getAssistantFilesByAssistantId } from "@/db/assistant-files"
// import { getAssistantToolsByAssistantId } from "@/db/assistant-tools"
Expand All @@ -12,7 +12,7 @@ export const usePromptAndCommand = () => {
userInput,
setUserInput,
setIsPromptPickerOpen,
} = useContext(ChatbotUIContext)
} = useContext(ApplicationContext)

const handleInputChange = (value: string) => {
const atTextRegex = /@([^ ]*)$/
Expand Down
4 changes: 2 additions & 2 deletions packages/ocular-ui/components/chat/chat-hooks/use-scroll.tsx
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { ChatbotUIContext } from "@/context/context"
import { ApplicationContext } from "@/context/context"
import {
type UIEventHandler,
useCallback,
Expand All @@ -9,7 +9,7 @@ import {
} from "react"

export const useScroll = () => {
const { isGenerating, chatMessages } = useContext(ChatbotUIContext)
const { isGenerating, chatMessages } = useContext(ApplicationContext)

const messagesStartRef = useRef<HTMLDivElement>(null)
const messagesEndRef = useRef<HTMLDivElement>(null)
Expand Down
4 changes: 2 additions & 2 deletions packages/ocular-ui/components/chat/chat-input.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ import {
IconSend
} from "@tabler/icons-react"

import { ChatbotUIContext } from "@/context/context"
import { ApplicationContext } from "@/context/context"
import { cn } from "@/lib/utils"
import { FC, useContext, useState } from "react"
import { TextareaAutosize } from "../ui/textarea-autosize"
Expand All @@ -22,7 +22,7 @@ export const ChatInput: FC<ChatInputProps> = ({}) => {
setFocusPrompt,
isPromptPickerOpen,
setIsPromptPickerOpen,
} = useContext(ChatbotUIContext)
} = useContext(ApplicationContext)

const {
chatInputRef,
Expand Down
4 changes: 2 additions & 2 deletions packages/ocular-ui/components/chat/chat-item.tsx
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { ChatbotUIContext } from "@/context/context"
import { ApplicationContext } from "@/context/context"
import { cn } from "@/lib/utils"
import { Chat } from "@/types/chat"
import { useParams, useRouter } from "next/navigation"
Expand All @@ -14,7 +14,7 @@ export const ChatItem: FC<ChatItemProps> = ({ chat }) => {
const {
selectedChat,
setSelectedChat,
} = useContext(ChatbotUIContext)
} = useContext(ApplicationContext)

const router = useRouter()
const params = useParams()
Expand Down
4 changes: 2 additions & 2 deletions packages/ocular-ui/components/chat/chat-messages.tsx
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
import { ChatbotUIContext } from "@/context/context"
import { ApplicationContext } from "@/context/context"
import { FC, useContext, useState } from "react"
import { Message } from "../messages/message"
import { Message as MessageType } from "@/types/chat"

interface ChatMessagesProps {}

export const ChatMessages: FC<ChatMessagesProps> = ({}) => {
const { chatMessages } = useContext(ChatbotUIContext)
const { chatMessages } = useContext(ApplicationContext)
const [editingMessage, setEditingMessage] = useState<MessageType>()

return chatMessages
Expand Down
4 changes: 2 additions & 2 deletions packages/ocular-ui/components/chat/chat-secondary-buttons.tsx
Original file line number Diff line number Diff line change
@@ -1,13 +1,13 @@
import { useChatHandler } from "@/components/chat/chat-hooks/use-chat-handler"
import { ChatbotUIContext } from "@/context/context"
import { ApplicationContext } from "@/context/context"
import { IconEdit } from "@tabler/icons-react"
import { FC, useContext } from "react"
import { WithTooltip } from "../ui/with-tooltip"

interface ChatSecondaryButtonsProps {}

export const ChatSecondaryButtons: FC<ChatSecondaryButtonsProps> = ({}) => {
const { selectedChat } = useContext(ChatbotUIContext)
const { selectedChat } = useContext(ApplicationContext)

const { handleNewChat } = useChatHandler()

Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { ChatbotUIContext } from "@/context/context"
import { ApplicationContext } from "@/context/context"
import { cn } from "@/lib/utils"
import { ContentType, DataItemType, DataListType } from "@/types"
import { FC, useContext, useEffect, useRef, useState } from "react"
Expand Down Expand Up @@ -35,7 +35,7 @@ export const SidebarDataList: FC<SidebarDataListProps> = ({
// setAssistants,
// setTools,
// setModels
} = useContext(ChatbotUIContext)
} = useContext(ApplicationContext)

const divRef = useRef<HTMLDivElement>(null)

Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { ChatbotUIContext } from "@/context/context"
import { ApplicationContext } from "@/context/context"
import { ContentType } from "@/types"
import { FC, useContext } from "react"
import { SIDEBAR_WIDTH } from "../../ui/dashboard"
Expand All @@ -13,7 +13,7 @@ interface SidebarProps {
export const ChatSideBar: FC<SidebarProps> = ({contentType, showSidebar }) => {
const {
chats,
} = useContext(ChatbotUIContext)
} = useContext(ApplicationContext)


const renderSidebarContent = (
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { ChatbotUIContext } from "@/context/context"
import { ApplicationContext } from "@/context/context"
import { useContext, useEffect, useState } from "react"

/**
Expand All @@ -11,7 +11,7 @@ import { useContext, useEffect, useState } from "react"
*/
export const useChatHistoryHandler = () => {
const { setUserInput, chatMessages, isGenerating } =
useContext(ChatbotUIContext)
useContext(ApplicationContext)
const userRoleString = "user"

const [messageHistoryIndex, setMessageHistoryIndex] = useState<number>(
Expand Down
4 changes: 2 additions & 2 deletions packages/ocular-ui/components/chat/chat-ui.tsx
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { useChatHandler } from "@/components/chat/chat-hooks/use-chat-handler"
import { ChatbotUIContext } from "@/context/context"
import { ApplicationContext } from "@/context/context"
import { useParams } from "next/navigation"
import { FC, useContext, useEffect, useState } from "react"
import { useScroll } from "./chat-hooks/use-scroll"
Expand All @@ -20,7 +20,7 @@ export const ChatUI: FC<ChatUIProps> = ({}) => {
setChatMessages,
selectedChat,
setSelectedChat,
} = useContext(ChatbotUIContext)
} = useContext(ApplicationContext)

const { handleNewChat, handleFocusChatInput } = useChatHandler()

Expand Down
4 changes: 2 additions & 2 deletions packages/ocular-ui/components/date-picker.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ import { format as formatDateFns } from "date-fns"
import { cn } from "@/lib/utils"
import { Button } from "@/components/ui/button"
import { Calendar } from "@/components/ui/calendar"
import { ChatbotUIContext } from "@/context/context";
import { ApplicationContext } from "@/context/context";
import {
Popover,
PopoverContent,
Expand All @@ -20,7 +20,7 @@ export function DatePickerWithRange({
className,
}: React.HTMLAttributes<HTMLDivElement>) {

const { resultFilterDate, setResultFilterDate } = useContext(ChatbotUIContext);
const { resultFilterDate, setResultFilterDate } = useContext(ApplicationContext);
const [isSelected, setIsSelected] = useState(false);

// Serialize the date to JSON format when logging
Expand Down
4 changes: 2 additions & 2 deletions packages/ocular-ui/components/messages/message-actions.tsx
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { ChatbotUIContext } from "@/context/context"
import { ApplicationContext } from "@/context/context"
import { IconCheck, IconCopy, IconEdit, IconRepeat } from "@tabler/icons-react"
import { FC, useContext, useEffect, useState } from "react"
import { WithTooltip } from "../ui/with-tooltip"
Expand All @@ -20,7 +20,7 @@ export const MessageActions: FC<MessageActionsProps> = ({
isHovering,
onCopy,
}) => {
const { isGenerating } = useContext(ChatbotUIContext)
const { isGenerating } = useContext(ApplicationContext)

const [showCheckmark, setShowCheckmark] = useState(false)

Expand Down
4 changes: 2 additions & 2 deletions packages/ocular-ui/components/messages/message.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
import { useRouter } from "next/navigation";
import { useTheme } from 'next-themes';

import { ChatbotUIContext } from "@/context/context"
import { ApplicationContext } from "@/context/context"
import { cn } from "@/lib/utils"
import {
IconBolt,
Expand Down Expand Up @@ -54,7 +54,7 @@ export const Message: FC<MessageProps> = ({
setIsGenerating,
firstTokenReceived,
chatMessages,
} = useContext(ChatbotUIContext)
} = useContext(ApplicationContext)

const editInputRef = useRef<HTMLTextAreaElement>(null)

Expand Down
21 changes: 11 additions & 10 deletions packages/ocular-ui/components/search/app-filter-option.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -3,23 +3,24 @@
import { useState, useContext } from 'react';
import Image from 'next/image';

import { ChatbotUIContext } from "@/context/context";
import { ApplicationContext } from "@/context/context";

type AppFilterOptionProps = {
src: string;
title: string;
label: string;
value: string;
results?: any;
};

export default function AppFilterOption({ src, title, results }: AppFilterOptionProps) {
const { setselectedResultSources, activeFilter, setActiveFilter } = useContext(ChatbotUIContext);

export default function AppFilterOption({ src, label, value, results }: AppFilterOptionProps) {
const { setselectedResultSources, activeFilter, setActiveFilter } = useContext(ApplicationContext);
const handleClick = () => {
setselectedResultSources([title]);
setActiveFilter(title);
setselectedResultSources([value]);
setActiveFilter(value);
};

const isSelected = activeFilter === title;
const isSelected = activeFilter === value;

return (
<div
Expand All @@ -29,9 +30,9 @@ export default function AppFilterOption({ src, title, results }: AppFilterOption
onClick={handleClick}
>
<div className='flex grow gap-2'>
<Image src={src} alt={title} width={20} height={20} />
<Image src={src} alt={label} width={20} height={20} />
<p className="hidden font-semibold text-sm sm:inline-flex dark:text-white">
{title.split('.')[0].charAt(0).toUpperCase() + title.split('.')[0].slice(1)}
{label}
</p>
</div>
<p className="hidden text-sm text-gray-500 sm:inline-flex">
Expand Down
19 changes: 13 additions & 6 deletions packages/ocular-ui/components/search/app-filter-options.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -3,15 +3,16 @@
import { useContext } from 'react';
import AppFilterOption from "./app-filter-option";
import Image from 'next/image';
import { ChatbotUIContext } from "@/context/context";
import { ApplicationContext } from "@/context/context";
import { formatLabel } from '@/lib/utils';

type AppFilterOptionsProps = {
results: any;
resultSources: string[];
};

export default function AppFilterOptions({results}: AppFilterOptionsProps) {
const { resultSources } = useContext(ChatbotUIContext);
const { activeFilter, setActiveFilter, setselectedResultSources } = useContext(ChatbotUIContext);
export default function AppFilterOptions({results, resultSources}: AppFilterOptionsProps) {
const { activeFilter, setActiveFilter, setselectedResultSources } = useContext(ApplicationContext);

const handleClick = () => {
setselectedResultSources(resultSources);
Expand All @@ -20,6 +21,12 @@ export default function AppFilterOptions({results}: AppFilterOptionsProps) {

const isSelected = activeFilter === 'All';

const mappedResultSources = resultSources.map(source => ({
label: formatLabel(source),
value: source,
icon: `/${source}.svg`,
}));

return (
<div className="mt-3 flex w-full text-sm text-gray-700 lg:justify-start lg:text-base dark:text-gray-400">
<div className="flex w-full flex-col justify-start space-y-2 sm:w-auto">
Expand All @@ -33,8 +40,8 @@ export default function AppFilterOptions({results}: AppFilterOptionsProps) {
</div>
<p className="hidden text-sm text-gray-500 sm:inline-flex">{results ? results : Math.floor(Math.random() * 1000) + 1}</p>
</div>
{resultSources.map((iconName) => (
<AppFilterOption src={`/${iconName}.svg`} title={iconName} key={iconName} />
{mappedResultSources.map((iconName) => (
<AppFilterOption src={iconName.icon} label={iconName.label} key={iconName.value} value={iconName.value} />
))}
</div>
</div>
Expand Down
Loading