Don't allow g keyboard shortcut in readonly mode, show laser tool in the toolbar (#1459)

Disable `g` keyboard shortcut in readonly mode. Show laser tool in
toolbar when in readonly mode.

Resolves [#1936](https://github.com/tldraw/brivate/issues/1936)
Resolves [#1935](https://github.com/tldraw/brivate/issues/1935)

### Change Type

- [x] `patch` — Bug Fix

### Test Plan

1. Open a readonly room.
2. Press `g` and make sure it doesn't switch to it.
3. Laser tool should be visible in the toolbar in readonly rooms.


### Release Notes

- Disable geo tool shortcut in readonly mode. Show laser on the toolbar.

---------

Co-authored-by: Steve Ruiz <steveruizok@gmail.com>
This commit is contained in:
Mitja Bezenšek 2023-05-25 21:08:52 +02:00 committed by GitHub
parent d22542bc55
commit 042edeb4b4
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
5 changed files with 15 additions and 2 deletions

View file

@ -81,6 +81,7 @@ export async function sleep(ms: number) {
export async function clearClipboard() { export async function clearClipboard() {
return await browser.execute(async () => { return await browser.execute(async () => {
if (!(navigator && navigator.clipboard)) return
if (navigator.clipboard.write) { if (navigator.clipboard.write) {
await navigator.clipboard.write([ await navigator.clipboard.write([
new ClipboardItem({ new ClipboardItem({

View file

@ -28,6 +28,7 @@ export const Toolbar = function Toolbar() {
const isReadOnly = useReadonly() const isReadOnly = useReadonly()
const toolbarItems = useToolbarSchema() const toolbarItems = useToolbarSchema()
const laserTool = toolbarItems.find((item) => item.toolItem.id === 'laser')
const activeToolId = useValue('current tool id', () => app.currentToolId, [app]) const activeToolId = useValue('current tool id', () => app.currentToolId, [app])
@ -142,6 +143,14 @@ export const Toolbar = function Toolbar() {
/> />
) )
})} })}
{isReadOnly && laserTool && (
<ToolbarButton
key={laserTool.toolItem.id}
item={laserTool.toolItem}
title={getTitle(laserTool.toolItem)}
isSelected={isActiveToolItem(laserTool.toolItem, activeToolId, geoState)}
/>
)}
{showEditingTools && ( {showEditingTools && (
<> <>
{/* Draw / Eraser */} {/* Draw / Eraser */}

View file

@ -479,7 +479,9 @@ async function handleClipboardThings(app: App, things: ClipboardThing[], point?:
const handleNativeOrMenuCopy = (app: App) => { const handleNativeOrMenuCopy = (app: App) => {
const content = app.getContent() const content = app.getContent()
if (!content) { if (!content) {
window.navigator.clipboard.writeText('') if (navigator && navigator.clipboard) {
navigator.clipboard.writeText('')
}
return return
} }

View file

@ -144,5 +144,6 @@ async function getExportedImageBlob(app: App, ids: TLShapeId[], format: 'png' |
} }
async function fallbackWriteTextAsync(getText: () => Promise<string>) { async function fallbackWriteTextAsync(getText: () => Promise<string>) {
if (!(navigator && navigator.clipboard)) return
navigator.clipboard.writeText(await getText()) navigator.clipboard.writeText(await getText())
} }

View file

@ -66,7 +66,7 @@ export function useKeyboardShortcuts() {
// todo: move these into the actions themselves and make the UI only display the first one // todo: move these into the actions themselves and make the UI only display the first one
hot('g', () => { hot('g', () => {
if (areShortcutsDisabled()) return if (areShortcutsDisabled() || app.isReadOnly) return
app.setSelectedTool('geo') app.setSelectedTool('geo')
}) })