Skip to content

Commit c6ab40a

Browse files
committed
Track content scrollability to adjust header layout in landscape mode
- if inner content height of 'main view content' is less than the 'main view content' (scrollbar is not appearing), Header should receive a prop 'is conotent scrollable':false - move [Changes] to a hook - if content is scrollable and is_browser_connection_status_bar_closed: false, should add 6px separator above 'edit/ask' buttons - if inner content height of 'main view content' is less than the 'main view content' (scrollbar is not appearing), Header should receive a prop 'is content scrollable':false ├── apps │ └── editor │ └── src │ └── views │ └── prompt │ └── frontend │ └── Main │ └── MainView │ ├── MainView.module.scss │ ├── MainView.tsx │ ├── components │ │ └── Header │ │ ├── Header.module.scss │ │ ├── Header.tsx │ │ └── index.ts │ └── hooks │ ├── use-browser-connection-status.ts │ ├── use-invocation-counts.ts │ ├── use-keyboard-shortcuts.ts │ ├── use-last-choice-tooltip.ts │ └── use-re-render-on-interval.ts └── packages └── ui └── src └── components └── editor └── common └── Scrollable └── Scrollable.tsx
1 parent 529f7fa commit c6ab40a

3 files changed

Lines changed: 64 additions & 19 deletions

File tree

‎apps/editor/src/views/prompt/frontend/Main/MainView/MainView.tsx‎

Lines changed: 13 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
import { useState } from 'react'
12
import styles from './MainView.module.scss'
23
import { Configurations as UiConfigurations } from '@ui/components/editor/prompt/Configurations'
34
import { PromptField as UiPromptField } from '@ui/components/editor/common/prompts/PromptField'
@@ -155,6 +156,7 @@ const chatbot_to_icon: Record<keyof typeof CHATBOTS, Icon.Variant> = {
155156
export const MainView: React.FC<Props> = (props) => {
156157
const { t } = use_translation()
157158
const is_landscape = use_is_landscape()
159+
const [is_content_scrollable, set_is_content_scrollable] = useState(false)
158160

159161
const show_edit_format_selector =
160162
(props.target == TARGET.WEB && props.web_prompt_type == 'edit-files') ||
@@ -273,6 +275,7 @@ export const MainView: React.FC<Props> = (props) => {
273275
is_alt_pressed={is_alt_pressed}
274276
is_landscape={is_landscape}
275277
is_browser_connection_status_bar_closed={browser_connection.is_closed}
278+
is_content_scrollable={is_content_scrollable}
276279
/>
277280
)
278281

@@ -576,7 +579,11 @@ export const MainView: React.FC<Props> = (props) => {
576579
<div
577580
className={`${styles.landscape__column} ${styles['landscape__column--prompt']}`}
578581
>
579-
<UiScrollable scroll_to_top_key={props.scroll_reset_key} top_shadow>
582+
<UiScrollable
583+
scroll_to_top_key={props.scroll_reset_key}
584+
top_shadow
585+
on_scrollable_change={set_is_content_scrollable}
586+
>
580587
<div className={styles.content}>{prompt_section}</div>
581588
</UiScrollable>
582589
</div>
@@ -606,7 +613,11 @@ export const MainView: React.FC<Props> = (props) => {
606613
return (
607614
<>
608615
{header}
609-
<UiScrollable scroll_to_top_key={props.scroll_reset_key} top_shadow>
616+
<UiScrollable
617+
scroll_to_top_key={props.scroll_reset_key}
618+
top_shadow
619+
on_scrollable_change={set_is_content_scrollable}
620+
>
610621
<div className={styles.content}>
611622
{prompt_section}
612623

‎apps/editor/src/views/prompt/frontend/Main/MainView/components/Header/Header.tsx‎

Lines changed: 48 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@ import {
1111
} from '../../prompt-type-labels'
1212
import { use_translation } from '@/views/prompt/frontend/i18n/use-translation'
1313
import { StatusBar as UiStatusBar } from '@ui/components/editor/prompt/StatusBar'
14+
import { Separator as UiSeparator } from '@ui/components/editor/prompt/Separator'
1415

1516
type Props = {
1617
target: Target
@@ -22,6 +23,7 @@ type Props = {
2223
is_alt_pressed: boolean
2324
is_landscape: boolean
2425
is_browser_connection_status_bar_closed: boolean
26+
is_content_scrollable: boolean
2527
}
2628

2729
export const Header: React.FC<Props> = (props) => {
@@ -31,7 +33,11 @@ export const Header: React.FC<Props> = (props) => {
3133
})
3234

3335
return (
34-
<div className={styles.header} ref={container_ref}>
36+
<div
37+
className={styles.header}
38+
ref={container_ref}
39+
data-is-content-scrollable={props.is_content_scrollable}
40+
>
3541
<div className={styles.header__left}>
3642
<div className={styles.header__back}>
3743
<UiIconButton
@@ -42,6 +48,34 @@ export const Header: React.FC<Props> = (props) => {
4248
</div>
4349

4450
<div className={styles.header__types}>
51+
{props.is_landscape &&
52+
!props.is_browser_connection_status_bar_closed &&
53+
!props.is_content_scrollable && (
54+
<>
55+
<div
56+
style={{
57+
visibility: 'hidden',
58+
pointerEvents: 'none',
59+
width: 0
60+
}}
61+
>
62+
<UiStatusBar
63+
icon="codicon-debug-disconnect"
64+
label=""
65+
actions={[
66+
{
67+
id: 'install',
68+
icon: 'codicon-add',
69+
label: '',
70+
title: '',
71+
on_click: () => {}
72+
}
73+
]}
74+
/>
75+
<UiSeparator height={6} />
76+
</div>
77+
</>
78+
)}
4579
{props.target == TARGET.WEB && (
4680
<>
4781
<div className={styles.header__types__inner}>
@@ -102,21 +136,19 @@ export const Header: React.FC<Props> = (props) => {
102136
width: 0
103137
}}
104138
>
105-
{props.is_browser_connection_status_bar_closed && (
106-
<UiStatusBar
107-
icon="codicon-debug-disconnect"
108-
label=""
109-
actions={[
110-
{
111-
id: 'install',
112-
icon: 'codicon-add',
113-
label: '',
114-
title: '',
115-
on_click: () => {}
116-
}
117-
]}
118-
/>
119-
)}
139+
<UiStatusBar
140+
icon="codicon-debug-disconnect"
141+
label=""
142+
actions={[
143+
{
144+
id: 'install',
145+
icon: 'codicon-add',
146+
label: '',
147+
title: '',
148+
on_click: () => {}
149+
}
150+
]}
151+
/>
120152
</div>
121153
)}
122154
</div>

‎packages/ui/src/components/editor/common/Scrollable/Scrollable.tsx‎

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@ type Props = {
1717
initial_scroll_top?: number
1818
on_scroll?: (top: number) => void
1919
on_scrolled_change?: (is_scrolled: boolean) => void
20+
on_scrollable_change?: (is_scrollable: boolean) => void
2021
scroll_trigger?: number
2122
top_shadow?: boolean
2223
bottom_shadow?: boolean
@@ -58,6 +59,7 @@ export const Scrollable = forwardRef<any, Props>((props, ref) => {
5859
set_has_bottom_shadow(is_scrollable && !is_scrolled_bottom)
5960
if (props.on_scroll) props.on_scroll(scrollTop)
6061
if (props.on_scrolled_change) props.on_scrolled_change(is_scrolled)
62+
if (props.on_scrollable_change) props.on_scrollable_change(is_scrollable)
6163
}
6264

6365
update()
@@ -74,7 +76,7 @@ export const Scrollable = forwardRef<any, Props>((props, ref) => {
7476
scroll_element.removeEventListener('scroll', update)
7577
resize_observer.disconnect()
7678
}
77-
}, [props.on_scroll, props.on_scrolled_change])
79+
}, [props.on_scroll, props.on_scrolled_change, props.on_scrollable_change])
7880

7981
useEffect(() => {
8082
const simplebar_instance = simplebar_ref.current

0 commit comments

Comments
 (0)