11import React from 'react'
22import styled from 'styled-components'
33import { navBarItemStyles } from './styles'
4+ import { useCookies } from 'react-cookie'
45
56type Action = {
67 title : string
@@ -9,31 +10,38 @@ type Action = {
910
1011export const ActionsMenu : React . FC = ( ) => {
1112 const [ isActive , setIsActive ] = React . useState ( false )
13+ const [ cookies ] = useCookies ( [ 'feature__myTags' ] )
14+ const [ actions , setActions ] = React . useState < Action [ ] > ( [ ] )
1215
13- const actions : Action [ ] = [ ]
16+ const addNewTag = { title : 'Add new tag' , onClick : ( ) => alert ( 'add new tag' ) }
1417
15- if ( ! actions . length ) return null
18+ React . useEffect ( ( ) => {
19+ const newActions = [ ]
20+ if ( cookies . feature__myTags === 'on' ) newActions . push ( addNewTag )
21+ setActions ( newActions )
22+ } , [ cookies ] )
1623
1724 return (
18- < Container title = 'More Actions' onClick = { ( ) => setIsActive ( ! isActive ) } >
25+ < Container title = 'Actions' onClick = { ( ) => setIsActive ( ! isActive ) } isHidden = { ! actions . length } >
1926 < svg viewBox = "0 0 24 24" >
2027 < circle cx = "5" cy = "12" r = "2" />
2128 < circle cx = "12" cy = "12" r = "2" />
2229 < circle cx = "19" cy = "12" r = "2" />
2330 </ svg >
2431 < Popup isActive = { isActive } >
2532 { actions . map ( action => (
26- < Item > < a onClick = { action . onClick } > { action . title } </ a > </ Item >
33+ < Item key = { action . title } > < a onClick = { action . onClick } > { action . title } </ a > </ Item >
2734 ) ) }
2835 </ Popup >
2936 </ Container >
3037 )
3138}
3239
33- const Container = styled . button . attrs ( { className : 'Explorer__ActionsMenu__Container' } ) `
40+ const Container = styled . button . attrs ( { className : 'Explorer__ActionsMenu__Container' } ) < { isHidden : boolean } > `
3441 ${ navBarItemStyles }
3542 background: none;
3643 border: 0;
44+ display: ${ o => o . isHidden && 'none' } ;
3745
3846 svg {
3947 display: block;
0 commit comments