mirror of
https://git.shipoclu.com/moon/plspace.git
synced 2026-08-14 03:02:31 +00:00
more targeted refresh
This commit is contained in:
@@ -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)
|
||||
})
|
||||
})
|
||||
|
||||
Reference in New Issue
Block a user