Skip to content

Commit 1c85b47

Browse files
committed
Improve auto-closing modal animation handling and focus chat input on close
- once autoclosing modal closes, should focus the prompt field - when 'auto closing modal' is closed by clicking on the button, triggering it again breaks the auto-closing timer so it never closes
1 parent cd76f33 commit 1c85b47

2 files changed

Lines changed: 17 additions & 5 deletions

File tree

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

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -808,7 +808,10 @@ export const Panel = () => {
808808
title={auto_closing_modal_data.title}
809809
type={auto_closing_modal_data.type}
810810
duration={3000}
811-
on_close={() => set_auto_closing_modal_data(undefined)}
811+
on_close={() => {
812+
set_auto_closing_modal_data(undefined)
813+
set_chat_input_focus_key((k) => k + 1)
814+
}}
812815
non_dismissable={auto_closing_modal_data.non_dismissable}
813816
/>
814817
</div>

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

Lines changed: 13 additions & 4 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 styles from './AutoClosingModal.module.scss'
33
import { Button } from '../../../common/Button'
44
import { Modal, ModalIconType } from '../Modal'
@@ -13,17 +13,26 @@ type Props = {
1313

1414
export const AutoClosingModal: React.FC<Props> = (props) => {
1515
const [is_filling, set_is_filling] = useState(false)
16+
const on_close_ref = useRef(props.on_close)
1617

1718
useEffect(() => {
18-
set_is_filling(true)
19+
on_close_ref.current = props.on_close
20+
}, [props.on_close])
21+
22+
useEffect(() => {
23+
const frame = requestAnimationFrame(() => {
24+
set_is_filling(true)
25+
})
26+
1927
const timeout = setTimeout(() => {
20-
props.on_close()
28+
on_close_ref.current()
2129
}, props.duration)
2230

2331
return () => {
32+
cancelAnimationFrame(frame)
2433
clearTimeout(timeout)
2534
}
26-
}, [])
35+
}, [props.duration])
2736

2837
return (
2938
<div

0 commit comments

Comments
 (0)