Skip to content

Commit

Permalink
add keyboard listener
Browse files Browse the repository at this point in the history
  • Loading branch information
mfix22 committed May 14, 2022
1 parent 27108aa commit 7557b55
Show file tree
Hide file tree
Showing 2 changed files with 31 additions and 15 deletions.
40 changes: 25 additions & 15 deletions components/SnippetToolbar.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import React from 'react'
import { useAsyncCallback, useOnline } from 'actionsack'
import { useAsyncCallback, useOnline, useKeyboardListener } from 'actionsack'

import Button from './Button'
import Toolbar from './Toolbar'
Expand Down Expand Up @@ -51,6 +51,29 @@ function DuplicateButton(props) {
)
}

function SaveButton({ loading, onClick }) {
useKeyboardListener('⌥-s', e => {
e.preventDefault()
onClick()
})

return (
<Button
border
large
center
color={COLORS.GREEN}
onClick={onClick}
data-cy="save-button"
style={{ minWidth: 84, borderBottomRightRadius: 0, borderTopRightRadius: 0 }}
title="Save"
disabled={loading}
>
{loading ? 'Saving…' : 'Save'}
</Button>
)
}

function SnippetToolbar({
toggleVisibility,
isVisible,
Expand Down Expand Up @@ -108,21 +131,8 @@ function SnippetToolbar({
}}
>
<div className="flex">
<SaveButton loading={loading} onClick={saveSnippet} />
<Button
border
large
center
color={COLORS.GREEN}
onClick={saveSnippet}
data-cy="save-button"
style={{ minWidth: 84, borderBottomRightRadius: 0, borderTopRightRadius: 0 }}
title="Save"
disabled={loading}
>
{loading ? 'Saving…' : 'Save'}
</Button>
<Button
id="save-menu"
title="Save menu dropdown"
border
large
Expand Down
6 changes: 6 additions & 0 deletions pages/about.js
Original file line number Diff line number Diff line change
Expand Up @@ -144,6 +144,12 @@ export default function About() {
<kbd>⇧ ⌘ S</kbd>
</td>
</tr>
<tr>
<td>Save snippet</td>
<td>
<kbd>⌥ S</kbd>
</td>
</tr>
<tr>
<td>Copy image to clipboard</td>
<td>
Expand Down

0 comments on commit 7557b55

Please sign in to comment.