Skip to content

Commit

Permalink
chore: absorb hotkey save event when no changes present
Browse files Browse the repository at this point in the history
  • Loading branch information
JessChowdhury committed May 20, 2024
1 parent 0e9bbec commit f5ea733
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 3 deletions.
5 changes: 3 additions & 2 deletions packages/ui/src/elements/Save/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,6 @@ import { useHotkey } from '../../hooks/useHotkey.js'
import { useEditDepth } from '../../providers/EditDepth/index.js'
import { useOperation } from '../../providers/Operation/index.js'
import { useTranslation } from '../../providers/Translation/index.js'

export const DefaultSaveButton: React.FC<{ label?: string }> = ({ label: labelProp }) => {
const { t } = useTranslation()
const { submit } = useForm()
Expand All @@ -21,7 +20,9 @@ export const DefaultSaveButton: React.FC<{ label?: string }> = ({ label: labelPr
const forceDisable = operation === 'update' && !modified

useHotkey({ cmdCtrlKey: true, editDepth, keyCodes: ['s'] }, (e) => {
if (forceDisable) return
if (forceDisable) {
// absorb the event
}

e.preventDefault()
e.stopPropagation()
Expand Down
4 changes: 3 additions & 1 deletion packages/ui/src/elements/SaveDraft/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,9 @@ const DefaultSaveDraftButton: React.FC = () => {
}, [submit, collectionSlug, globalSlug, serverURL, api, locale, id, forceDisable])

useHotkey({ cmdCtrlKey: true, editDepth, keyCodes: ['s'] }, (e) => {
if (forceDisable) return
if (forceDisable) {
// absorb the event
}

e.preventDefault()
e.stopPropagation()
Expand Down

0 comments on commit f5ea733

Please sign in to comment.