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 { type Conversation } from "./components/layout/HistorySidebar"
|
||||||
import { registerUnauthorizedCallback } from "./services/api"
|
import { registerUnauthorizedCallback } from "./services/api"
|
||||||
import { Button } from "./components/ui/button"
|
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"
|
import { useSilentRefresh } from "./hooks/use-silent-refresh"
|
||||||
|
|
||||||
// --- Auth Context ---
|
// --- Auth Context ---
|
||||||
@@ -61,6 +62,15 @@ function AppContent() {
|
|||||||
const [conversations, setConversations] = useState<Conversation[]>([])
|
const [conversations, setConversations] = useState<Conversation[]>([])
|
||||||
const [threadMessages, setThreadMessages] = useState<Record<string, MessageResponse[]>>({})
|
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(() => {
|
useEffect(() => {
|
||||||
registerUnauthorizedCallback(() => {
|
registerUnauthorizedCallback(() => {
|
||||||
setIsAuthenticated(false)
|
setIsAuthenticated(false)
|
||||||
@@ -89,16 +99,7 @@ function AppContent() {
|
|||||||
}
|
}
|
||||||
|
|
||||||
initAuth()
|
initAuth()
|
||||||
}, [setIsAuthenticated, setThemeLocal, setUser])
|
}, [setIsAuthenticated, setThemeLocal, setUser, loadHistory])
|
||||||
|
|
||||||
const loadHistory = useCallback(async () => {
|
|
||||||
try {
|
|
||||||
const history = await ChatService.listConversations()
|
|
||||||
setConversations(history)
|
|
||||||
} catch (err) {
|
|
||||||
console.error("Failed to load conversation history:", err)
|
|
||||||
}
|
|
||||||
}, [])
|
|
||||||
|
|
||||||
const handleAuthSuccess = useCallback(async () => {
|
const handleAuthSuccess = useCallback(async () => {
|
||||||
try {
|
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"
|
import { AuthService } from "@/services/auth"
|
||||||
|
import { type Theme, ThemeContext } from "./theme-context"
|
||||||
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)
|
|
||||||
|
|
||||||
export function ThemeProvider({
|
export function ThemeProvider({
|
||||||
children,
|
children,
|
||||||
@@ -61,11 +51,3 @@ export function ThemeProvider({
|
|||||||
</ThemeContext.Provider>
|
</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 api from "./api"
|
||||||
import type { Theme } from "@/components/theme-provider"
|
import type { Theme } from "@/components/theme-context"
|
||||||
|
|
||||||
export interface AuthResponse {
|
export interface AuthResponse {
|
||||||
access_token: string
|
access_token: string
|
||||||
|
|||||||
Reference in New Issue
Block a user