Skip to content

Commit

Permalink
fix(sheets-ui): room slide does not need to be disabled
Browse files Browse the repository at this point in the history
  • Loading branch information
wzhudev committed Mar 14, 2024
1 parent 0ce931d commit 45c60bf
Showing 1 changed file with 8 additions and 34 deletions.
42 changes: 8 additions & 34 deletions packages/sheets-ui/src/views/count-bar/ZoomSlider.tsx
Expand Up @@ -15,48 +15,30 @@
*/

import {
EDITOR_ACTIVATED,
FOCUSING_UNIVER_EDITOR,
ICommandService,
IContextService,
IUniverInstanceService,
} from '@univerjs/core';
import { useObservable } from '@univerjs/ui';
import { Slider } from '@univerjs/design';
import { SetWorksheetActivateCommand } from '@univerjs/sheets';
import { useDependency } from '@wendellhu/redi/react-bindings';
import React, { useEffect, useState } from 'react';
import { combineLatest, debounceTime, map } from 'rxjs';
import React, { useCallback, useEffect, useState } from 'react';

import { SetZoomRatioCommand } from '../../commands/commands/set-zoom-ratio.command';
import { SetZoomRatioOperation } from '../../commands/operations/set-zoom-ratio.operation';
import { SHEET_ZOOM_RANGE } from '../../common/keys';

const ZOOM_MAP = [50, 80, 100, 130, 150, 170, 200, 400];

const DISABLE_DEBOUNCE_TIME = 100;

export function ZoomSlider() {
const commandService = useDependency(ICommandService);
const univerInstanceService = useDependency(IUniverInstanceService);
const contextService = useDependency(IContextService);

const currentZoom = getCurrentZoom();
const [zoom, setZoom] = useState(currentZoom);
const sheetEditorFocused = useObservable(
() =>
combineLatest(
contextService.subscribeContextValue$(FOCUSING_UNIVER_EDITOR),
contextService.subscribeContextValue$(EDITOR_ACTIVATED)
).pipe(
map(([editorFocus, editorActivated]) => editorFocus && !editorActivated),
debounceTime(DISABLE_DEBOUNCE_TIME)
),
true,
false,
[FOCUSING_UNIVER_EDITOR]
);
const disabled = !sheetEditorFocused;
const getCurrentZoom = useCallback(() => {
const currentZoom = univerInstanceService.getCurrentUniverSheetInstance().getActiveSheet().getZoomRatio() * 100 || 100;
return Math.round(currentZoom);
}, [univerInstanceService]);

const [zoom, setZoom] = useState(() => getCurrentZoom());

useEffect(() => {
const disposable = commandService.onCommandExecuted((commandInfo) => {
Expand All @@ -66,14 +48,7 @@ export function ZoomSlider() {
}
});
return disposable.dispose;
}, [commandService]);

function getCurrentZoom() {
const currentZoom =
univerInstanceService.getCurrentUniverSheetInstance().getActiveSheet().getZoomRatio() * 100 || 100;

return Math.round(currentZoom);
}
}, [commandService, getCurrentZoom]);

function handleChange(value: number) {
setZoom(value);
Expand All @@ -94,7 +69,6 @@ export function ZoomSlider() {

return (
<Slider
disabled={disabled}
min={SHEET_ZOOM_RANGE[0]}
value={zoom}
shortcuts={ZOOM_MAP}
Expand Down

0 comments on commit 45c60bf

Please sign in to comment.