PluginProbe
Code Snippets / 3.10.0-beta.1
Code Snippets v3.10.0-beta.1
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.0-beta.1, at js/components/ManageMenu/CommunityCloud/CommunityCloud.tsx

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