diff --git a/src/drive/styles/filelist.styl b/src/drive/styles/filelist.styl index a1565da8f4..d4da52c0dd 100644 --- a/src/drive/styles/filelist.styl +++ b/src/drive/styles/filelist.styl @@ -157,8 +157,8 @@ column-width-thumbnail-bigger = 7rem .fil-content-header-action display flex justify-content flex-end - flex 1 - width 4.8rem + flex-shrink 0 + width 3.8rem padding-right .8rem margin-right 2rem diff --git a/src/drive/web/modules/filelist/cells/SharingShortcutBadge.jsx b/src/drive/web/modules/filelist/cells/SharingShortcutBadge.jsx index 0229c00d08..140c65f8c1 100644 --- a/src/drive/web/modules/filelist/cells/SharingShortcutBadge.jsx +++ b/src/drive/web/modules/filelist/cells/SharingShortcutBadge.jsx @@ -5,6 +5,7 @@ import cx from 'classnames' import { isSharingShortcutNew } from 'cozy-client/dist/models/file' import { useI18n } from 'cozy-ui/transpiled/react/I18n' import { TableCell } from 'cozy-ui/transpiled/react/Table' +import Circle from 'cozy-ui/transpiled/react/Circle' import styles from 'drive/styles/filelist.styl' @@ -19,17 +20,14 @@ const SharingShortcutBadge = ({ file }) => { )} > {isSharingShortcutNew(file) ? ( -
+ 1 -
+ ) : null} ) diff --git a/src/drive/web/modules/navigation/Nav.jsx b/src/drive/web/modules/navigation/Nav.jsx index 75c7cc8eea..ccd9dd103f 100644 --- a/src/drive/web/modules/navigation/Nav.jsx +++ b/src/drive/web/modules/navigation/Nav.jsx @@ -1,115 +1,47 @@ /* global __TARGET__ */ import React, { useState } from 'react' -import cx from 'classnames' -import { useLocation } from 'react-router-dom' -import { useI18n } from 'cozy-ui/transpiled/react' +import UINav from 'cozy-ui/transpiled/react/Nav' -import UINav, { - NavItem, - NavIcon, - NavText, - NavLink as UINavLink -} from 'cozy-ui/transpiled/react/Nav' +import { NavItem } from 'drive/web/modules/navigation/NavItem' +import { SharingsNavItem } from 'drive/web/modules/navigation/SharingsNavItem' -/** - * Returns true if `to` and `pathname` match - * Supports `rx` for regex matches. - */ -const navLinkMatch = (rx, to, pathname) => { - return rx ? rx.test(pathname) : pathname.slice(1) === to -} - -/** - * Like react-router NavLink but sets the lastClicked state (passed in props) - * to have a faster change of active (not waiting for the route to completely - * change). - */ -export const NavLink = ({ - children, - to, - rx, - clickState: [lastClicked, setLastClicked] -}) => { - const location = useLocation() - const pathname = lastClicked ? lastClicked : location.pathname - const isActive = navLinkMatch(rx, to, pathname) - return ( - setLastClicked(to)} - href={`#${to}`} - className={cx( - UINavLink.className, - isActive ? UINavLink.activeClassName : null - )} - > - {children} - - ) -} - -const NavItems = ({ items }) => { - const clickState = useState(null) - return ( - <> - {items.map((item, i) => - item ? ( - - - {item.icon ? : null} - {item.label} - - - ) : null - )} - - ) -} -const folderRoute = /\/folder(\/.*)?/ -const settingsRoute = /\/settings(\/.*)?/ -const recentRoute = /\/recent(\/.*)?/ -const sharingRoute = /\/sharings(\/.*)?/ -const trashRoute = /\/trash(\/.*)?/ export const Nav = () => { - const { t } = useI18n() - const routes = [ - { - to: '/folder', - icon: 'folder', - label: t('Nav.item_drive'), - rx: folderRoute - }, - { - to: '/recent', - icon: 'clock', - label: t('Nav.item_recent'), - rx: recentRoute - }, - { - to: '/sharings', - icon: 'share', - label: t('Nav.item_sharings'), - rx: sharingRoute - }, - { - to: '/trash', - icon: 'trash', - label: t('Nav.item_trash'), - rx: trashRoute - } - ] - if (__TARGET__ === 'mobile') { - routes.push({ - to: '/settings', - icon: 'gear', - label: t('Nav.item_settings'), - rx: settingsRoute - }) - } + const clickState = useState(null) + return ( - + + + + + {__TARGET__ === 'mobile' ? ( + + ) : null} ) } diff --git a/src/drive/web/modules/navigation/NavContent.jsx b/src/drive/web/modules/navigation/NavContent.jsx new file mode 100644 index 0000000000..47320194be --- /dev/null +++ b/src/drive/web/modules/navigation/NavContent.jsx @@ -0,0 +1,55 @@ +import React from 'react' +import PropTypes from 'prop-types' + +import { NavIcon, NavText } from 'cozy-ui/transpiled/react/Nav' +import Badge from 'cozy-ui/transpiled/react/Badge' +import useBreakpoints from 'cozy-ui/transpiled/react/hooks/useBreakpoints' +import Circle from 'cozy-ui/transpiled/react/Circle' + +const NavContent = ({ icon, badgeContent, label }) => { + 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 new file mode 100644 index 0000000000..219af62f06 --- /dev/null +++ b/src/drive/web/modules/navigation/NavItem.jsx @@ -0,0 +1,34 @@ +import React from 'react' +import PropTypes from 'prop-types' + +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, badgeContent }) => { + const { t } = useI18n() + + return ( + + + + + + ) +} + +NavItem.propTypes = { + to: PropTypes.string.isRequired, + icon: PropTypes.string.isRequired, + label: PropTypes.string.isRequired, + rx: PropTypes.shape(RegExp), + badgeContent: PropTypes.number +} + +export { NavItem } diff --git a/src/drive/web/modules/navigation/NavLink.jsx b/src/drive/web/modules/navigation/NavLink.jsx new file mode 100644 index 0000000000..e6a4db53ed --- /dev/null +++ b/src/drive/web/modules/navigation/NavLink.jsx @@ -0,0 +1,45 @@ +import React from 'react' +import cx from 'classnames' +import { useLocation } from 'react-router-dom' +import PropTypes from 'prop-types' + +import { NavLink as UINavLink } from 'cozy-ui/transpiled/react/Nav' + +import { navLinkMatch } from 'drive/web/modules/navigation/helpers' + +/** + * Like react-router NavLink but sets the lastClicked state (passed in props) + * to have a faster change of active (not waiting for the route to completely + * change). + */ +const NavLink = ({ + children, + to, + rx, + clickState: [lastClicked, setLastClicked] +}) => { + const location = useLocation() + const pathname = lastClicked ? lastClicked : location.pathname + const isActive = navLinkMatch(rx, to, pathname) + return ( + setLastClicked(to)} + href={`#${to}`} + className={cx( + UINavLink.className, + isActive ? UINavLink.activeClassName : null + )} + > + {children} + + ) +} + +NavLink.propTypes = { + children: PropTypes.node.isRequired, + to: PropTypes.string.isRequired, + rx: PropTypes.shape(RegExp) +} + +export { NavLink } 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/navigation/helpers.js b/src/drive/web/modules/navigation/helpers.js new file mode 100644 index 0000000000..70b57942a4 --- /dev/null +++ b/src/drive/web/modules/navigation/helpers.js @@ -0,0 +1,7 @@ +/** + * Returns true if `to` and `pathname` match + * Supports `rx` for regex matches. + */ +export const navLinkMatch = (rx, to, pathname) => { + return rx ? rx.test(pathname) : pathname.slice(1) === to +} diff --git a/src/drive/web/modules/queries.js b/src/drive/web/modules/queries.js index df0ce6649a..9681f20c5f 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({ + 'metadata.sharing.status': 'new', + class: 'shortcut' + }) + .indexFields(['metadata.sharing.status', 'class']), + options: { + as: 'io.cozy.files/metadata.sharing.status/new/class/shortcut', + fetchPolicy: defaultFetchPolicy + } +})