PluginProbe
Extendify / 0.10.1
Extendify v0.10.1
3.2.1 3.2.0 3.1.6 3.1.5 3.1.4 3.1.3 3.1.2 3.1.1 3.1.0 3.0.6 3.0.5 3.0.4 trunk 0.1.0 0.10.0 0.10.1 0.10.2 0.11.0 0.11.1 0.2.0 0.3.0 0.3.1 0.4.0 0.5.0 0.6.0 All 127 releases
extendify / src / Library / components / MainButtons.js

MainButtons.js in Extendify 0.10.1, at src/Library/components/MainButtons.js

100 lines 3.3 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
1 import { Button } from '@wordpress/components'
2 import { useState, useEffect, useRef } from '@wordpress/element'
3 import { __ } from '@wordpress/i18n'
4 import { Icon } from '@wordpress/icons'
5 import { General } from '@library/api/General'
6 import { useGlobalStore } from '@library/state/GlobalState'
7 import { useUserStore } from '@library/state/User'
8 import { openModal } from '@library/util/general'
9 import { brandMark } from './icons'
10 import { NewImportsPopover } from './popovers/NewImportsPopover'
11
12 export const MainButtonWrapper = () => {
13 const [showTooltip, setShowTooltip] = useState(false)
14 const once = useRef(false)
15 const buttonRef = useRef()
16 const loggedIn = useUserStore((state) => state.apiKey.length)
17 const hasImported = useUserStore((state) => state.imports > 0)
18 const open = useGlobalStore((state) => state.open)
19 const hasPendingNewImports = useUserStore(
20 (state) => state.allowedImports === 0,
21 )
22
23 const handleTooltipClose = async () => {
24 await General.ping('mb-tooltip-closed')
25 setShowTooltip(false)
26 // If they close the tooltip, we can set the allowed imports
27 // to -1 and when it opens it will fetch and update. Meanwhile,
28 // -1 will be ignored by the this component.
29 useUserStore.setState({
30 allowedImports: -1,
31 })
32 }
33
34 useEffect(() => {
35 if (open) {
36 setShowTooltip(false)
37 once.current = true
38 }
39 if (!loggedIn && hasPendingNewImports && hasImported) {
40 once.current || setShowTooltip(true)
41 once.current = true
42 }
43 }, [loggedIn, hasPendingNewImports, hasImported, open])
44
45 return (
46 <>
47 <MainButton
48 buttonRef={buttonRef}
49 text={__('Design Library', 'extendify')}
50 />
51 {showTooltip && (
52 <NewImportsPopover
53 anchorRef={buttonRef}
54 onClick={async () => {
55 await General.ping('mb-tooltip-pressed')
56 openModal('main-button-tooltip')
57 }}
58 onPressX={handleTooltipClose}
59 />
60 )}
61 </>
62 )
63 }
64 const MainButton = ({ buttonRef, text }) => {
65 return (
66 <div className="extendify">
67 <Button
68 isPrimary
69 ref={buttonRef}
70 className="h-8 xs:h-9 px-1 min-w-0 xs:pl-2 xs:pr-3 sm:ml-2"
71 onClick={() => openModal('main-button')}
72 id="extendify-templates-inserter-btn"
73 icon={
74 <Icon
75 icon={brandMark}
76 size={24}
77 style={{ marginRight: 0 }}
78 />
79 }>
80 <span className="hidden xs:inline ml-1">{text}</span>
81 </Button>
82 </div>
83 )
84 }
85 export const CtaButton = () => {
86 return (
87 <Button
88 id="extendify-cta-button"
89 style={{
90 margin: '1rem 1rem 0',
91 width: 'calc(100% - 2rem)',
92 justifyContent: ' center',
93 }}
94 onClick={() => openModal('patterns-cta')}
95 isSecondary>
96 {__('Discover patterns in Extendify Library', 'extendify')}
97 </Button>
98 )
99 }
100