PluginProbe
Code Snippets / 3.9.6
Code Snippets v3.9.6
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 / Import / ImportApp.tsx

ImportApp.tsx in Code Snippets 3.9.6, at js/components/Import/ImportApp.tsx

63 lines 1.6 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
1 import React, { useState, useEffect } from 'react'
2 import { __ } from '@wordpress/i18n'
3 import { FileUploadForm } from './FromFileUpload/FileUploadForm'
4 import { ImportForm } from './FromOtherPlugins/ImportForm'
5 import { ImportSection } from './shared'
6
7 type TabType = 'upload' | 'plugins'
8
9 export const ImportApp: React.FC = () => {
10 const [activeTab, setActiveTab] = useState<TabType>('upload')
11
12 useEffect(() => {
13 const urlParams = new URLSearchParams(window.location.search)
14 const tabParam = urlParams.get('tab') as TabType
15 if (tabParam === 'plugins' || tabParam === 'upload') {
16 setActiveTab(tabParam)
17 }
18 }, [])
19
20 const handleTabChange = (tab: TabType) => {
21 setActiveTab(tab)
22
23 const url = new URL(window.location.href)
24 url.searchParams.set('tab', tab)
25 window.history.replaceState({}, '', url)
26 }
27
28 return (
29 <div className="narrow" style={{ maxWidth: '800px' }}>
30 <h2 className="nav-tab-wrapper" style={{ marginBottom: '20px' }}>
31 <a
32 className={`nav-tab${activeTab === 'upload' ? ' nav-tab-active' : ''}`}
33 href="#"
34 onClick={(e) => {
35 e.preventDefault()
36 handleTabChange('upload')
37 }}
38 >
39 {__('Import Snippets', 'code-snippets')}
40 </a>
41 <a
42 className={`nav-tab${activeTab === 'plugins' ? ' nav-tab-active' : ''}`}
43 href="#"
44 onClick={(e) => {
45 e.preventDefault()
46 handleTabChange('plugins')
47 }}
48 >
49 {__('Import from other plugins', 'code-snippets')}
50 </a>
51 </h2>
52
53 <ImportSection active={activeTab === 'upload'}>
54 <FileUploadForm />
55 </ImportSection>
56
57 <ImportSection active={activeTab === 'plugins'}>
58 <ImportForm />
59 </ImportSection>
60 </div>
61 )
62 }
63