Skip to content

Commit

Permalink
feat: Do not display share action
Browse files Browse the repository at this point in the history
And share banner in a subfolder
  • Loading branch information
Merkur39 committed Nov 29, 2024
1 parent c0e718b commit b036ea0
Show file tree
Hide file tree
Showing 3 changed files with 28 additions and 16 deletions.
10 changes: 2 additions & 8 deletions src/modules/public/PublicToolbar.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -12,8 +12,7 @@ const PublicToolbar = ({
sharingInfos,
className
}) => {
const { loading, discoveryLink, sharing, isSharingShortcutCreated } =
sharingInfos
const { loading, discoveryLink } = sharingInfos

if (loading) return null
return (
Expand All @@ -28,12 +27,7 @@ const PublicToolbar = ({
refreshFolderContent={refreshFolderContent}
/>
) : (
<PublicToolbarCozyToCozy
discoveryLink={discoveryLink}
files={files}
isSharingShortcutCreated={isSharingShortcutCreated}
sharing={sharing}
/>
<PublicToolbarCozyToCozy files={files} sharingInfos={sharingInfos} />
)}
</div>
)
Expand Down
24 changes: 17 additions & 7 deletions src/modules/public/PublicToolbarCozyToCozy.jsx
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import PropTypes from 'prop-types'
import React from 'react'

import { useClient } from 'cozy-client'
Expand All @@ -8,30 +9,34 @@ import useBreakpoints from 'cozy-ui/transpiled/react/providers/Breakpoints'
import { useI18n } from 'cozy-ui/transpiled/react/providers/I18n'

import { BarRightOnMobile } from 'components/Bar'
import useCurrentFolderId from 'hooks/useCurrentFolderId'
import { download, hr, openExternalLink, select } from 'modules/actions'
import { DownloadFilesButton } from 'modules/public/DownloadFilesButton'
import { OpenExternalLinkButton } from 'modules/public/OpenExternalLinkButton'
import PublicToolbarMoreMenu from 'modules/public/PublicToolbarMoreMenu'
import { useSelectionContext } from 'modules/selection/SelectionProvider'

const PublicToolbarCozyToCozy = ({
isSharingShortcutCreated,
discoveryLink,
files
}) => {
const PublicToolbarCozyToCozy = ({ sharingInfos, files }) => {
const { loading, discoveryLink, sharing, isSharingShortcutCreated } =
sharingInfos
const { isMobile } = useBreakpoints()
const { t } = useI18n()
const { showAlert } = useAlert()
const client = useClient()
const { showSelectionBar } = useSelectionContext()
const vaultClient = useVaultClient()
const currentFolderId = useCurrentFolderId()

const isOnSharedFolder =
!loading &&
sharing?.rules?.some(rule => rule.values.includes(currentFolderId))

const actions = makeActions(
[
isMobile && download,
files.length > 1 && select,
((isMobile && files.length > 0) || files.length > 1) && hr,
openExternalLink
isOnSharedFolder && openExternalLink
],
{
t,
Expand All @@ -47,7 +52,7 @@ const PublicToolbarCozyToCozy = ({
return (
<BarRightOnMobile>
{!isMobile && files.length > 0 && <DownloadFilesButton files={files} />}
{!isMobile && !isSharingShortcutCreated && (
{!isMobile && !isSharingShortcutCreated && isOnSharedFolder && (
<OpenExternalLinkButton
className="u-ml-half"
link={discoveryLink}
Expand All @@ -63,4 +68,9 @@ const PublicToolbarCozyToCozy = ({
)
}

PublicToolbarCozyToCozy.propTypes = {
files: PropTypes.array.isRequired,
sharingInfos: PropTypes.object.isRequired
}

export default PublicToolbarCozyToCozy
10 changes: 9 additions & 1 deletion src/modules/views/Public/PublicFolderView.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -87,6 +87,11 @@ const PublicFolderView = () => {
const sharingInfos = useSharingInfos()
const { showAlert } = useAlert()
const styles = useFabStyles()
const isOnSharedFolder =
!sharingInfos.loading &&
sharingInfos.sharing?.rules?.some(rule =>
rule.values.includes(currentFolderId)
)

const filesResult = usePublicFilesQuery(currentFolderId)
const files = filesResult.data
Expand Down Expand Up @@ -164,6 +169,9 @@ const PublicFolderView = () => {
!sharingInfos.loading && sharingInfos.isSharingShortcutCreated
// Check if you are sharing Cozy to Cozy (Link sharing is on the `/public` route)
const isPreview = window.location.pathname === '/preview'
// Show the sharing banner plugin only on shared links view and cozy to cozy sharing view(not added)
const isSharingBannerPluginDisplayed =
!isShareAlreadyAdded || (isOnSharedFolder && !isPreview)

const isAddToMyCozyFabDisplayed =
isMobile && isPreview && !isShareAlreadyAdded
Expand All @@ -172,7 +180,7 @@ const PublicFolderView = () => {
<Main isPublic={true}>
<ModalStack />
<ModalManager />
{!isShareAlreadyAdded && <SharingBannerPlugin />}
{isSharingBannerPluginDisplayed && <SharingBannerPlugin />}
<span className={cx({ 'u-pt-2': !isMobile })} />
<FolderViewHeader>
{currentFolderId && (
Expand Down

0 comments on commit b036ea0

Please sign in to comment.