Add a toast for missing clipboard permissions. (#4117)
Shows a toast notifying the user that pasting failed due to clipboard permissions. Resolves https://github.com/orgs/tldraw/projects/53?pane=issue&itemId=70294454 ![image](https://github.com/tldraw/tldraw/assets/2523721/704aaca2-a087-4b5b-a0bc-dd710960a318) ### Change type - [ ] `bugfix` - [x] `improvement` - [ ] `feature` - [ ] `api` - [ ] `other` ### Test plan 1. Open a new private window. 2. Copy some shapes and paste them. Make sure you don't allow the clipboard access. 3. You should see the toast. ### Release notes - Show a toast when pasting failed due to missing clipboard permissions.
This commit is contained in:
parent
9a3afa2e2a
commit
ec0ec71c69
5 changed files with 26 additions and 9 deletions
|
@ -59,6 +59,8 @@
|
||||||
"action.open-file": "Open file",
|
"action.open-file": "Open file",
|
||||||
"action.pack": "Pack",
|
"action.pack": "Pack",
|
||||||
"action.paste": "Paste",
|
"action.paste": "Paste",
|
||||||
|
"action.paste-error-title": "Pasting failed",
|
||||||
|
"action.paste-error-description": "Could not paste due to missing clipboard permissions. Please enable the permissions and try again.",
|
||||||
"action.print": "Print",
|
"action.print": "Print",
|
||||||
"action.redo": "Redo",
|
"action.redo": "Redo",
|
||||||
"action.remove-frame": "Remove frame",
|
"action.remove-frame": "Remove frame",
|
||||||
|
|
File diff suppressed because one or more lines are too long
|
@ -86,7 +86,7 @@ export function ActionsProvider({ overrides, children }: ActionsProviderProps) {
|
||||||
const editor = useEditor()
|
const editor = useEditor()
|
||||||
|
|
||||||
const { addDialog, clearDialogs } = useDialogs()
|
const { addDialog, clearDialogs } = useDialogs()
|
||||||
const { clearToasts } = useToasts()
|
const { clearToasts, addToast } = useToasts()
|
||||||
const msg = useTranslation()
|
const msg = useTranslation()
|
||||||
|
|
||||||
const insertMedia = useInsertMedia()
|
const insertMedia = useInsertMedia()
|
||||||
|
@ -944,13 +944,22 @@ export function ActionsProvider({ overrides, children }: ActionsProviderProps) {
|
||||||
label: 'action.paste',
|
label: 'action.paste',
|
||||||
kbd: '$v',
|
kbd: '$v',
|
||||||
onSelect(source) {
|
onSelect(source) {
|
||||||
navigator.clipboard?.read().then((clipboardItems) => {
|
navigator.clipboard
|
||||||
paste(
|
?.read()
|
||||||
clipboardItems,
|
.then((clipboardItems) => {
|
||||||
source,
|
paste(
|
||||||
source === 'context-menu' ? editor.inputs.currentPagePoint : undefined
|
clipboardItems,
|
||||||
)
|
source,
|
||||||
})
|
source === 'context-menu' ? editor.inputs.currentPagePoint : undefined
|
||||||
|
)
|
||||||
|
})
|
||||||
|
.catch(() => {
|
||||||
|
addToast({
|
||||||
|
title: msg('action.paste-error-title'),
|
||||||
|
description: msg('action.paste-error-description'),
|
||||||
|
severity: 'error',
|
||||||
|
})
|
||||||
|
})
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
|
@ -1427,6 +1436,7 @@ export function ActionsProvider({ overrides, children }: ActionsProviderProps) {
|
||||||
trackEvent,
|
trackEvent,
|
||||||
overrides,
|
overrides,
|
||||||
addDialog,
|
addDialog,
|
||||||
|
addToast,
|
||||||
insertMedia,
|
insertMedia,
|
||||||
exportAs,
|
exportAs,
|
||||||
copyAs,
|
copyAs,
|
||||||
|
|
|
@ -63,6 +63,8 @@ export type TLUiTranslationKey =
|
||||||
| 'action.open-file'
|
| 'action.open-file'
|
||||||
| 'action.pack'
|
| 'action.pack'
|
||||||
| 'action.paste'
|
| 'action.paste'
|
||||||
|
| 'action.paste-error-title'
|
||||||
|
| 'action.paste-error-description'
|
||||||
| 'action.print'
|
| 'action.print'
|
||||||
| 'action.redo'
|
| 'action.redo'
|
||||||
| 'action.remove-frame'
|
| 'action.remove-frame'
|
||||||
|
|
|
@ -63,6 +63,9 @@ export const DEFAULT_TRANSLATION = {
|
||||||
'action.open-file': 'Open file',
|
'action.open-file': 'Open file',
|
||||||
'action.pack': 'Pack',
|
'action.pack': 'Pack',
|
||||||
'action.paste': 'Paste',
|
'action.paste': 'Paste',
|
||||||
|
'action.paste-error-title': 'Pasting failed',
|
||||||
|
'action.paste-error-description':
|
||||||
|
'Could not paste due to missing clipboard permissions. Please enable the permissions and try again.',
|
||||||
'action.print': 'Print',
|
'action.print': 'Print',
|
||||||
'action.redo': 'Redo',
|
'action.redo': 'Redo',
|
||||||
'action.remove-frame': 'Remove frame',
|
'action.remove-frame': 'Remove frame',
|
||||||
|
|
Loading…
Reference in a new issue