PluginProbe
Code Snippets / 3.10.2
Code Snippets v3.10.2
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 / EditMenu / SnippetForm / page / PageHeading.tsx

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

67 lines 1.9 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 '../WithSnippetFormContext'
4 import { createSnippetObject, isCondition } 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 isCondition(snippet)
11 ? __('Add New Condition', 'code-snippets')
12 : __('Create New Snippet', 'code-snippets')
13
14 const getPageHeading = (snippet: Snippet): string => {
15 if (isCondition(snippet)) {
16 return snippet.locked
17 ? __('View Condition', 'code-snippets')
18 : __('Edit Condition', 'code-snippets')
19 }
20
21 return snippet.locked
22 ? __('View Snippet', 'code-snippets')
23 : __('Edit Snippet', 'code-snippets')
24 }
25
26 export const PageHeading: React.FC = () => {
27 const { snippet, updateSnippet, setCurrentNotice } = useSnippetForm()
28
29 return (
30 <>
31 <h1>
32 {snippet.id
33 ? <>
34 {`${getPageHeading(snippet)} `}
35
36 <a
37 href={window.CODE_SNIPPETS?.urls.addNew}
38 className="page-title-action"
39 onClick={event => {
40 event.preventDefault()
41 updateSnippet(({ scope }) => createSnippetObject({ scope }))
42 setCurrentNotice(undefined)
43
44 window.document.title = window.document.title
45 .replace(__('Edit Snippet', 'code-snippets'), getAddNewHeading(snippet))
46 .replace(__('Edit Condition', 'code-snippets'), getAddNewHeading(snippet))
47
48 window.history.pushState({}, '', window.CODE_SNIPPETS?.urls.addNew)
49 }}
50 >
51 {_x('Add New', 'snippet', 'code-snippets')}
52 </a>
53 </>
54 : getAddNewHeading(snippet)}
55
56 {OPTIONS?.pageTitleActions && Object.entries(OPTIONS.pageTitleActions).map(([label, url]) =>
57 <>
58 <a key={label} href={url} className="page-title-action">{label}</a>{' '}
59 </>
60 )}
61 </h1>
62
63 <hr className="wp-header-end" />
64 </>
65 )
66 }
67