mirror of
https://github.com/lensapp/lens.git
synced 2025-05-20 05:10:56 +00:00
Cleanup. Remove reaction.
Signed-off-by: DmitriyNoa <dmytro.zharkov@gmail.com>
This commit is contained in:
parent
1c55fe6167
commit
d97d0a6cda
@ -49,7 +49,6 @@ const getComponent = (dockStore: DockStore) => (
|
|||||||
selectedTab={dockStore.selectedTab}
|
selectedTab={dockStore.selectedTab}
|
||||||
autoFocus={true}
|
autoFocus={true}
|
||||||
onChangeTab={noop}
|
onChangeTab={noop}
|
||||||
dockStore={dockStore}
|
|
||||||
/>
|
/>
|
||||||
);
|
);
|
||||||
|
|
||||||
|
|||||||
@ -4,23 +4,21 @@
|
|||||||
*/
|
*/
|
||||||
|
|
||||||
import React, { Fragment, useRef, useEffect, useState, UIEvent } from "react";
|
import React, { Fragment, useRef, useEffect, useState, UIEvent } from "react";
|
||||||
import { reaction } from "mobx";
|
|
||||||
import { Icon } from "../icon";
|
import { Icon } from "../icon";
|
||||||
import { Tabs } from "../tabs/tabs";
|
import { Tabs } from "../tabs/tabs";
|
||||||
import { DockTab } from "./dock-tab";
|
import { DockTab } from "./dock-tab";
|
||||||
import type { DockTab as DockTabModel } from "./dock/store";
|
import type { DockTab as DockTabModel } from "./dock/store";
|
||||||
import { TabKind, DockStore } from "./dock/store";
|
import { TabKind } from "./dock/store";
|
||||||
import { TerminalTab } from "./terminal/dock-tab";
|
import { TerminalTab } from "./terminal/dock-tab";
|
||||||
|
|
||||||
interface Props {
|
interface Props {
|
||||||
tabs: DockTabModel[]
|
tabs: DockTabModel[]
|
||||||
dockStore: DockStore;
|
|
||||||
autoFocus: boolean
|
autoFocus: boolean
|
||||||
selectedTab: DockTabModel
|
selectedTab: DockTabModel
|
||||||
onChangeTab: (tab: DockTabModel) => void
|
onChangeTab: (tab: DockTabModel) => void
|
||||||
}
|
}
|
||||||
|
|
||||||
export const DockTabs = ({ tabs, autoFocus, selectedTab, onChangeTab, dockStore }: Props) => {
|
export const DockTabs = ({ tabs, autoFocus, selectedTab, onChangeTab }: Props) => {
|
||||||
const elem = useRef(null);
|
const elem = useRef(null);
|
||||||
const contentElem = useRef(null);
|
const contentElem = useRef(null);
|
||||||
const [contentWidth, setContentWidth] = useState(0);
|
const [contentWidth, setContentWidth] = useState(0);
|
||||||
@ -102,21 +100,22 @@ export const DockTabs = ({ tabs, autoFocus, selectedTab, onChangeTab, dockStore
|
|||||||
|
|
||||||
useEffect(() => {
|
useEffect(() => {
|
||||||
// update values in store on scroll
|
// update values in store on scroll
|
||||||
elem.current.addEventListener("scroll", updateScrollPosition);
|
elem?.current.addEventListener("scroll", updateScrollPosition);
|
||||||
|
|
||||||
// update current values on resize to show/hide scroll
|
// update current values on resize to show/hide scroll
|
||||||
window.addEventListener("resize", onWindowResize);
|
window.addEventListener("resize", onWindowResize);
|
||||||
|
|
||||||
// update scroll state if tabs numbers has changed
|
|
||||||
const tabsNumberChangeDisposer = reaction(() => dockStore.tabsNumber, updateStateValues, { fireImmediately: true });
|
|
||||||
|
|
||||||
return () => {
|
return () => {
|
||||||
window.removeEventListener("resize", onWindowResize);
|
window.removeEventListener("resize", onWindowResize);
|
||||||
elem.current.removeEventListener("scroll", updateScrollPosition);
|
elem?.current.removeEventListener("scroll", updateScrollPosition);
|
||||||
tabsNumberChangeDisposer();
|
|
||||||
};
|
};
|
||||||
}, []);
|
}, []);
|
||||||
|
|
||||||
|
useEffect(() => {
|
||||||
|
// update scroll state if tabs numbers has changed
|
||||||
|
updateStateValues();
|
||||||
|
}, [tabs]);
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<div className={"tabs-wrapper flex gaps align-center"}>
|
<div className={"tabs-wrapper flex gaps align-center"}>
|
||||||
{isScrollableLeft() && (
|
{isScrollableLeft() && (
|
||||||
|
|||||||
@ -4,10 +4,8 @@
|
|||||||
*/
|
*/
|
||||||
|
|
||||||
import "./dock.scss";
|
import "./dock.scss";
|
||||||
|
|
||||||
import React from "react";
|
import React from "react";
|
||||||
import { observer } from "mobx-react";
|
import { observer } from "mobx-react";
|
||||||
|
|
||||||
import { cssNames } from "../../utils";
|
import { cssNames } from "../../utils";
|
||||||
import { Icon } from "../icon";
|
import { Icon } from "../icon";
|
||||||
import { MenuItem } from "../menu";
|
import { MenuItem } from "../menu";
|
||||||
@ -37,7 +35,10 @@ interface Dependencies {
|
|||||||
dockStore: DockStore
|
dockStore: DockStore
|
||||||
}
|
}
|
||||||
|
|
||||||
type Direction = 1 | -1;
|
enum Direction {
|
||||||
|
NEXT = 1,
|
||||||
|
PREV = -1,
|
||||||
|
}
|
||||||
|
|
||||||
@observer
|
@observer
|
||||||
class NonInjectedDock extends React.Component<Props & Dependencies> {
|
class NonInjectedDock extends React.Component<Props & Dependencies> {
|
||||||
@ -70,11 +71,11 @@ class NonInjectedDock extends React.Component<Props & Dependencies> {
|
|||||||
}
|
}
|
||||||
|
|
||||||
if(ctrlKey && code === "Period") {
|
if(ctrlKey && code === "Period") {
|
||||||
this.nextTab();
|
this.switchToNextTab();
|
||||||
}
|
}
|
||||||
|
|
||||||
if(ctrlKey && code === "Comma") {
|
if(ctrlKey && code === "Comma") {
|
||||||
this.nextTab(-1);
|
this.switchToNextTab(Direction.PREV);
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
@ -86,16 +87,13 @@ class NonInjectedDock extends React.Component<Props & Dependencies> {
|
|||||||
this.element?.current.focus();
|
this.element?.current.focus();
|
||||||
};
|
};
|
||||||
|
|
||||||
nextTab = (direction: Direction = 1) => {
|
switchToNextTab = (direction: Direction = Direction.NEXT) => {
|
||||||
const { tabs, selectedTab } = this.props.dockStore;
|
const { tabs, selectedTab } = this.props.dockStore;
|
||||||
const currentIndex = tabs.indexOf(selectedTab);
|
const currentIndex = tabs.indexOf(selectedTab);
|
||||||
const nextIndex = currentIndex + direction;
|
const nextIndex = currentIndex + direction;
|
||||||
|
|
||||||
// check if moving to the next tab is possible.
|
// check if moving to the next or previous tab is possible.
|
||||||
if (direction === 1 && currentIndex!== -1 && nextIndex >= tabs.length) return;
|
if (currentIndex!== -1 && (nextIndex >= tabs.length || nextIndex < 0)) return;
|
||||||
|
|
||||||
// check if moving to the previous tab is possible
|
|
||||||
if (direction === -1 && currentIndex!== -1 && nextIndex < 0) return;
|
|
||||||
|
|
||||||
const nextElement = tabs[nextIndex];
|
const nextElement = tabs[nextIndex];
|
||||||
|
|
||||||
@ -158,7 +156,6 @@ class NonInjectedDock extends React.Component<Props & Dependencies> {
|
|||||||
selectedTab={selectedTab}
|
selectedTab={selectedTab}
|
||||||
autoFocus={isOpen}
|
autoFocus={isOpen}
|
||||||
onChangeTab={this.onChangeTab}
|
onChangeTab={this.onChangeTab}
|
||||||
dockStore={dockStore}
|
|
||||||
/>
|
/>
|
||||||
<div className="toolbar flex gaps align-center box grow">
|
<div className="toolbar flex gaps align-center box grow">
|
||||||
<div className="dock-menu box grow">
|
<div className="dock-menu box grow">
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user