fix: error clicking outside edit-comment dialog
Massimo Melina committed
Nov 5, 2024 at 18:02 UTC
8cfe0be55c38cd8587d8fd55503f10936fadc82f
2 files changed
+7
-9
frontend/src/fileMenu.ts
+1
-1
@@ -164,7 +164,7 @@ async function rename(entry: DirEntry) {
164
165
async function editComment(entry: DirEntry) {
166
const res = await inputComment(entry.name, entry.comment)
167
- if (res === null) return
167
+ if (res === undefined) return
168
await apiCall('comment', { uri: entry.uri, comment: res }, { modal: working })
169
updateEntry(entry, e => e.comment = res)
170
toast(t`Operation successful`, 'success')
shared/dialogs.ts
+6
-8
@@ -108,7 +108,7 @@ export function Dialogs(props: HTMLAttributes<HTMLDivElement>) {
108
}
109
110
function Dialog(d: DialogOptions) {
111
- const ref = useRef<HTMLElement>()
111
+ const ref = useRef<HTMLElement>(null)
112
const [shiftY, setShiftY] = useState(0)
113
useEffect(()=>{
114
const el = ref.current?.querySelector('.dialog') as HTMLElement | undefined
@@ -124,7 +124,11 @@ function Dialog(d: DialogOptions) {
124
return h('div', {
125
ref,
126
className: 'dialog-backdrop '+(d.className||''),
127
- onKeyDown,
127
+ onKeyDown(ev) {
128
+ if (ev.key === 'Escape')
129
+ closeDialog()
130
+ ev.stopPropagation()
131
+ },
132
onClick: (ev: any) => d.closable
133
&& ev.target === ev.currentTarget // this test will tell us if really the backdrop was clicked
134
&& closeDialog()
@@ -173,12 +177,6 @@ export function componentOrNode(x: ReactNode | FunctionComponent) {
177
return isPrimitive(x) || isValidElement(x) ? x : h(x as any)
178
}
179
176
-function onKeyDown(ev:any) {
177
- if (ev.key === 'Escape')
178
- closeDialog()
179
- ev.stopPropagation()
180
-}
181
-
180
export function newDialog(options: DialogOptions) {
181
const $id = Math.random()
182
const ts = performance.now()