| 1 |
import { Panel } from '@wordpress/components' |
| 2 |
import { Button } from '@wordpress/components' |
| 3 |
import { memo } from '@wordpress/element' |
| 4 |
import { __ } from '@wordpress/i18n' |
| 5 |
import { Icon, close } from '@wordpress/icons' |
| 6 |
import classNames from 'classnames' |
| 7 |
import { ImportCounter } from '@extendify/components/ImportCounter' |
| 8 |
import { SidebarNotice } from '@extendify/components/SidebarNotice' |
| 9 |
import { SiteTypeSelector } from '@extendify/components/SiteTypeSelector' |
| 10 |
import TaxonomySection from '@extendify/components/TaxonomySection' |
| 11 |
import { featured } from '@extendify/components/icons' |
| 12 |
import { brandMark } from '@extendify/components/icons/' |
| 13 |
import { useTestGroup } from '@extendify/hooks/useTestGroup' |
| 14 |
import { useGlobalStore } from '@extendify/state/GlobalState' |
| 15 |
import { useTaxonomyStore } from '@extendify/state/Taxonomies' |
| 16 |
import { useTemplatesStore } from '@extendify/state/Templates' |
| 17 |
import { useUserStore } from '@extendify/state/User' |
| 18 |
|
| 19 |
export const Sidebar = memo(function Sidebar() { |
| 20 |
const taxonomies = useTaxonomyStore((state) => state.taxonomies) |
| 21 |
const searchParams = useTemplatesStore((state) => state.searchParams) |
| 22 |
const updatePreferredSiteType = useUserStore( |
| 23 |
(state) => state.updatePreferredSiteType, |
| 24 |
) |
| 25 |
const updateTaxonomies = useTemplatesStore( |
| 26 |
(state) => state.updateTaxonomies, |
| 27 |
) |
| 28 |
const apiKey = useUserStore((state) => state.apiKey) |
| 29 |
const taxonomyType = |
| 30 |
searchParams.type === 'pattern' ? 'patternType' : 'layoutType' |
| 31 |
const isFeatured = !searchParams?.taxonomies[taxonomyType]?.slug?.length |
| 32 |
const setOpen = useGlobalStore((state) => state.setOpen) |
| 33 |
const noticeVariety = useTestGroup('import-counter-type', ['A', 'B']) |
| 34 |
|
| 35 |
return ( |
| 36 |
<> |
| 37 |
<div className="-ml-1.5 hidden px-5 text-extendify-black sm:flex"> |
| 38 |
<Icon icon={brandMark} size={40} /> |
| 39 |
</div> |
| 40 |
<div className="flex md:hidden items-center justify-end -mt-5 mx-1"> |
| 41 |
<Button |
| 42 |
onClick={() => setOpen(false)} |
| 43 |
icon={<Icon icon={close} size={24} />} |
| 44 |
label={__('Close library', 'extendify')} |
| 45 |
/> |
| 46 |
</div> |
| 47 |
<div className="px-5 hidden md:block"> |
| 48 |
<button |
| 49 |
onClick={() => |
| 50 |
updateTaxonomies({ |
| 51 |
[taxonomyType]: { slug: '', title: 'Featured' }, |
| 52 |
}) |
| 53 |
} |
| 54 |
className={classNames( |
| 55 |
'button-focus m-0 flex w-full cursor-pointer items-center space-x-1 bg-transparent px-0 py-2 text-left text-sm leading-none transition duration-200 hover:text-wp-theme-500', |
| 56 |
{ 'text-wp-theme-500': isFeatured }, |
| 57 |
)}> |
| 58 |
<Icon icon={featured} size={24} /> |
| 59 |
<span className="text-sm"> |
| 60 |
{__('Featured', 'extendify')} |
| 61 |
</span> |
| 62 |
</button> |
| 63 |
</div> |
| 64 |
<div className="mx-6 px-5 pt-0.5 sm:mx-0 sm:mb-8 sm:mt-0"> |
| 65 |
{Object.keys(taxonomies?.siteType ?? {}).length > 0 && ( |
| 66 |
<SiteTypeSelector |
| 67 |
value={searchParams?.taxonomies?.siteType ?? ''} |
| 68 |
setValue={(termData) => { |
| 69 |
updatePreferredSiteType(termData) |
| 70 |
updateTaxonomies({ siteType: termData }) |
| 71 |
}} |
| 72 |
terms={taxonomies.siteType} |
| 73 |
/> |
| 74 |
)} |
| 75 |
</div> |
| 76 |
<div className="mt-px hidden flex-grow overflow-y-auto pb-36 pt-px sm:block space-y-6"> |
| 77 |
<Panel className="bg-transparent"> |
| 78 |
<TaxonomySection |
| 79 |
taxType={taxonomyType} |
| 80 |
taxonomies={taxonomies[taxonomyType]?.filter( |
| 81 |
(term) => !term?.designType, |
| 82 |
)} |
| 83 |
/> |
| 84 |
</Panel> |
| 85 |
<Panel className="bg-transparent"> |
| 86 |
<TaxonomySection |
| 87 |
taxLabel={__('Design', 'extendify')} |
| 88 |
taxType={taxonomyType} |
| 89 |
taxonomies={taxonomies[taxonomyType]?.filter((term) => |
| 90 |
Boolean(term?.designType), |
| 91 |
)} |
| 92 |
/> |
| 93 |
</Panel> |
| 94 |
</div> |
| 95 |
{!apiKey.length && ( |
| 96 |
<div className="px-5"> |
| 97 |
{noticeVariety === 'A' ? <ImportCounter /> : null} |
| 98 |
{noticeVariety === 'B' ? <SidebarNotice /> : null} |
| 99 |
</div> |
| 100 |
)} |
| 101 |
</> |
| 102 |
) |
| 103 |
}) |
| 104 |
|