fix(frontend): resolve build errors
- Fix undefined loadHistory in App.tsx - Use type-only import for Theme in theme-provider.tsx - Update auth.ts to import Theme from theme-context
This commit is contained in:
@@ -9,7 +9,8 @@ import { ChatService, type MessageResponse } from "./services/chat"
|
||||
import { type Conversation } from "./components/layout/HistorySidebar"
|
||||
import { registerUnauthorizedCallback } from "./services/api"
|
||||
import { Button } from "./components/ui/button"
|
||||
import { ThemeProvider, useTheme } from "./components/theme-provider"
|
||||
import { ThemeProvider } from "./components/theme-provider"
|
||||
import { useTheme } from "./components/theme-context"
|
||||
import { useSilentRefresh } from "./hooks/use-silent-refresh"
|
||||
|
||||
// --- Auth Context ---
|
||||
@@ -61,6 +62,15 @@ function AppContent() {
|
||||
const [conversations, setConversations] = useState<Conversation[]>([])
|
||||
const [threadMessages, setThreadMessages] = useState<Record<string, MessageResponse[]>>({})
|
||||
|
||||
const loadHistory = useCallback(async () => {
|
||||
try {
|
||||
const history = await ChatService.listConversations()
|
||||
setConversations(history)
|
||||
} catch (err) {
|
||||
console.error("Failed to load conversation history:", err)
|
||||
}
|
||||
}, [])
|
||||
|
||||
useEffect(() => {
|
||||
registerUnauthorizedCallback(() => {
|
||||
setIsAuthenticated(false)
|
||||
@@ -89,16 +99,7 @@ function AppContent() {
|
||||
}
|
||||
|
||||
initAuth()
|
||||
}, [setIsAuthenticated, setThemeLocal, setUser])
|
||||
|
||||
const loadHistory = useCallback(async () => {
|
||||
try {
|
||||
const history = await ChatService.listConversations()
|
||||
setConversations(history)
|
||||
} catch (err) {
|
||||
console.error("Failed to load conversation history:", err)
|
||||
}
|
||||
}, [])
|
||||
}, [setIsAuthenticated, setThemeLocal, setUser, loadHistory])
|
||||
|
||||
const handleAuthSuccess = useCallback(async () => {
|
||||
try {
|
||||
|
||||
@@ -1,16 +1,6 @@
|
||||
import { createContext, useContext, useEffect, useState, useCallback, useMemo } from "react"
|
||||
import { useEffect, useState, useCallback, useMemo } from "react"
|
||||
import { AuthService } from "@/services/auth"
|
||||
|
||||
export type Theme = "light" | "dark"
|
||||
|
||||
interface ThemeContextType {
|
||||
theme: Theme
|
||||
setTheme: (theme: Theme) => void
|
||||
setThemeLocal: (theme: Theme) => void
|
||||
toggleTheme: () => void
|
||||
}
|
||||
|
||||
const ThemeContext = createContext<ThemeContextType | undefined>(undefined)
|
||||
import { type Theme, ThemeContext } from "./theme-context"
|
||||
|
||||
export function ThemeProvider({
|
||||
children,
|
||||
@@ -61,11 +51,3 @@ export function ThemeProvider({
|
||||
</ThemeContext.Provider>
|
||||
)
|
||||
}
|
||||
|
||||
export const useTheme = () => {
|
||||
const context = useContext(ThemeContext)
|
||||
if (context === undefined) {
|
||||
throw new Error("useTheme must be used within a ThemeProvider")
|
||||
}
|
||||
return context
|
||||
}
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
import api from "./api"
|
||||
import type { Theme } from "@/components/theme-provider"
|
||||
import type { Theme } from "@/components/theme-context"
|
||||
|
||||
export interface AuthResponse {
|
||||
access_token: string
|
||||
|
||||
Reference in New Issue
Block a user