diff --git a/src/drive/web/modules/navigation/Nav.jsx b/src/drive/web/modules/navigation/Nav.jsx index a6df4e2354..ccd9dd103f 100644 --- a/src/drive/web/modules/navigation/Nav.jsx +++ b/src/drive/web/modules/navigation/Nav.jsx @@ -4,6 +4,7 @@ import React, { useState } from 'react' import UINav from 'cozy-ui/transpiled/react/Nav' import { NavItem } from 'drive/web/modules/navigation/NavItem' +import { SharingsNavItem } from 'drive/web/modules/navigation/SharingsNavItem' export const Nav = () => { const clickState = useState(null) @@ -24,13 +25,7 @@ export const Nav = () => { rx={/\/recent(\/.*)?/} clickState={clickState} /> - + { + const { isDesktop } = useBreakpoints() + + if (badgeContent) { + if (isDesktop) { + return ( + <> + + {label} + + + {badgeContent > 99 ? '99+' : badgeContent} + + + + ) + } else { + return ( + <> + + + + {label} + + ) + } + } + + return ( + <> + + {label} + + ) +} + +NavContent.propTypes = { + icon: PropTypes.string, + badgeContent: PropTypes.number, + label: PropTypes.string +} + +export { NavContent } diff --git a/src/drive/web/modules/navigation/NavItem.jsx b/src/drive/web/modules/navigation/NavItem.jsx index 81cd400a30..219af62f06 100644 --- a/src/drive/web/modules/navigation/NavItem.jsx +++ b/src/drive/web/modules/navigation/NavItem.jsx @@ -1,24 +1,23 @@ import React from 'react' import PropTypes from 'prop-types' -import { useI18n } from 'cozy-ui/transpiled/react' - -import { - NavItem as UINavItem, - NavIcon, - NavText -} from 'cozy-ui/transpiled/react/Nav' +import { NavItem as UINavItem } from 'cozy-ui/transpiled/react/Nav' +import { useI18n } from 'cozy-ui/transpiled/react/I18n' +import { NavContent } from 'drive/web/modules/navigation/NavContent' import { NavLink } from 'drive/web/modules/navigation/NavLink' -const NavItem = ({ to, icon, label, rx, clickState }) => { +const NavItem = ({ to, icon, label, rx, clickState, badgeContent }) => { const { t } = useI18n() return ( - - {t(`Nav.item_${label}`)} + ) @@ -28,7 +27,8 @@ NavItem.propTypes = { to: PropTypes.string.isRequired, icon: PropTypes.string.isRequired, label: PropTypes.string.isRequired, - rx: PropTypes.shape(RegExp) + rx: PropTypes.shape(RegExp), + badgeContent: PropTypes.number } export { NavItem } diff --git a/src/drive/web/modules/navigation/SharingsNavItem.jsx b/src/drive/web/modules/navigation/SharingsNavItem.jsx new file mode 100644 index 0000000000..d75bd799e8 --- /dev/null +++ b/src/drive/web/modules/navigation/SharingsNavItem.jsx @@ -0,0 +1,27 @@ +import React from 'react' + +import { useQuery } from 'cozy-client' + +import { buildNewSharingShortcutQuery } from 'drive/web/modules/queries' +import { NavItem } from 'drive/web/modules/navigation/NavItem' + +const SharingsNavItem = ({ clickState }) => { + const newSharingShortcutQuery = buildNewSharingShortcutQuery() + const newSharingShortcutResult = useQuery( + newSharingShortcutQuery.definition, + newSharingShortcutQuery.options + ) + + return ( + + ) +} + +export { SharingsNavItem } diff --git a/src/drive/web/modules/queries.js b/src/drive/web/modules/queries.js index df0ce6649a..f19d753bf1 100644 --- a/src/drive/web/modules/queries.js +++ b/src/drive/web/modules/queries.js @@ -355,3 +355,17 @@ export const buildFolderByPathQuery = path => ({ fetchPolicy: defaultFetchPolicy } }) + +export const buildNewSharingShortcutQuery = () => ({ + definition: () => + Q('io.cozy.files') + .where({ + class: 'shortcut', + 'metadata.sharing.status': 'new' + }) + .indexFields(['class', 'metadata.sharing.status']), + options: { + as: 'io.cozy.files/new_sharing_shortcut', + fetchPolicy: defaultFetchPolicy + } +})