Skip to content

Commit 13d4ed2

Browse files
committed
Add dynamic bottom spacing based on api calls modal height across views
- `packages/ui/src/components/editor/panel/modals/PanelApiCallsModal/PanelApiCallsModal.tsx` should report back its height. The height should be used as dynamic separator at the bottom of home/main scrollable contents.
1 parent d71da1f commit 13d4ed2

6 files changed

Lines changed: 68 additions & 16 deletions

File tree

‎apps/editor/src/views/panel/frontend/Home/Home.tsx‎

Lines changed: 28 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,7 @@ type Props = {
3232
is_setup_complete: boolean
3333
is_connected: boolean
3434
on_donate_click: () => void
35+
bottom_spacer_height?: number
3536
}
3637

3738
export const Home: React.FC<Props> = (props) => {
@@ -246,19 +247,35 @@ export const Home: React.FC<Props> = (props) => {
246247
)}
247248
</div>
248249

249-
<div className={styles.bottom}>
250-
<div className={styles.bottom__links}>
251-
<div>{props.version}</div>
252-
<div>
253-
<Translation
254-
id="home.footer.copyright"
255-
components={{
256-
year: new Date().getFullYear().toString(),
257-
link: <a href="https://x.com/robertpiosik">Robert Piosik</a>
258-
}}
259-
/>
250+
<div
251+
style={{
252+
display: 'flex',
253+
flexDirection: 'column',
254+
width: '100%'
255+
}}
256+
>
257+
<div className={styles.bottom}>
258+
<div className={styles.bottom__links}>
259+
<div>{props.version}</div>
260+
<div>
261+
<Translation
262+
id="home.footer.copyright"
263+
components={{
264+
year: new Date().getFullYear().toString(),
265+
link: (
266+
<a href="https://x.com/robertpiosik">Robert Piosik</a>
267+
)
268+
}}
269+
/>
270+
</div>
260271
</div>
261272
</div>
273+
{props.bottom_spacer_height !== undefined &&
274+
props.bottom_spacer_height > 0 && (
275+
<div
276+
style={{ height: props.bottom_spacer_height, flexShrink: 0 }}
277+
/>
278+
)}
262279
</div>
263280
</div>
264281
</UiScrollable>

‎apps/editor/src/views/panel/frontend/Main/Main.tsx‎

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -84,6 +84,7 @@ type Props = {
8484
missing_web_configuration?: boolean
8585
voice_input_push_to_talk: boolean
8686
token_count: number
87+
bottom_spacer_height?: number
8788
}
8889

8990
export const Main: React.FC<Props> = (props) => {
@@ -648,6 +649,7 @@ export const Main: React.FC<Props> = (props) => {
648649
on_tab_delete={props.on_tab_delete}
649650
on_tabs_reorder={props.on_tabs_reorder}
650651
voice_input_push_to_talk={props.voice_input_push_to_talk}
652+
bottom_spacer_height={props.bottom_spacer_height}
651653
/>
652654
)
653655
}

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

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -118,6 +118,7 @@ type Props = {
118118
on_tab_delete: (index: number) => void
119119
on_tabs_reorder: (new_order: number[]) => void
120120
voice_input_push_to_talk: boolean
121+
bottom_spacer_height?: number
121122
}
122123

123124
const chatbot_to_icon: Record<keyof typeof CHATBOTS, Icon.Variant> = {
@@ -522,6 +523,12 @@ export const MainView: React.FC<Props> = (props) => {
522523
/>
523524
</>
524525
)}
526+
{props.bottom_spacer_height !== undefined &&
527+
props.bottom_spacer_height > 0 && (
528+
<div
529+
style={{ height: props.bottom_spacer_height, flexShrink: 0 }}
530+
/>
531+
)}
525532
</UiScrollable>
526533
</>
527534
)

‎apps/editor/src/views/panel/frontend/Panel.tsx‎

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -150,6 +150,10 @@ export const Panel = () => {
150150
address: string
151151
}>()
152152

153+
const [api_calls_modal_height, set_api_calls_modal_height] = useState(0)
154+
const bottom_spacer_height =
155+
api_calls_modal_height > 0 ? api_calls_modal_height + 16 : 0
156+
153157
const { viewing_donations, set_viewing_donations, ...donations_state } =
154158
use_recent_donations()
155159

@@ -309,6 +313,7 @@ export const Panel = () => {
309313
})}
310314
>
311315
<Main
316+
bottom_spacer_height={bottom_spacer_height}
312317
scroll_reset_key={main_view_scroll_reset_key}
313318
are_keyboard_shortcuts_disabled={
314319
are_keyboard_shortcuts_disabled
@@ -431,6 +436,7 @@ export const Panel = () => {
431436
})}
432437
>
433438
<Home
439+
bottom_spacer_height={bottom_spacer_height}
434440
vscode={vscode}
435441
is_active={active_view == 'home'}
436442
is_connected={is_connected}
@@ -599,6 +605,7 @@ export const Panel = () => {
599605
id
600606
})
601607
}}
608+
on_height_change={set_api_calls_modal_height}
602609
/>
603610
</div>
604611
)}

‎packages/ui/src/components/editor/panel/modals/PanelApiCallsModal/PanelApiCallsModal.module.scss‎

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -7,11 +7,11 @@
77
display: flex;
88
align-items: flex-end;
99
justify-content: flex-end;
10-
padding: 0 12px 48px 8px;
10+
padding: 0 12px 49px 0;
1111
pointer-events: none;
1212

1313
:global([data-modern-ui='true']) & {
14-
padding: 0 10px 38px 8px;
14+
padding: 0 10px 38px 0;
1515
}
1616
}
1717

@@ -38,7 +38,7 @@
3838
border: 1px solid var(--vscode-editorWidget-border);
3939
box-shadow: 0 3px 6px var(--vscode-widget-shadow);
4040
width: 100%;
41-
max-width: min(260px, 70vw);
41+
max-width: min(260px, 60vw);
4242
overflow: hidden;
4343
animation: slideIn var(--transition-duration-250)
4444
var(--transition-timing-function);

‎packages/ui/src/components/editor/panel/modals/PanelApiCallsModal/PanelApiCallsModal.tsx‎

Lines changed: 21 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import { useEffect, useState } from 'react'
1+
import { useEffect, useState, useRef } from 'react'
22
import { Scrollable } from '../../../common/Scrollable'
33
import { use_progress_times } from '../../../../../hooks/use-progress-times'
44
import styles from './PanelApiCallsModal.module.scss'
@@ -14,6 +14,7 @@ type Props = {
1414
reasoning_effort?: string
1515
}[]
1616
on_cancel: (id: string) => void
17+
on_height_change?: (height: number) => void
1718
}
1819

1920
const format_tokens = (tokens: number): string => {
@@ -27,6 +28,24 @@ const format_tokens = (tokens: number): string => {
2728
export const PanelApiCallsModal: React.FC<Props> = (props) => {
2829
const { start_times, now } = use_progress_times(props.progress_items)
2930
const [window_width, set_window_width] = useState(window.innerWidth)
31+
const container_ref = useRef<HTMLDivElement>(null)
32+
33+
useEffect(() => {
34+
if (!props.on_height_change || !container_ref.current) return
35+
36+
const observer = new ResizeObserver((entries) => {
37+
for (const entry of entries) {
38+
props.on_height_change!(entry.target.getBoundingClientRect().height)
39+
}
40+
})
41+
42+
observer.observe(container_ref.current)
43+
44+
return () => {
45+
observer.disconnect()
46+
props.on_height_change?.(0)
47+
}
48+
}, [props.on_height_change])
3049

3150
useEffect(() => {
3251
const handle_resize = () => set_window_width(window.innerWidth)
@@ -45,7 +64,7 @@ export const PanelApiCallsModal: React.FC<Props> = (props) => {
4564
}
4665
}}
4766
>
48-
<div className={styles.container}>
67+
<div className={styles.container} ref={container_ref}>
4968
<Scrollable top_shadow max_height="40vh">
5069
<div className={styles['requests-container']}>
5170
{props.progress_items.map((item) => {

0 commit comments

Comments
 (0)