mirror of
https://github.com/toeverything/AFFiNE.git
synced 2026-02-13 12:55:00 +00:00
refactor(core): new back&forward button base on workbench (#6012)
# feature: ## In Browser: - hidden back&forward button in sidebar. - back and forward is equal with `window.history.back()` `window.history.forward()` ## In Desktop: - Back and forward can be controlled through the sidebar, cmdk, and shortcut keys. - back and forward act on the currently **active** view. - buttons change disable&enable style based on current active view history # Refactor: Move app-sidebar and app-container from @affine/component to @affine/core
This commit is contained in:
@@ -1,7 +1,8 @@
|
||||
import { appSidebarOpenAtom } from '@affine/component/app-sidebar';
|
||||
import { useAtom } from 'jotai';
|
||||
import { useCallback, useMemo } from 'react';
|
||||
|
||||
import { appSidebarOpenAtom } from '../../components/app-sidebar';
|
||||
|
||||
export function useSwitchSidebarStatus() {
|
||||
const [isOpened, setOpened] = useAtom(appSidebarOpenAtom);
|
||||
|
||||
|
||||
@@ -1,49 +0,0 @@
|
||||
import {
|
||||
PreconditionStrategy,
|
||||
registerAffineCommand,
|
||||
} from '@toeverything/infra/command';
|
||||
import { useEffect } from 'react';
|
||||
|
||||
export function useRegisterBrowserHistoryCommands(
|
||||
back: () => unknown,
|
||||
forward: () => unknown
|
||||
) {
|
||||
useEffect(() => {
|
||||
const unsubs: Array<() => void> = [];
|
||||
|
||||
unsubs.push(
|
||||
registerAffineCommand({
|
||||
id: 'affine:shortcut-history-go-back',
|
||||
category: 'affine:general',
|
||||
preconditionStrategy: PreconditionStrategy.Never,
|
||||
icon: 'none',
|
||||
label: 'go back',
|
||||
keyBinding: {
|
||||
binding: '$mod+[',
|
||||
},
|
||||
run() {
|
||||
back();
|
||||
},
|
||||
})
|
||||
);
|
||||
unsubs.push(
|
||||
registerAffineCommand({
|
||||
id: 'affine:shortcut-history-go-forward',
|
||||
category: 'affine:general',
|
||||
preconditionStrategy: PreconditionStrategy.Never,
|
||||
icon: 'none',
|
||||
label: 'go forward',
|
||||
keyBinding: {
|
||||
binding: '$mod+]',
|
||||
},
|
||||
run() {
|
||||
forward();
|
||||
},
|
||||
})
|
||||
);
|
||||
|
||||
return () => {
|
||||
unsubs.forEach(unsub => unsub());
|
||||
};
|
||||
}, [back, forward]);
|
||||
}
|
||||
Reference in New Issue
Block a user