Initial commit: WordPress wp-content (themes, plugins, languages)
- Theme: momentry (custom theme with REST API routes) - Plugins: code-snippets (contains all API proxies) - Languages: zh_TW translations - Excludes: cache, backups, uploads, logs
This commit is contained in:
@@ -0,0 +1,34 @@
|
||||
import { createInterpolateElement } from '@wordpress/element'
|
||||
import React from 'react'
|
||||
import { __, sprintf } from '@wordpress/i18n'
|
||||
import { useSnippetForm } from '../../../hooks/useSnippetForm'
|
||||
import { DismissibleNotice } from '../../common/DismissableNotice'
|
||||
|
||||
export const Notices: React.FC = () => {
|
||||
const { currentNotice, setCurrentNotice, snippet, setSnippet } = useSnippetForm()
|
||||
|
||||
return <>
|
||||
{currentNotice
|
||||
? <DismissibleNotice className={currentNotice[0]} onDismiss={() => setCurrentNotice(undefined)}>
|
||||
<p>{createInterpolateElement(currentNotice[1], { strong: <strong /> })}</p>
|
||||
</DismissibleNotice>
|
||||
: null}
|
||||
|
||||
{snippet.code_error
|
||||
? <DismissibleNotice
|
||||
className="notice-error"
|
||||
onDismiss={() => setSnippet(previous => ({ ...previous, code_error: null }))}
|
||||
>
|
||||
<p>
|
||||
<strong>{sprintf(
|
||||
// translators: %d: line number.
|
||||
__('Snippet automatically deactivated due to an error on line %d:', 'code-snippets'),
|
||||
snippet.code_error[1]
|
||||
)}</strong>
|
||||
|
||||
<blockquote>{snippet.code_error[0]}</blockquote>
|
||||
</p>
|
||||
</DismissibleNotice>
|
||||
: null}
|
||||
</>
|
||||
}
|
||||
@@ -0,0 +1,52 @@
|
||||
import { __, _x } from '@wordpress/i18n'
|
||||
import React from 'react'
|
||||
import { useSnippetForm } from '../../../hooks/useSnippetForm'
|
||||
import { createSnippetObject } from '../../../utils/snippets/snippets'
|
||||
import type { Snippet } from '../../../types/Snippet'
|
||||
|
||||
const OPTIONS = window.CODE_SNIPPETS_EDIT
|
||||
|
||||
const getAddNewHeading = (snippet: Snippet): string =>
|
||||
'condition' === snippet.scope
|
||||
? __('Add New Condition', 'code-snippets')
|
||||
: __('Add New Snippet', 'code-snippets')
|
||||
|
||||
export const PageHeading: React.FC = () => {
|
||||
const { snippet, updateSnippet, setCurrentNotice } = useSnippetForm()
|
||||
|
||||
return (
|
||||
<h1>
|
||||
{snippet.id
|
||||
? <>
|
||||
{`${'condition' === snippet.scope
|
||||
? __('Edit Condition', 'code-snippets')
|
||||
: __('Edit Snippet', 'code-snippets')} `}
|
||||
|
||||
<a
|
||||
href={window.CODE_SNIPPETS?.urls.addNew}
|
||||
className="page-title-action"
|
||||
onClick={event => {
|
||||
event.preventDefault()
|
||||
updateSnippet(({ scope }) => createSnippetObject({ scope }))
|
||||
setCurrentNotice(undefined)
|
||||
|
||||
window.document.title = window.document.title
|
||||
.replace(__('Edit Snippet', 'code-snippets'), getAddNewHeading(snippet))
|
||||
.replace(__('Edit Condition', 'code-snippets'), getAddNewHeading(snippet))
|
||||
|
||||
window.history.pushState({}, '', window.CODE_SNIPPETS?.urls.addNew)
|
||||
}}
|
||||
>
|
||||
{_x('Add New', 'snippet', 'code-snippets')}
|
||||
</a>
|
||||
</>
|
||||
: getAddNewHeading(snippet)}
|
||||
|
||||
{OPTIONS?.pageTitleActions && Object.entries(OPTIONS.pageTitleActions).map(([label, url]) =>
|
||||
<>
|
||||
<a key={label} href={url} className="page-title-action">{label}</a>{' '}
|
||||
</>
|
||||
)}
|
||||
</h1>
|
||||
)
|
||||
}
|
||||
Reference in New Issue
Block a user