PluginProbe
Code Snippets / 3.10.1
Code Snippets v3.10.1
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 3.0.1 All 64 releases
code-snippets / js / components / EditMenu / EditorSidebar / controls / LockControl.tsx

LockControl.tsx in Code Snippets 3.10.1, at js/components/EditMenu/EditorSidebar/controls/LockControl.tsx

48 lines 1.8 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
1 import React from 'react'
2 import classnames from 'classnames'
3 import { __ } from '@wordpress/i18n'
4 import { useSnippetsAPI } from '../../../../hooks/useSnippetsAPI'
5 import { TooltipButton } from '../../../common/TooltipButton'
6 import { useSnippetForm } from '../../SnippetForm/WithSnippetFormContext'
7
8 export const LockControl: React.FC = () => {
9 const { update } = useSnippetsAPI()
10 const { acceptSnippet, snippet, setSnippet, isWorking, setIsWorking, setCurrentNotice } = useSnippetForm()
11
12 const handleToggle = () => {
13 setIsWorking(true)
14 setSnippet(previous => ({ ...previous, locked: !previous.locked }))
15
16 update({ id: snippet.id, network: snippet.network, locked: !snippet.locked })
17 .then(result => {
18 acceptSnippet(result)
19
20 setCurrentNotice(['updated', result.locked
21 ? __('Snippet <strong>locked</strong>.', 'code-snippets')
22 : __('Snippet <strong>unlocked</strong>.', 'code-snippets')])
23 })
24 .catch(() => setCurrentNotice(['error', __('Unable to lock snippet.', 'code-snippets')]))
25 .finally(() => setIsWorking(false))
26 }
27
28 return (
29 <div className={classnames('snippet-lock-control', { 'tooltip tooltip-block tooltip-end': !isWorking })}>
30 <TooltipButton
31 small block end
32 primary={snippet.locked}
33 className="snippet-lock-button"
34 containerClassName="snippet-lock-control"
35 disabled={isWorking}
36 onClick={handleToggle}
37 tooltip={snippet.locked
38 ? __('Unlock this snippet to allow editing and deletion.', 'code-snippets')
39 : __('Mark this snippet as read-only to prevent accidental changes or deletion.', 'code-snippets')}
40 >
41 {snippet.locked
42 ? <span className="dashicons dashicons-unlock" aria-hidden="true" />
43 : <span className="dashicons dashicons-lock" aria-hidden="true" />}
44 </TooltipButton>
45 </div>
46 )
47 }
48