From 7637026b5e86458094d5d156b14d9238e0e3876e Mon Sep 17 00:00:00 2001 From: Antonin Cezard Date: Mon, 20 Dec 2021 14:29:35 +0100 Subject: [PATCH] fix: Properly display note path --- src/components/HeaderNotePath.jsx | 29 +++++++++++++++++++++++++++++ src/components/header_menu.jsx | 19 +++---------------- src/components/notes/editor.jsx | 1 - src/hooks/useFileWithPath.js | 1 - 4 files changed, 32 insertions(+), 18 deletions(-) create mode 100644 src/components/HeaderNotePath.jsx diff --git a/src/components/HeaderNotePath.jsx b/src/components/HeaderNotePath.jsx new file mode 100644 index 00000000..3fba2b87 --- /dev/null +++ b/src/components/HeaderNotePath.jsx @@ -0,0 +1,29 @@ +import React, { useMemo } from 'react' + +import { getDriveLink } from 'lib/utils' +import { Breakpoints } from 'types/enums' +import { NotePath } from './notes/List/NotePath' +import { WithBreakpoints } from './notes/List/WithBreakpoints' +import { useClient } from 'cozy-client' +import useFileWithPath from 'hooks/useFileWithPath' + +export const HeaderNotePath = ({ file }) => { + const client = useClient() + const fileWithPath = useFileWithPath({ cozyClient: client, file }) + const drivePath = useMemo(() => getDriveLink(client, file.attributes.dirId), [ + client, + file.attributes.dirId + ]) + + return ( + + {fileWithPath ? ( + + ) : null} + + ) +} diff --git a/src/components/header_menu.jsx b/src/components/header_menu.jsx index ac8050db..1a11a944 100644 --- a/src/components/header_menu.jsx +++ b/src/components/header_menu.jsx @@ -1,4 +1,4 @@ -import React, { useMemo } from 'react' +import React from 'react' import { models } from 'cozy-client' import { SharedRecipients } from 'cozy-sharing' @@ -10,11 +10,10 @@ import Typography from 'cozy-ui/transpiled/react/Typography' import { Slugs } from 'constants/strings' import { Breakpoints } from 'types/enums' -import { getDriveLink } from 'lib/utils' -import { NotePath } from './notes/List/NotePath' import { WithBreakpoints } from './notes/List/WithBreakpoints' import styles from './header_menu.styl' import { useFetchIcons } from 'hooks/useFetchIcons' +import { HeaderNotePath } from './HeaderNotePath' const HeaderMenu = ({ homeHref, @@ -22,14 +21,8 @@ const HeaderMenu = ({ rightComponent, isPublic, file, - client, primaryToolBarComponents }) => { - const drivePath = useMemo( - () => getDriveLink(client, file.attributes.dir_id), - [client, file.attributes.dir_id] - ) - const simplifiedDrivePath = drivePath.split('#')[1] const { fetchHomeIcon, fetchNoteIcon } = useFetchIcons() const { filename } = models.file.splitFilename(file.attributes) @@ -67,13 +60,7 @@ const HeaderMenu = ({ {filename} - - - + {!isPublic && } diff --git a/src/components/notes/editor.jsx b/src/components/notes/editor.jsx index d4331047..aa2c6149 100644 --- a/src/components/notes/editor.jsx +++ b/src/components/notes/editor.jsx @@ -130,7 +130,6 @@ export default function Editor(props) { } isPublic={isPublic} file={doc.file} - client={collabProvider.serviceClient.cozyClient} primaryToolbarComponents={ isPreview ? : null } diff --git a/src/hooks/useFileWithPath.js b/src/hooks/useFileWithPath.js index 033b6125..f332328a 100644 --- a/src/hooks/useFileWithPath.js +++ b/src/hooks/useFileWithPath.js @@ -3,7 +3,6 @@ import { models } from 'cozy-client' function useFileWithPath({ cozyClient, file }) { const [fileWithPath, setFileWithPath] = useState(undefined) - useEffect(() => { async function getParent(rawFile) { const file = models.file.normalize(rawFile)