File tree Expand file tree Collapse file tree 2 files changed +40
-3
lines changed
apps/mavrochat/src/context
packages/ui/src/components/navigation Expand file tree Collapse file tree 2 files changed +40
-3
lines changed Original file line number Diff line number Diff line change 11'use client' ;
22
3- import { createContext , useContext , useState } from 'react' ;
3+ import { createContext , useContext , useState , useEffect } from 'react' ;
44
55interface ModelContextType {
66 model : string ;
77 setModel : ( model : string ) => void ;
88}
99
1010const DEFAULT_MODEL = 'gpt-4o' ;
11+ const MODEL_STORAGE_KEY = 'mavrochat-selected-model' ;
1112
1213const ModelContext = createContext < ModelContextType | undefined > ( undefined ) ;
1314
1415export function ModelProvider ( { children } : { children : React . ReactNode } ) {
1516 const [ model , setModel ] = useState < string > ( DEFAULT_MODEL ) ;
17+ const [ mounted , setMounted ] = useState ( false ) ;
18+
19+ // Load saved model preference on mount
20+ useEffect ( ( ) => {
21+ setMounted ( true ) ;
22+ try {
23+ const savedModel = localStorage . getItem ( MODEL_STORAGE_KEY ) ;
24+ if ( savedModel ) {
25+ setModel ( savedModel ) ;
26+ }
27+ } catch ( error ) {
28+ console . error ( 'Failed to load saved model:' , error ) ;
29+ }
30+ } , [ ] ) ;
31+
32+ // Save model preference when it changes (only after mounted)
33+ useEffect ( ( ) => {
34+ if ( mounted ) {
35+ try {
36+ localStorage . setItem ( MODEL_STORAGE_KEY , model ) ;
37+ } catch ( error ) {
38+ console . error ( 'Failed to save model preference:' , error ) ;
39+ }
40+ }
41+ } , [ model , mounted ] ) ;
1642
1743 return (
1844 < ModelContext . Provider value = { { model, setModel } } >
Original file line number Diff line number Diff line change @@ -3,6 +3,7 @@ import Link from 'next/link';
33import Image from 'next/image' ;
44import { useTheme } from 'next-themes' ;
55import { Button } from '../form/Button' ;
6+ import { useState , useEffect } from 'react' ;
67
78export function LogoButton ( {
89 className,
@@ -15,8 +16,18 @@ export function LogoButton({
1516 darkLogoSrc : string ;
1617 href ?: string ;
1718} ) {
18- const { theme } = useTheme ( ) ;
19- const logoSrc = theme === 'light' ? lightLogoSrc : darkLogoSrc ;
19+ const { theme, systemTheme } = useTheme ( ) ;
20+ const [ mounted , setMounted ] = useState ( false ) ;
21+
22+ // Avoid hydration mismatch by only rendering theme-specific content after mount
23+ useEffect ( ( ) => {
24+ setMounted ( true ) ;
25+ } , [ ] ) ;
26+
27+ // Use dark logo as default until we know the actual theme
28+ const currentTheme = theme === 'system' ? systemTheme : theme ;
29+ const logoSrc =
30+ mounted && currentTheme === 'light' ? lightLogoSrc : darkLogoSrc ;
2031 const isExternal = href . startsWith ( 'http' ) ;
2132
2233 return (
You can’t perform that action at this time.
0 commit comments