-
Notifications
You must be signed in to change notification settings - Fork 64
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(OO): Add an edit button to the toolbar in place of the FabButton
And no longer display the FabButton in Desktop mode
- Loading branch information
Showing
7 changed files
with
170 additions
and
7 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
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,131 @@ | ||
import React, { useState } from 'react' | ||
import { useNavigate } from 'react-router-dom' | ||
|
||
import { useClient, useQuery, Q, isQueryLoading } from 'cozy-client' | ||
import Buttons from 'cozy-ui/transpiled/react/Buttons' | ||
import Icon from 'cozy-ui/transpiled/react/Icon' | ||
import LightbulbIcon from 'cozy-ui/transpiled/react/Icons/Lightbulb' | ||
import RenameIcon from 'cozy-ui/transpiled/react/Icons/Rename' | ||
import Tooltip from 'cozy-ui/transpiled/react/Tooltip' | ||
import Typography from 'cozy-ui/transpiled/react/Typography' | ||
import useBreakpoints from 'cozy-ui/transpiled/react/providers/Breakpoints' | ||
import { useI18n } from 'cozy-ui/transpiled/react/providers/I18n' | ||
import { makeStyles } from 'cozy-ui/transpiled/react/styles' | ||
|
||
import { DOCTYPE_FILES_SETTINGS } from 'lib/doctypes' | ||
import { useOnlyOfficeContext } from 'modules/views/OnlyOffice/OnlyOfficeProvider' | ||
import { canWriteOfficeDocument } from 'modules/views/OnlyOffice/helpers' | ||
import { getAppSettingQuery } from 'queries' | ||
|
||
const useStyle = makeStyles({ | ||
popper: { | ||
pointerEvents: 'auto', | ||
'& .actions-tooltip': { | ||
display: 'flex', | ||
justifyContent: 'flex-end', | ||
marginTop: '0.5rem', | ||
'& > button': { | ||
color: 'var(--white)' | ||
} | ||
} | ||
}, | ||
tooltip: { | ||
backgroundColor: 'var(--primaryColor)' | ||
}, | ||
arrow: { | ||
color: 'var(--primaryColor)' | ||
} | ||
}) | ||
|
||
const EditButton = ({ openTooltip }) => { | ||
const classes = useStyle() | ||
const client = useClient() | ||
const { t } = useI18n() | ||
const { editorMode, setEditorMode } = useOnlyOfficeContext() | ||
const navigate = useNavigate() | ||
const [showTooltip, setShowTooltip] = useState(true) | ||
|
||
const handleClick = () => { | ||
if (canWriteOfficeDocument()) { | ||
setEditorMode(editorMode === 'view' ? 'edit' : 'view') | ||
} else { | ||
navigate('./paywall') | ||
} | ||
} | ||
|
||
const closeTooltip = () => { | ||
setShowTooltip(false) | ||
} | ||
|
||
const handleTooltip = async () => { | ||
const { data } = await client.query(Q(DOCTYPE_FILES_SETTINGS)) | ||
const settings = data?.[0] || {} | ||
await client.save({ | ||
...settings, | ||
_type: DOCTYPE_FILES_SETTINGS, | ||
hideOOEditTooltip: true | ||
}) | ||
} | ||
|
||
return ( | ||
<Tooltip | ||
open={showTooltip && openTooltip} | ||
classes={classes} | ||
title={ | ||
<> | ||
<div className="u-flex u-flex-items-center u-mb-half"> | ||
<Icon icon={LightbulbIcon} className="u-mr-half" /> | ||
<Typography variant="h6" color="inherit"> | ||
{t('OnlyOffice.tooltip.title')} | ||
</Typography> | ||
</div> | ||
<Typography variant="body2" color="inherit"> | ||
{t('OnlyOffice.tooltip.text')} | ||
</Typography> | ||
<div className="actions-tooltip"> | ||
<Buttons | ||
onClick={handleTooltip} | ||
variant="text" | ||
label={t('OnlyOffice.tooltip.actions.hide')} | ||
/> | ||
<Buttons | ||
onClick={closeTooltip} | ||
variant="text" | ||
label={t('OnlyOffice.tooltip.actions.ok')} | ||
/> | ||
</div> | ||
</> | ||
} | ||
> | ||
<Buttons | ||
className="u-ml-half" | ||
onClick={handleClick} | ||
disabled={editorMode === 'edit'} | ||
startIcon={<Icon icon={RenameIcon} />} | ||
label={t('OnlyOffice.actions.edit')} | ||
/> | ||
</Tooltip> | ||
) | ||
} | ||
|
||
const EditButtonWrapper = () => { | ||
const { isMobile } = useBreakpoints() | ||
const { editorMode } = useOnlyOfficeContext() | ||
|
||
const { data: settings, ...appSettingsQueryResult } = useQuery( | ||
getAppSettingQuery.definition, | ||
getAppSettingQuery.options | ||
) | ||
const hideOOEditTooltip = settings?.[0]?.hideOOEditTooltip | ||
const openTooltip = isQueryLoading(appSettingsQueryResult) | ||
? false | ||
: !hideOOEditTooltip && editorMode === 'view' && canWriteOfficeDocument() | ||
|
||
if (isMobile) { | ||
return null | ||
} | ||
|
||
return <EditButton openTooltip={openTooltip} /> | ||
} | ||
|
||
export default EditButtonWrapper |
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
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