Skip to content

Commit

Permalink
fix(core): add mobile edit button (#7996)
Browse files Browse the repository at this point in the history
  • Loading branch information
L-Sun authored Aug 28, 2024
1 parent 65a8719 commit 0668568
Show file tree
Hide file tree
Showing 3 changed files with 23 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -1099,7 +1099,7 @@ export const PagePropertiesTable = ({ docId }: { docId: string }) => {
// if the given page is not in the current workspace, then we don't render anything
// eg. when it is in history modal

if (!manager.page || manager.readonly) {
if (!manager.page) {
return null;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -207,7 +207,7 @@ export const BlocksuiteDocEditor = forwardRef<
}}
></div>
) : null}
{!page.readonly && settings.displayBiDirectionalLink ? (
{!shared && settings.displayBiDirectionalLink ? (
<BiDirectionalLinkPanel />
) : null}
</div>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ import { useEnableCloud } from '@affine/core/hooks/affine/use-enable-cloud';
import { useExportPage } from '@affine/core/hooks/affine/use-export-page';
import { useTrashModalHelper } from '@affine/core/hooks/affine/use-trash-modal-helper';
import { useAsyncCallback } from '@affine/core/hooks/affine-async-hooks';
import { useDocMetaHelper } from '@affine/core/hooks/use-block-suite-page-meta';
import { track } from '@affine/core/mixpanel';
import { EditorService } from '@affine/core/modules/editor';
import { WorkbenchService } from '@affine/core/modules/workbench';
Expand All @@ -35,6 +36,7 @@ import {
InformationIcon,
OpenInNewIcon,
PageIcon,
SaveIcon,
ShareIcon,
SplitViewIcon,
TocIcon,
Expand Down Expand Up @@ -83,6 +85,9 @@ export const PageHeaderMenuButton = ({
const { importFile } = usePageHelper(docCollection);
const { setTrashModal } = useTrashModalHelper(docCollection);

const [isEditing, setEditing] = useState(!page.readonly);
const { setDocReadonly } = useDocMetaHelper(docCollection);

const view = useService(ViewService).view;

const openSidePanel = useCallback(
Expand Down Expand Up @@ -196,6 +201,21 @@ export const PageHeaderMenuButton = ({
toggleFavorite();
}, [toggleFavorite]);

const handleToggleEdit = useCallback(() => {
setDocReadonly(page.id, !page.readonly);
setEditing(!isEditing);
}, [isEditing, page.id, page.readonly, setDocReadonly]);

const isMobile = environment.isBrowser && environment.isMobile;
const mobileEditMenuItem = (
<MenuItem
prefixIcon={isEditing ? <SaveIcon /> : <EditIcon />}
onSelect={handleToggleEdit}
>
{t[isEditing ? 'Save' : 'Edit']()}
</MenuItem>
);

const showResponsiveMenu = hideShare;
const ResponsiveMenuItems = (
<>
Expand Down Expand Up @@ -235,6 +255,7 @@ export const PageHeaderMenuButton = ({
const EditMenu = (
<>
{showResponsiveMenu ? ResponsiveMenuItems : null}
{isMobile && mobileEditMenuItem}
{!isJournal && (
<MenuItem
prefixIcon={<EditIcon />}
Expand Down

0 comments on commit 0668568

Please sign in to comment.