more targeted refresh

This commit is contained in:
Moon.eth
2026-07-29 12:51:33 +09:00
parent 4f682857ac
commit a42145c678
11 changed files with 229 additions and 4 deletions
+4 -3
View File
@@ -6,7 +6,8 @@
* navigating, and editable controls are ignored so composing text is safe.
*/
interface Props {
onrefresh?: () => void
/** Returning false means this page has no refreshable timeline. */
onrefresh?: () => void | boolean
}
let { onrefresh = () => window.location.reload() }: Props = $props()
@@ -35,8 +36,8 @@
return
}
event.preventDefault()
onrefresh()
const handled = onrefresh()
if (handled !== false) event.preventDefault()
}
</script>
@@ -33,4 +33,18 @@ describe('RefreshHotkey', () => {
expect(onrefresh).not.toHaveBeenCalled()
})
it('leaves the shortcut unclaimed when the page has no timeline', () => {
render(RefreshHotkey, { props: { onrefresh: () => false } })
const event = new KeyboardEvent('keydown', {
key: 'R',
shiftKey: true,
bubbles: true,
cancelable: true,
})
window.dispatchEvent(event)
expect(event.defaultPrevented).toBe(false)
})
})