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 / ManageMenu / CommunityCloud / CommunityCloud.tsx

CommunityCloud.tsx in Code Snippets 3.10.2, at js/components/ManageMenu/CommunityCloud/CommunityCloud.tsx

86 lines 2.6 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
1 import React, { useState } from 'react'
2 import { __, sprintf } from '@wordpress/i18n'
3 import { WithRestAPIContext } from '../../../hooks/useRestAPI'
4 import { useSnippetView } from '../../../hooks/useSnippetView'
5 import { isLicensed } from '../../../utils/screen'
6 import { updateQueryParams } from '../../../utils/urls'
7 import { ScreenMetaSlot } from '../../common/ScreenMetaSlot'
8 import { SubnavTabs, getTabFromQuery } from '../../common/SubnavTabs'
9 import { WithCloudSnippetDownloadsContext } from '../../common/cloud/WithCloudSnippetDownloadsContext'
10 import { UpsellPage } from '../../common/UpsellDialog'
11 import { WithCloudSearchContext, useCloudSearch } from './WithCloudSearchContext'
12 import { CloudSearch } from './CloudSearch'
13 import type { SubnavTab } from '../../common/SubnavTabs'
14
15 const TAB_QUERY_PARAM = 'tab'
16
17 const TABS: SubnavTab<'snippets' | 'bundles'>[] = [
18 {
19 name: 'snippets',
20 label: __('Snippets', 'code-snippets')
21 },
22 {
23 name: 'bundles',
24 label: __('Bundles', 'code-snippets'),
25 pro: true
26 }
27 ]
28
29 const CommunityCloudInner = () => {
30 const [currentTab, setCurrentTab] = useState(() => getTabFromQuery(TABS, TAB_QUERY_PARAM))
31 const { snippetView, setSnippetView } = useSnippetView()
32 const { searchResults } = useCloudSearch()
33
34 return (
35 <>
36 <SubnavTabs
37 className="community-cloud-nav"
38 ariaLabel={__('Community Cloud types', 'code-snippets')}
39 tabs={TABS}
40 getTabCount={tab => 'snippets' === tab.name ? searchResults?.totalItems : undefined}
41 currentTab={currentTab}
42 setCurrentTab={tab => {
43 updateQueryParams({ [TAB_QUERY_PARAM]: tab.name })
44 setCurrentTab(tab)
45 }}
46 />
47
48 <ScreenMetaSlot hidden={'bundles' === currentTab.name} />
49
50 {(!currentTab.pro || isLicensed()) && (
51 <>
52 <div className="snippets-page-header">
53 <h1>{
54 // translators: %s: label of the currently selected community cloud tab.
55 sprintf(__('Community Cloud: %s', 'code-snippets'), currentTab.label)}</h1>
56 </div>
57
58 <hr className="wp-header-end" />
59
60 <p className="snippets-page-description">
61 {__('Search the community cloud and download user-shared snippets directly to your site.', 'code-snippets')}
62 </p>
63 </>)}
64
65 {(() => {
66 switch (currentTab.name) {
67 case 'snippets':
68 return <CloudSearch snippetView={snippetView} setSnippetView={setSnippetView} />
69
70 case 'bundles':
71 return <UpsellPage />
72 }
73 })()}
74 </>
75 )
76 }
77
78 export const CommunityCloud = () =>
79 <WithRestAPIContext>
80 <WithCloudSnippetDownloadsContext>
81 <WithCloudSearchContext>
82 <CommunityCloudInner />
83 </WithCloudSearchContext>
84 </WithCloudSnippetDownloadsContext>
85 </WithRestAPIContext>
86