PluginProbe
Code Snippets / 3.10.1
Code Snippets v3.10.1
4.0.0-beta.2 3.10.2 3.10.1 3.10.0 3.10.0-beta.2 3.10.0-beta.1 4.0.0-beta.1 3.9.6 trunk 2.10.0 2.10.1 2.12.0 2.12.1 2.13.0 2.13.1 2.13.2 2.13.3 2.14.0 2.14.1 2.14.2 2.14.3 2.14.4 2.14.5 2.14.6 3.0.0 All 65 releases
code-snippets / js / components / SnippetForm / page / PageHeading.tsx

PageHeading.tsx in Code Snippets 3.10.1, at js/components/SnippetForm/page/PageHeading.tsx

53 lines 1.6 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
1 import { __, _x } from '@wordpress/i18n'
2 import React from 'react'
3 import { useSnippetForm } from '../../../hooks/useSnippetForm'
4 import { createSnippetObject } from '../../../utils/snippets/snippets'
5 import type { Snippet } from '../../../types/Snippet'
6
7 const OPTIONS = window.CODE_SNIPPETS_EDIT
8
9 const getAddNewHeading = (snippet: Snippet): string =>
10 'condition' === snippet.scope
11 ? __('Add New Condition', 'code-snippets')
12 : __('Add New Snippet', 'code-snippets')
13
14 export const PageHeading: React.FC = () => {
15 const { snippet, updateSnippet, setCurrentNotice } = useSnippetForm()
16
17 return (
18 <h1>
19 {snippet.id
20 ? <>
21 {`${'condition' === snippet.scope
22 ? __('Edit Condition', 'code-snippets')
23 : __('Edit Snippet', 'code-snippets')} `}
24
25 <a
26 href={window.CODE_SNIPPETS?.urls.addNew}
27 className="page-title-action"
28 onClick={event => {
29 event.preventDefault()
30 updateSnippet(({ scope }) => createSnippetObject({ scope }))
31 setCurrentNotice(undefined)
32
33 window.document.title = window.document.title
34 .replace(__('Edit Snippet', 'code-snippets'), getAddNewHeading(snippet))
35 .replace(__('Edit Condition', 'code-snippets'), getAddNewHeading(snippet))
36
37 window.history.pushState({}, '', window.CODE_SNIPPETS?.urls.addNew)
38 }}
39 >
40 {_x('Add New', 'snippet', 'code-snippets')}
41 </a>
42 </>
43 : getAddNewHeading(snippet)}
44
45 {OPTIONS?.pageTitleActions && Object.entries(OPTIONS.pageTitleActions).map(([label, url]) =>
46 <>
47 <a key={label} href={url} className="page-title-action">{label}</a>{' '}
48 </>
49 )}
50 </h1>
51 )
52 }
53