Skip to content

Commit

Permalink
fix: Properly display note path
Browse files Browse the repository at this point in the history
  • Loading branch information
acezard committed Dec 20, 2021
1 parent c18ce12 commit 7637026
Show file tree
Hide file tree
Showing 4 changed files with 32 additions and 18 deletions.
29 changes: 29 additions & 0 deletions src/components/HeaderNotePath.jsx
Original file line number Diff line number Diff line change
@@ -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 (
<WithBreakpoints hideOn={Breakpoints.Mobile}>
{fileWithPath ? (
<NotePath
drivePath={drivePath}
path={fileWithPath.path}
target="_blank"
/>
) : null}
</WithBreakpoints>
)
}
19 changes: 3 additions & 16 deletions src/components/header_menu.jsx
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import React, { useMemo } from 'react'
import React from 'react'

import { models } from 'cozy-client'
import { SharedRecipients } from 'cozy-sharing'
Expand All @@ -10,26 +10,19 @@ 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,
leftComponent,
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)

Expand Down Expand Up @@ -67,13 +60,7 @@ const HeaderMenu = ({
<strong>{filename}</strong>
</Typography>

<WithBreakpoints hideOn={Breakpoints.Mobile}>
<NotePath
drivePath={drivePath}
path={file.attributes.path || simplifiedDrivePath}
target="_blank"
/>
</WithBreakpoints>
{!isPublic && <HeaderNotePath file={file} />}
</div>
</div>

Expand Down
1 change: 0 additions & 1 deletion src/components/notes/editor.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -130,7 +130,6 @@ export default function Editor(props) {
}
isPublic={isPublic}
file={doc.file}
client={collabProvider.serviceClient.cozyClient}
primaryToolbarComponents={
isPreview ? <SharingBannerPlugin /> : null
}
Expand Down
1 change: 0 additions & 1 deletion src/hooks/useFileWithPath.js
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down

0 comments on commit 7637026

Please sign in to comment.