Skip to content

Commit

Permalink
feat(mobile): editor mode switch (#8896)
Browse files Browse the repository at this point in the history
  • Loading branch information
CatsJuice committed Nov 25, 2024
1 parent 5994814 commit 922db5c
Show file tree
Hide file tree
Showing 3 changed files with 69 additions and 0 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
import { style } from '@vanilla-extract/css';

export const radioWrapper = style({
padding: '6px 10px',
width: '100%',
});
Original file line number Diff line number Diff line change
@@ -0,0 +1,61 @@
import {
RadioGroup,
type RadioItem,
useMobileMenuController,
} from '@affine/component';
import { EditorService } from '@affine/core/modules/editor';
import track from '@affine/track';
import type { DocMode } from '@blocksuite/affine/blocks';
import { useLiveData, useService } from '@toeverything/infra';
import { useCallback } from 'react';

import * as styles from './mode-switch.css';

const EdgelessRadioItem: RadioItem = {
value: 'edgeless',
label: 'Edgeless',
testId: 'switch-edgeless-mode-button',
};
const PageRadioItem: RadioItem = {
value: 'page',
label: 'Page',
testId: 'switch-page-mode-button',
};
const items = [PageRadioItem, EdgelessRadioItem];

export const EditorModeSwitch = () => {
const { close } = useMobileMenuController();
const editor = useService(EditorService).editor;
const trash = useLiveData(editor.doc.trash$);
const isSharedMode = editor.isSharedMode;
const currentMode = useLiveData(editor.mode$);

const onToggle = useCallback(
(mode: DocMode) => {
editor.setMode(mode);
editor.setSelector(undefined);
track.$.header.actions.switchPageMode({ mode });
close();
},
[close, editor]
);

if (trash || isSharedMode) {
return null;
}

return (
<div className={styles.radioWrapper}>
<RadioGroup
itemHeight={28}
width="100%"
borderRadius={8}
padding={2}
gap={4}
value={currentMode}
items={items}
onChange={onToggle}
/>
</div>
);
};
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ import { useCallback, useEffect, useState } from 'react';

import { JournalConflictsMenuItem } from './menu/journal-conflicts';
import { JournalTodayActivityMenuItem } from './menu/journal-today-activity';
import { EditorModeSwitch } from './menu/mode-switch';
import * as styles from './page-header-more-button.css';
import { DocInfoSheet } from './sheets/doc-info';

Expand Down Expand Up @@ -86,6 +87,7 @@ export const PageHeaderMenuButton = () => {

const EditMenu = (
<>
<EditorModeSwitch />
<JournalTodayActivityMenuItem suffix={<MenuSeparator />} />
<MobileMenuItem
prefixIcon={primaryMode === 'page' ? <EdgelessIcon /> : <PageIcon />}
Expand Down

0 comments on commit 922db5c

Please sign in to comment.