bookwiz.io / lib / contexts / ChatContext.tsx
ChatContext.tsx
Raw
'use client'

import React, { createContext, useContext } from 'react'
import { Chat } from '@/lib/types/database'

export interface ChatContextType {
  currentChatId: string | null
  setCurrentChatId: (chatId: string | null) => void
  chats: Chat[]
  fetchChats: () => void
  addNewChatToList: (newChat: Chat) => void
  updateChatTimestamp: (chatId: string) => void
}

export const ChatContext = createContext<ChatContextType | null>(null)

export const useChatContext = () => {
  const context = useContext(ChatContext)
  if (!context) {
    throw new Error('useChatContext must be used within a ChatContext.Provider')
  }
  return context
}