-
Notifications
You must be signed in to change notification settings - Fork 8
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: Sharing button with label on large view
- Loading branch information
Showing
4 changed files
with
68 additions
and
55 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
.sharing-button | ||
& > span > svg + span | ||
display var(--notes-share-button-label, unset) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,41 @@ | ||
import { useEffect, useState } from 'react' | ||
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) | ||
try { | ||
const parent = await cozyClient.query( | ||
cozyClient.get('io.cozy.files', file.attributes.dir_id) | ||
) | ||
setFileWithPath(models.file.ensureFilePath(file, parent.data)) | ||
} catch (e) { | ||
// eslint-disable-next-line no-console | ||
console.warn( | ||
`Request failed when try to fetch the parent ${ | ||
file.attributes.dir_id | ||
} of io.cozy.files ${file.id}` | ||
) | ||
setFileWithPath(null) | ||
// nothing to do here | ||
// @TODO send a sentry event | ||
} | ||
} | ||
|
||
getParent(file) | ||
}, | ||
[file.attributes.dir_id] | ||
) | ||
|
||
if (fileWithPath && fileWithPath.id == file.id) { | ||
return fileWithPath | ||
} else { | ||
return undefined | ||
} | ||
} | ||
|
||
export default useFileWithPath |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters