1- import { useState , useEffect , useRef , useCallback } from 'react'
1+ import { useRef , useCallback } from 'react'
22import cn from 'classnames'
33import { MODE , Mode } from '@/views/panel/types/main-view-mode'
44import { use_is_narrow_viewport , use_is_mac } from '@shared/hooks'
@@ -21,13 +21,11 @@ type Props = {
2121}
2222
2323export const Header : React . FC < Props > = ( props ) => {
24- const [ dropdown_max_width , set_dropdown_max_width ] = useState <
25- number | undefined
26- > ( undefined )
2724 const header_ref = useRef < HTMLDivElement > ( null )
2825 const is_narrow_viewport = use_is_narrow_viewport ( 294 )
2926 const is_mac = use_is_mac ( )
3027 const header_left_ref = useRef < HTMLDivElement > ( null )
28+ const dropdown_container_ref = useRef < HTMLDivElement > ( null )
3129
3230 const handle_heading_click = useCallback ( ( ) => {
3331 if ( props . mode == MODE . WEB ) {
@@ -41,36 +39,10 @@ export const Header: React.FC<Props> = (props) => {
4139 mode : props . mode ,
4240 handle_heading_click,
4341 on_web_prompt_type_change : props . on_web_prompt_type_change ,
44- on_api_prompt_type_change : props . on_api_prompt_type_change
42+ on_api_prompt_type_change : props . on_api_prompt_type_change ,
43+ on_show_home : props . on_show_home
4544 } )
4645
47- const calculate_dropdown_max_width = ( ) => {
48- if ( ! header_ref . current || ! header_left_ref . current ) return
49-
50- const header_width = header_ref . current . offsetWidth
51- const header_left_width = header_left_ref . current . offsetWidth
52- // header_width - left_width - (header padding) 24 - (gap between left/right) 12 - (gap in right) 8 - (settings button) 20
53- const calculated_width = header_width - header_left_width - 64
54- set_dropdown_max_width ( calculated_width )
55- }
56-
57- useEffect ( ( ) => {
58- if ( ! header_ref . current || ! header_left_ref . current ) return
59-
60- const resize_observer = new ResizeObserver ( ( ) => {
61- calculate_dropdown_max_width ( )
62- } )
63-
64- resize_observer . observe ( header_ref . current )
65- resize_observer . observe ( header_left_ref . current )
66-
67- calculate_dropdown_max_width ( )
68-
69- return ( ) => {
70- resize_observer . disconnect ( )
71- }
72- } , [ ] )
73-
7446 return (
7547 < div className = { styles . header } ref = { header_ref } >
7648 < div className = { styles . header__left } ref = { header_left_ref } >
@@ -82,14 +54,17 @@ export const Header: React.FC<Props> = (props) => {
8254 < button
8355 className = { styles [ 'header__left__toggler' ] }
8456 onClick = { handle_heading_click }
85- title = { `Change mode (${ is_mac ? '⌘ Esc' : 'Ctrl+Esc' } )` }
57+ title = { `Change mode (${ is_mac ? '⌘Esc' : 'Ctrl+Esc' } )` }
8658 >
8759 { props . mode == MODE . WEB ? MODE . WEB : MODE . API }
8860 </ button >
8961 </ div >
9062
9163 < div className = { styles . header__right } >
92- < div className = { styles . header__right__dropdown } >
64+ < div
65+ className = { styles . header__right__dropdown }
66+ ref = { dropdown_container_ref }
67+ >
9368 { props . mode == MODE . WEB && (
9469 < UiDropdown
9570 options = { Object . entries ( web_mode_labels ) . map (
@@ -101,7 +76,6 @@ export const Header: React.FC<Props> = (props) => {
10176 ) }
10277 selected_value = { props . web_prompt_type }
10378 on_change = { props . on_web_prompt_type_change }
104- max_width = { dropdown_max_width }
10579 menu_max_width = "calc(100vw - 52px)"
10680 info = { is_narrow_viewport ? undefined : 'prompt type' }
10781 title = {
@@ -122,7 +96,6 @@ export const Header: React.FC<Props> = (props) => {
12296 ) }
12397 selected_value = { props . api_prompt_type }
12498 on_change = { props . on_api_prompt_type_change }
125- max_width = { dropdown_max_width }
12699 menu_max_width = "calc(100vw - 60px)"
127100 info = { is_narrow_viewport ? undefined : 'prompt type' }
128101 title = {
0 commit comments