Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat(OO): Change actions of the toolbar #3258

Merged
merged 7 commits into from
Dec 3, 2024
Merged
36 changes: 15 additions & 21 deletions src/modules/views/OnlyOffice/Title.jsx
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import React, { useMemo } from 'react'
import React from 'react'

import { SharingBannerPlugin } from 'cozy-sharing'
import { useSharingInfos } from 'cozy-sharing'
import { DialogTitle } from 'cozy-ui/transpiled/react/Dialog'
import Divider from 'cozy-ui/transpiled/react/Divider'
import useBreakpoints from 'cozy-ui/transpiled/react/providers/Breakpoints'
Expand All @@ -9,7 +10,6 @@ import { makeStyles } from 'cozy-ui/transpiled/react/styles'
import { TrashedBanner } from 'components/TrashedBanner'
import { useOnlyOfficeContext } from 'modules/views/OnlyOffice/OnlyOfficeProvider'
import Toolbar from 'modules/views/OnlyOffice/Toolbar'
import { showSharingBanner } from 'modules/views/OnlyOffice/helpers'

const useStyles = makeStyles(theme => ({
root: {
Expand All @@ -21,25 +21,19 @@ const useStyles = makeStyles(theme => ({

const Title = () => {
const { isMobile } = useBreakpoints()
const {
fileId,
isPublic,
isFromSharing,
isInSharedFolder,
isEditorModeView,
isTrashed
} = useOnlyOfficeContext()
const { fileId, isPublic, isEditorModeView, isTrashed } =
useOnlyOfficeContext()
const sharingInfos = useSharingInfos()
const { loading, isSharingShortcutCreated } = sharingInfos
const styles = useStyles()

const showBanner = useMemo(
() =>
showSharingBanner({
isPublic,
isFromSharing,
isInSharedFolder
}),
[isPublic, isFromSharing, isInSharedFolder]
)
// Check if the sharing shortcut has already been created (but not synced)
const isShareAlreadyAdded = !loading && isSharingShortcutCreated
// Check if you are sharing Cozy to Cozy (Link sharing is on the `/public` route)
const isPreview = window.location.pathname === '/preview'
zatteo marked this conversation as resolved.
Show resolved Hide resolved
// Show the sharing banner plugin only on shared links view and cozy to cozy sharing view(not added)
const isSharingBannerPluginDisplayed =
isPublic && (!isShareAlreadyAdded || !isPreview)
Merkur39 marked this conversation as resolved.
Show resolved Hide resolved

const showDialogToolbar = isEditorModeView || !isMobile

Expand All @@ -53,7 +47,7 @@ const Title = () => {
className="u-ellipsis u-flex u-flex-items-center u-p-0 u-pr-1"
classes={styles}
>
<Toolbar />
<Toolbar sharingInfos={sharingInfos} />
</DialogTitle>
<Divider />
</>
Expand All @@ -62,7 +56,7 @@ const Title = () => {
<div style={{ backgroundColor: 'var(--paperBackgroundColor)' }}>
<TrashedBanner fileId={fileId} isPublic={isPublic} />
</div>
) : showBanner ? (
) : isSharingBannerPluginDisplayed ? (
<SharingBannerPlugin />
) : null}
</div>
Expand Down
35 changes: 31 additions & 4 deletions src/modules/views/OnlyOffice/Toolbar/index.jsx
Original file line number Diff line number Diff line change
@@ -1,23 +1,30 @@
import React from 'react'

import { makeActions } from 'cozy-ui/transpiled/react/ActionsMenu/Actions'
import useBreakpoints from 'cozy-ui/transpiled/react/providers/Breakpoints'
import { useI18n } from 'cozy-ui/transpiled/react/providers/I18n'

import FilesRealTimeQueries from 'components/FilesRealTimeQueries'
import { HOME_LINK_HREF } from 'constants/config'
import { useRedirectLink } from 'hooks/useRedirectLink'
import { openExternalLink } from 'modules/actions'
import { OpenExternalLinkButton } from 'modules/public/OpenExternalLinkButton'
import PublicToolbarMoreMenu from 'modules/public/PublicToolbarMoreMenu'
import { useOnlyOfficeContext } from 'modules/views/OnlyOffice/OnlyOfficeProvider'
import BackButton from 'modules/views/OnlyOffice/Toolbar/BackButton'
import FileIcon from 'modules/views/OnlyOffice/Toolbar/FileIcon'
import FileName from 'modules/views/OnlyOffice/Toolbar/FileName'
import HomeIcon from 'modules/views/OnlyOffice/Toolbar/HomeIcon'
import HomeLinker from 'modules/views/OnlyOffice/Toolbar/HomeLinker'
import ReadOnly from 'modules/views/OnlyOffice/Toolbar/ReadOnly'
import Separator from 'modules/views/OnlyOffice/Toolbar/Separator'
import Sharing from 'modules/views/OnlyOffice/Toolbar/Sharing'
import { useFileWithPath } from 'modules/views/hooks'

const Toolbar = () => {
const Toolbar = ({ sharingInfos }) => {
const { isMobile } = useBreakpoints()
const { fileId, isPublic, isReadOnly, isEditorReady } = useOnlyOfficeContext()
const { t } = useI18n()
const { fileId, isPublic, isEditorReady } = useOnlyOfficeContext()
const { discoveryLink, isSharingShortcutCreated, loading } = sharingInfos
zatteo marked this conversation as resolved.
Show resolved Hide resolved

const { data: fileWithPath } = useFileWithPath(fileId)
const { redirectBack, canRedirect } = useRedirectLink({ isPublic })
Expand All @@ -27,6 +34,16 @@ const Toolbar = () => {
const handleOnClick = () => {
redirectBack()
}
// Check if the share shortcut has not yet been added
const isShareNotAdded = !loading && !isSharingShortcutCreated

// discoveryLink exists only in cozy to cozy sharing
const link = discoveryLink || HOME_LINK_HREF
const actions = makeActions([openExternalLink], {
t,
link,
isSharingShortcutCreated
})

return (
<>
Expand All @@ -50,7 +67,17 @@ const Toolbar = () => {
)}
<FileName fileWithPath={fileWithPath} isPublic={isPublic} />
</div>
{isReadOnly && <ReadOnly />}
{isPublic && !isMobile && isShareNotAdded && (
<OpenExternalLinkButton
link={link}
isSharingShortcutCreated={isSharingShortcutCreated}
/>
)}

{isPublic && (
<PublicToolbarMoreMenu files={[fileWithPath]} actions={actions} />
)}

{!isPublic && isEditorReady && <Sharing fileWithPath={fileWithPath} />}
</>
)
Expand Down