feat: translate page name when creating new page (#720)
* feat: translate page name when creating new page * Update createPage.ts Co-authored-by: Steve Ruiz <steveruizok@gmail.com>
This commit is contained in:
parent
27e0b8d96e
commit
e8459adc6b
3 changed files with 10 additions and 9 deletions
|
@ -9,7 +9,7 @@ import { DMContent, DMDivider } from '~components/Primitives/DropdownMenu'
|
||||||
import { SmallIcon } from '~components/Primitives/SmallIcon'
|
import { SmallIcon } from '~components/Primitives/SmallIcon'
|
||||||
import { RowButton } from '~components/Primitives/RowButton'
|
import { RowButton } from '~components/Primitives/RowButton'
|
||||||
import { ToolButton } from '~components/Primitives/ToolButton'
|
import { ToolButton } from '~components/Primitives/ToolButton'
|
||||||
import { FormattedMessage } from 'react-intl'
|
import { FormattedMessage, useIntl } from 'react-intl'
|
||||||
|
|
||||||
const sortedSelector = (s: TDSnapshot) =>
|
const sortedSelector = (s: TDSnapshot) =>
|
||||||
Object.values(s.document.pages).sort((a, b) => (a.childIndex || 0) - (b.childIndex || 0))
|
Object.values(s.document.pages).sort((a, b) => (a.childIndex || 0) - (b.childIndex || 0))
|
||||||
|
@ -59,13 +59,14 @@ export function PageMenu() {
|
||||||
|
|
||||||
function PageMenuContent({ onClose }: { onClose: () => void }) {
|
function PageMenuContent({ onClose }: { onClose: () => void }) {
|
||||||
const app = useTldrawApp()
|
const app = useTldrawApp()
|
||||||
|
const intl = useIntl()
|
||||||
|
|
||||||
const sortedPages = app.useStore(sortedSelector)
|
const sortedPages = app.useStore(sortedSelector)
|
||||||
|
|
||||||
const currentPageId = app.useStore(currentPageIdSelector)
|
const currentPageId = app.useStore(currentPageIdSelector)
|
||||||
|
|
||||||
const handleCreatePage = React.useCallback(() => {
|
const handleCreatePage = React.useCallback(() => {
|
||||||
app.createPage()
|
app.createPage(undefined, intl.formatMessage({ id: 'new.page' }))
|
||||||
}, [app])
|
}, [app])
|
||||||
|
|
||||||
const handleChangePage = React.useCallback(
|
const handleChangePage = React.useCallback(
|
||||||
|
|
|
@ -1666,10 +1666,10 @@ export class TldrawApp extends StateManager<TDSnapshot> {
|
||||||
* Create a new page.
|
* Create a new page.
|
||||||
* @param pageId (optional) The new page's id.
|
* @param pageId (optional) The new page's id.
|
||||||
*/
|
*/
|
||||||
createPage = (id?: string): this => {
|
createPage = (id?: string, name?: string): this => {
|
||||||
if (this.readOnly) return this
|
if (this.readOnly) return this
|
||||||
const { width, height } = this.rendererBounds
|
const { width, height } = this.rendererBounds
|
||||||
return this.setState(Commands.createPage(this, [-width / 2, -height / 2], id))
|
return this.setState(Commands.createPage(this, [-width / 2, -height / 2], id, name))
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -1758,7 +1758,7 @@ export class TldrawApp extends StateManager<TDSnapshot> {
|
||||||
e?.preventDefault()
|
e?.preventDefault()
|
||||||
|
|
||||||
this.copy(ids, e)
|
this.copy(ids, e)
|
||||||
|
|
||||||
if (!this.readOnly) {
|
if (!this.readOnly) {
|
||||||
this.delete(ids)
|
this.delete(ids)
|
||||||
}
|
}
|
||||||
|
@ -1772,7 +1772,7 @@ export class TldrawApp extends StateManager<TDSnapshot> {
|
||||||
*/
|
*/
|
||||||
copy = (ids = this.selectedIds, e?: ClipboardEvent): this => {
|
copy = (ids = this.selectedIds, e?: ClipboardEvent): this => {
|
||||||
// Allow when in readOnly mode
|
// Allow when in readOnly mode
|
||||||
|
|
||||||
e?.preventDefault()
|
e?.preventDefault()
|
||||||
|
|
||||||
this.clipboard = this.getClipboard(ids)
|
this.clipboard = this.getClipboard(ids)
|
||||||
|
|
|
@ -5,7 +5,8 @@ import type { TldrawApp } from '~state'
|
||||||
export function createPage(
|
export function createPage(
|
||||||
app: TldrawApp,
|
app: TldrawApp,
|
||||||
center: number[],
|
center: number[],
|
||||||
pageId = Utils.uniqueId()
|
pageId = Utils.uniqueId(),
|
||||||
|
pageName = 'New page'
|
||||||
): TldrawCommand {
|
): TldrawCommand {
|
||||||
const { currentPageId } = app
|
const { currentPageId } = app
|
||||||
|
|
||||||
|
@ -16,11 +17,10 @@ export function createPage(
|
||||||
const nextChildIndex = topPage?.childIndex ? topPage?.childIndex + 1 : 1
|
const nextChildIndex = topPage?.childIndex ? topPage?.childIndex + 1 : 1
|
||||||
|
|
||||||
// TODO: Iterate the name better
|
// TODO: Iterate the name better
|
||||||
const nextName = `New Page`
|
|
||||||
|
|
||||||
const page: TDPage = {
|
const page: TDPage = {
|
||||||
id: pageId,
|
id: pageId,
|
||||||
name: nextName,
|
name: pageName,
|
||||||
childIndex: nextChildIndex,
|
childIndex: nextChildIndex,
|
||||||
shapes: {},
|
shapes: {},
|
||||||
bindings: {},
|
bindings: {},
|
||||||
|
|
Loading…
Reference in a new issue